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
Spread the Word
  • Twitter
  • del.icio.us
  • Digg
  • Facebook
  • Google Bookmarks
  • Reddit
  • NewsVine
  • Slashdot
  • connotea
  • HackerNews
  • Print
  • email

About Daz

This is the blog of Darren Oakley
This entry was posted in postgresql, ruby and tagged , , , . Bookmark the permalink.

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

  1. Kyle says:

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

  2. Furg says:

    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

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">