0

I had a Rails project on C9 with a SQLite 3 database. Recently I wanted to switch to a PostgreSQL database to be able to run a project on Heroku. All records from the SQLite 3 database were copied to the PostgreSQL database with the Sequel gem, without any issues. All records were passed to the new database and I was able to see it, however, after rebooting my C9 project, and starting the PostgreSQL service, and connecting it to my database, I found that there weren't any records inside the database. Or, it's not connected yet. I don't get it.

Every time I reboot the project, records from the PostgreSQL database disappear, I have to create a new database and migrate it again to see my records. What am I doing wrong?

Here is list of my actions:

sudo service postgresql start
psql -c "create database myapp_development owner=ubuntu"
sequel -C sqlite://db/development.sqlite3 postgres://ubuntu@""/myapp_development

Then update database.yml file records with:

Development:
  - adapter: postgresql
  - encoding: SQL_ASCII
  - database: myapp_development
  - pool: 5
  - username: ubuntu
  - password: password

Then run:

rake db:migrate

After these actions I can run the project and see my records.

After rebooting the project, I've tried to run the following commands:

sudo service postgresql start
psql myapp_development ubuntu
\c

but it does not help me to see any records.

Please advise me if I've missed any command.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Nikita
  • 5
  • 3
  • By "reboot" do you mean just restarting everything, or does it recreate the VM and set up your code files again? (in which case of course the database is gone) – Richard Huxton Nov 15 '16 at 07:36
  • Richard, by reboot i mean restarting browser and opening new c9 session with the same workspace – Nikita Nov 15 '16 at 10:16

1 Answers1

0

Run psql as the postgres user:

sudo sudo -u postgres psql -d myapp_development -U ubuntu -W
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Michael Malov
  • 1,877
  • 1
  • 14
  • 20
  • Mikhail, i've tried. Received following message: FATAL: Peer authentication failed for user "ubuntu" Previous connection kept – Nikita Nov 15 '16 at 10:14
  • Try with -W `sudo sudo -u postgres psql -d myapp_development -U ubuntu -W` – Michael Malov Nov 15 '16 at 11:08
  • Mikhail, i've tried – after asking password for user ubuntu result is the same: psql: FATAL: Peer authentication failed for user "ubuntu" – Nikita Nov 15 '16 at 11:44
  • The "peer auth" error will be because you have configured pg_hba.conf to use that rather than password access – Richard Huxton Nov 15 '16 at 11:49
  • solved my issue by repeating every step from the start and granting access privileges to postgres database. Thanks, guys – Nikita Nov 25 '16 at 10:02