Connecting Rails and Postgres

I am working on a project for Code Academy with a few other students. We decided to use PostgreSQL, since that is what Heroku uses. One of the other students posted some directions on his blog. I could not follow them since I run Linux.

I had already run apt-get to install some libraries, so I will skip that.

I put this into my Gemfile:

I put this in config/database.yml

But when I ran

I got this error:

I had to do a lot of googling. I won’t go over some of the other errors I got, so I will try to list some commands that will help me to get Rails working with Postgres on Linux boxes in the future.

You must create a user that has the same name as the username that will be running the rails app. It must own the database, and have permissions to create and alter databases. For some reason I did not need to enter a password in any Rails file. Even so, things seemed to work.

In order to use Postgres, I have to type this:

I would like to log into postgres without sudo-ing. I can log into MySQL as root from my main user ID.

To create the user:

To see users, run the metacommand \dg

Then create the database:

To list the databases, run the metacommand \l

After this, you should be able to run the commands to create, populate and reset the databases:

Page created on 2012-03-12_14:37:02, last modified on 2012-03-12_14:37:02.

This site has a disclaimer.