Postgres with Rails

I needed to get my Rails app running with a Postgres DB today (so I could take advantage of the excellent Texticle) , but found it a little trickier than expected.

Here's what I had to do (using Ubuntu Karmic)

1/ Install Postgres

This is as easy as sudo apt-get install postgresql for Ubuntu folk.

2/ Make a yourself a superuser

By default, Postgres uses 'ident sameuser' so you don't need a password when connecting from the same machine. I did:

sudo -u postgres createuser --superuser $USER
sudo -u postgres psql

which will take you to the psql command line. Set yourself a password with:

postgres=# \password $USER

This password is used (I think) when connecting to the DB remotely. The only time I've had to use it is to do a db:pull with taps.

3/ Install the postgres and postgres-pr gem

I'll be honest. I don't remember if both are necessary (I could have sworn it was just postgres), but I've got both installed so it can't hurt to have both.

They required some dependencies which were resolved by installing libpq-dev. On Ubuntu, this is:

sudo aptitude install libpq-dev

Now you're free to do

gem install postgres
gem install postgres-pr

4/ Set your database.yml

Finally, set the config/database.yml file in your Rails app to mimic:

development:
  adapter: postgresql
  database: db_name
  pool: 5
  timeout: 5000

No need for a username/password because of step 2.

Fin.

Posted by email 

0 comments

Leave a comment...