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



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…


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:


I ultimately set up prostres for my rails app on c9 as follows: (following

  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:
        adapter: postgresql
        encoding: SQL_ASCII
        database: cc_database
        pool: 5
        username: ubuntu
        password: password

8. rake db:migrate


Setting up PostgreSQL
Running a Rails App

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:

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.


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


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


Here is my config for setting postgres up on a Clou9 rails app:

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


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’.