Setting up Postgres + Postgis on OSX

Even though I’m stupidly busy with my current work I’ve started getting ready for my next gig.  As this has ment installing Postgresql on my Macbook for the first time I thought I’d quickly share the solution to the pain I went through in getting it to work.

I received two suggestions for the ‘best install method’, firstly MacPorts and then later pre-compiled dmg’s from Kyng Chaos.  I already use ports extensively making that choice easy for me – I like being able to  uninstall things if they don’t work to well and was concerned the dmg option wouldn’t allow me to.

sudo port install postgresql83 postgresql83-doc postgresql83-server postgis

I then added the following to my path in ~/.zshrc so I could actually run things

/opt/local/lib/postgresql83/bin

and started the server.

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

All seemed to be fine and dandy as I could connect with pgAdmin.  I quickly discovered that I needed to create a user with the same login as my osx login when I tried creating a test db.

Next I tried restoring my client’s db dump and it barfed big time.  As I’ll be working on some mapping software I’d installed the PostGIS package which seems to have failed to link up with Postgres properly.   I was getting the follow missing library error:

could not load library /usr/lib/postgresl/liblwgeom.so.1.3

Obviously it’s looking in the wrong place for a start, so I setup a LIBDIR export in my profile to get over that problem and restarted the server.

export LIBDIR=/opt/local/lib/postgresql83

That still didn’t solve the problem though as I don’t have a file by that name on my system, I do however have liblwgeom.1.3.so which looked to be the same thing.  Pretty annoying, but easily solved with a symlink.

cd /opt/local/lib/postgresql83
sudo ln -snf liblwgeom.1.3.so liblwgeom.so.1.3

Then the backup restored like a chalm.

To get Rails talking to Postgresql I needed to install the postgres adapter gem appropriately called ‘postgres’.  I didn’t expect that to work straight off though as I’d installed postgresql with ports and the gem by default would be looking in the wrong place for it.  I was correct, but I also received an additional error complaining about the architechture not being specified – I needed to tell it I wanted i386.

sudo env ARCHFLAGS="-arch i386" gem install postgres -- --with-pgsql-include-dir=/opt/local/include/postgresql83l --with-pgsql-lib-dir=/opt/local/lib/postgresql83/

I gropped around for a bit trying to figure out the correct way of letting it know and eventually found the above solution on code snippets.

No related posts.

This entry was posted in Database, Features and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

3 Comments

  1. Ruitao Su
    Posted December 20, 2008 at 3:12 am | Permalink

    hey the new look of your blog is really nice, love it :D

  2. Ruitao Su
    Posted December 20, 2008 at 3:16 am | Permalink

    I really hate pgAdmin, this program just doesn’t feel like OS X and it is buggy, I really want something like cocoamysql for postgreSQL in OS X.

  3. nahum
    Posted December 20, 2008 at 8:10 am | Permalink

    Alternatively you could use http://phppgadmin.sourceforge.net/ which I’ve not yet installed – but it’s actually what the main guy at my next gig uses. It’s like phpmyadmin but for postgres.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*
  •  

  • About Nahum Wild

    I'm a High Performance Website Consultant specialising in Ruby on Rails deployments. In this blog I cover common problems I've seen and provide insight on optimisation techniques.

  • Recommend Me

    Follow me on Twitter