How do I set up PostgreSQL on c9 for my Rails app?

rails
postgresql

#1

I have a rails app on both my local machine and c9 that used to run on MYSQL. I recently migrated the app to PostgreSQL on my localmachine without any problems. On c9, however, I do not seem to be able to setup Postgres correctly.

I keep getting the error FATAL: Peer authentication failed for user

where I tried both new user development and root user postgres.

Does anyone else have the same issue and how did you solve it? I tried several available walkthroughs but all failed…


#2

How are you starting postgres? On a new workspace I can run sudo service postgresql start and it comes up without issues. Beyond that, it sounds like a postgres configuration issue and not an issue with cloud9. Maybe it is the same problem as this: http://stackoverflow.com/questions/18664074/getting-error-peer-authentication-failed-for-user-postgres-when-trying-to-ge


#3

I ultimately set up prostres for my rails app on c9 as follows: (following http://stackoverflow.com/a/29379969/5521564)

  1. sudo service postgresql start
  2. $ echo $USER
  3. $ sudo su - postgres;
  4. $ createuser ubuntu -dslP
  5. $ sudo sudo -u postgres psql
  6. # create database myapp_development owner=ubuntu;
  7. Then change my database.yml file to:
      development:
        adapter: postgresql
        encoding: SQL_ASCII
        database: cc_database
        pool: 5
        username: ubuntu
        password: password

8. rake db:migrate

Voila!


Setting up PostgreSQL
Running a Rails App
#4

Ah, thanks for that. I’ve made a fix that will go out when we update our images next so the ubuntu user will be able to create databases by default: https://github.com/c9/templates/pull/29

Once that’s out, your first 6 steps can be replaced by:

  1. sudo service postgresql start
  2. psql -c "create database myapp_development owner=ubuntu"

Then configure your app to suit.


#5

But, how would I log into psql as user ubuntu?


#6

The user created has no password, so just typing psql will open up the prompt without anything further. if you require a password you can set one from there and prevents people having to look up what the default password might be if we set one


#7

Here is my config for setting postgres up on a Clou9 rails app: https://github.com/JohnnyBurst/c9_sqlite3_to_pg

If the app/box wasn’t setup by default to run postgres, of course. :slight_smile:


#9

I get stuck on step four. When I echo $USER, there is already a user named ubuntu. When I try to use Postgres, it won’t allow me because I do not know the password for user ubuntu. Blank does not work, neither does ‘ubuntu’ or ‘password’.


#10

I’m struggling with this same problem. Any insight?