Using PostgreSQL With Ruby on Rails on OS X

Following on from my last post for getting PostgreSQL up and running nicely on Mac OS X, my next task was getting it playing nicely with ruby on rails - I’m off on a rails course next week so I’m getting stuff ready. :)

It appears that there is currently two/three gem packages for using postgresql with ruby: postgres, ruby-pg, and pg - and from what I can make out, they’re all maintained by the same team now, (postgres was the original package, but it got abandoned - ruby-pg and pg are the replacements). As such, i’ll go with the newer ruby-pg gem…

sudo env ARCHFLAGS="-arch i386" gem install \
 ruby-pg -- \
 --with-pgsql-lib=/opt/local/lib/postgresql83 \
 --with-pgsql-include=/opt/local/include/postgresql83

Then finally, when writing the database.yml entry for connecting to postgresql, we have to define our adapter as follows:

development:
  adapter: postgresql
  database: test_dev
  encoding: unicode
  host: localhost
  user: XXXXX
  password: XXXXX
  timeout: 5000

2 Responses to “Using PostgreSQL With Ruby on Rails on OS X”


  1. 1 Kyle

    Thanks man! I’ve been trying for so long to get postgre installed and working with rails locally. This is a lifesaver.

  2. 2 Furg

    I echo the thanks! After having problems with the standard postgres ruby support I tried to get ruby-pr working. These are the only set of instructions I could find that work. Thanks again for taking the time to put these up. The saved me hours and a lot of frustration.

Leave a Reply