Monday, April 12, 2010

Getting PostgreSQL to run on a Mac...

So I decided to switch to PostgreSQL from MySQL. First off, it's what's used by default at Heroku, and I'm so far loving Heroku, its great integration with git, and the resulting ease of deployment. Secondly, I'm a tad concerned about what might happen in the future since Oracle now owns MySQL: could be 'interesting'.

Anyway, I'd always heard that installing PostgreSQL was more challenging than installing MySQL: "MySQL put more effort into making things easier for first-time users" is what my friends have told me. But I also heard that PostgreSQL had better and more standard SQL support (for example, support for foreign keys).

Anyway, with a bit of searching, I finally found this RubyOnRails page which seemed to do a great job of laying things out for all 3 platforms. Seemed pretty straight-forward: 

Install the server:
sudo port install postgresql83-server

Start the server:
sudo launchctl load -w /Library/LaunchDaemons/org.macports.postgresql83-server.plist

Setup the database:
sudo mkdir -p /opt/local/var/db/postgresql83/defaultdb
sudo chown postgres:postgres /opt/local/var/db/postgresql83/defaultdb
sudo su postgres -c '/opt/local/lib/postgresql83/bin/initdb -D /opt/local/var/db/postgresql83/defaultdb'

Two problems:
  1. It failed installing the database -- complaining that it couldn't find the header file libpq-fe.h. 
  2. It installed version 8.3 and version 8.4 is now current.

More searching led me to the MacPorts site which has the required library:
sudo port install libpqxx

However, it also wound up installing the 8.4 version of PostgreSQL, but version 8.3 still is the one that gets launched... seems to work, but certainly not as clean as I would like.

Given the problems I had in the past before I cleaned my machine and installed Ruby & Rails "from scratch" with MacPorts (see my previous post on this issue) as I could easily get PostgreSQL with relatively little hassle.

So far, so good...

PS Check out "Enterprise Rails" (Dan Chak, O'Reilly). He does a really nice job of discussing Rails' scaling and reliability issues and does it all in the context of PostgreSQL. Good book!

No comments:

Post a Comment