PostgreSQL on Leopard for Rails: A few notes January 02, 2008 TweetSo I recently had a client project where the production database was postgresql. I was able to go quite a while using mysql, mostly because I was blissfully ignorant that my SQL was not postgresql compatible. At any rate, I finally had a reason to install postgresql on my machine and learn how to run it.
So I started reading around about it. It looked like for a while that there were some problems with postgresql on Leopard, then they were fixed or something, mostly using the MacPorts way of installation, which is the way I prefer. I found this article by Robby Russell which appears to be the bible when it comes to OS X, Ruby on Rails and postgresql. Since I already most of the ruby/rails part down, I skipped ahead to the "Step 4: Installing the World's Most Advanced Database Server...PostgreSQL!". Unfortunately it didn't work. Compile errors everywhere. I was slightly annoyed, but not [SOMETHING]. (Editors note: [SOMETHING] was supposed to be a place holder for a descriptive word. Whoops).
I decided to consult the OS X god of the Edgecase office, Chad Humphries, in hopes he would help a mere mortal with his database dilemma. "Fear not!", he said. "The MacPorts of yesteryear is broken and desolate. To become whole again, you must renew yourself and become one with the ports." "What???", I said totally not understanding where Chad was going with this one. That's what I get for calling him on his vacation.
sudo port selfupdate
sudo port sync
And then all was well. Or so I thought. I continued by following the Robby Russel bible bringing me closer and closer to a postgresql epiphany until I came to this1:
sudo gem install ruby-postgres (don't run this)
Yay! More build errors. This one was a wee bit easier to figure out since there have been a lot of gems already that have had issues with Leopard because during the build process it attempts to link against PPC libraries, which apparently must be absent from Leopard installed on a Mactel. The basic gist to fixing this problem is to pass ARCHFLAGS environment variable to the command, which seems easy enough, but to the untrained eye, this doesn't seem to work with sudo. You might be tempted to do something like sudo -s, but we're more agile than that, aren't we? So instead we have this:
sudo env ARCHFLAGS='-arch i386' gem install postgres
and badda bing! PostgreSQL, Rails and my mac are now all happy. The end.
P.S. If you're a wimp like me and need a GUI tool every once and a while to get you through some data grokking, I've found that the free Navicat for PostgreSQL works pretty well.
 - The new version of RubyGems, which you probably have by now, assumes the "-y" flag, so I left it off in my examples, as opposed to the Robby Russell article.