PostgreSQL on Leopard gotchas

Jan 16 by Andre

For a recent Rails project, I had to use PostgreSQL instead of the standard MySQL for the database. Setting up Postgres on Mac OS 10.5 has some quirks, which I will share with you here.

  • There are three primary ways to get PostGRES onto Leopard: a pre-built binary, MacPorts, and source. My choice was to build with source. There are several good posts on building from source:
  • I do not recommend creating a separate user to run postgres. Doing so clutters your startup screen with another user, and requires you to su to that user to start the database. Instead:

    1) install Postgres as root

    2) after install, from the command line: chown -R andre /usr/local/pgsql/data. The -r flag changes the ownership recursively. Obviously, substitute your own username for "andre" in the example.

  • Since I don't use PostGres all the time, I don't want it to be started up automatically. Instead, I set up two aliases in by .bashrc:

    alias startpostgres='/usr/local/pgsql/bin/pgctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/logfile start' alias stoppostgres='/usr/local/pgsql/bin/pgctl -D /usr/local/pgsql/data -l /usr/local/pgsql/data/logfile stop'

  • when you start postgres, you'll probably get the dreaded "shared memory error," which looks like this:

    FATAL: could not create shared memory segment: Cannot allocate memory DETAIL: Failed system call was shmget(key=1, size=1081344, 03600). HINT: This error usually means that PostgreSQL's request for a shared memory segment exceeded available memory or swap space. To reduce the request size (currently 1081344 bytes), reduce PostgreSQL's sharedbuffers parameter (currently 50) and/or its maxconnections parameter (currently 10).

  • some resources will tell you to edit the /etc/rc file, which is incorrect for Leopard. Instead, create /etc/sysctl.conf (if it does not already exist -- mine didn't), and add the following lines:

    kern.sysv.shmmax=167772160 kern.sysv.shmmin=1 kern.sysv.shmmni=32 kern.sysv.shmseg=8 kern.sysv.shmall=65536

You'll need to su to root to create /etc/rc

Have fun with Postgres!

Comments

1

Wiatraki on Jan 18

Finally it's working. I made two attempts to get postgre running on my mac and now it fine. Thanks a lot Andre!

2

Tom on Feb 13

Thanks for the article Andre. I got it working too now.

Maybe I can ask you something? (I'm new to all that terminal/Unix stuff) What is required if I want to change the path AFTER install?

I installed it to '/opt/local/...' (just like in the first example from Stiefels you gave) and now realized that it's not quite what I wanted.

I tried just to move it (out of curiousity) but starting the PostgreSQL then brings "library not loaded" or similar. Remove and then reinstall? And how do I do that?

3

Norman Süsstrunk on Feb 20

It worked "out of the box" with your "guide", probably saved me a lot of time!
yes, thanks a lot, Andre!

4

Scott Meade on Jul 22

Thanks Andre! Worked like a charm following your directions. I used the Apple Dev. link for building from source.

Post a comment

 
This is so filters can reject the spam-bots. Thanks!