Installing PostgreSQL 8.3 on Leopard

Date Arrow  April 23, 2008

This is the documented path to my discovery of PostgreSQL 8.3, which I’ve never used before. Now that MySQL’s community is getting hammered to death by Sun, and thanks to all the good things I’ve heard about it over the years (including enhanced performance on multicore systems and greater scalability), I really wanted to install it and play with it.

Frankly, it’s not easy. At all (actually this is why I think MySQL is so popular, because of the ease of installation!) So hang tight and read on.

Installation

Russ Brooks says it is better to avoid MacPorts: I must say that indeed, I tried installing PostgreSQL with MacPorts and I got seriously stuck, unable to do anything with it, not even starting the server. So I uninstalled the PostgreSQL MacPorts package and found other options: a PostgreSQL for Mac installer, and Marc Liyanage’s own installer. I decided to go with the first one, since Marc’s installs version 8.1 of the server, and PostgreSQL for Mac offers version 8.3.

The installation goes without trouble, using a standard installer (which means that you need administrative privileges, as usual). However, you want to read these explanations before doing anything ;)

NOTE: if you have trouble installing PostgreSQL using the above installer (as I did after the unsuccessful MacPorts installation / desinstallation), open Terminal.app and try these commands:

$ sudo dscl localhost
>cd Local/Default/Users/
>ls

If you see a “postgres” entry in the list of local users, delete it and re-run the installer:

>delete postgres

After the Installation

The installer puts the PostgreSQL installation into /Library/PostgreSQL8. You should add the path to the PostgreSQL binaries in your PATH environment variable before doing anything else:

export PATH=/Library/PostgreSQL8/bin:$PATH (bash)
setenv PATH /Library/PostgreSQL8/bin:$PATH (tcsh)

Then, type the following commands to create the default database, owned by the “postgres” user:

cd /Library/PostgreSQL8/
sudo rm -r data
sudo mkdir data
sudo chown postgres:postgres data
cd bin
sudo -u postgres initdb -E utf8 /Library/PostgreSQL8/data

In my case (Leopard-powered PowerBook G4) I had the “Shared Memory error” that Russ talks about. So I followed his advice: I created a file named /etc/sysctl.conf with the following contents, then rebooted my computer and everything went fine:

kern.sysv.shmmax=4194304
kern.sysv.shmmin=1
kern.sysv.shmmni=32
kern.sysv.shmseg=8
kern.sysv.shmall=1024

I also used dscl to change the password of the postgres user (otherwise, how to know which is it??)

>passwd postgres postgres

The installer adds some handy utilities on your /Application folder (see the image above). You can also use pgAdmin to manage the database server. Very handy. I tried to use phpPgAdmin but without success (can’t get past the login screen… :(

And that’s it! There are interesting resources out there explaining how to use it from Rails or Django, so I’ll start reviewing them…

Tagged   Django · How to? · Open Source · Ruby on Rails

3 Comments

  • #1.   Pierre Omidyar 04.23.2008

    Thanks for your post. I have to say that I had no trouble at all installing PostgresSQL 8.3 using MacPorts on Leopard on a new MacBook Air. The only slightly tricky thing is that you have to manually install the startup item, and manually init the database. The port makes this easy by spitting out two commands at the end of its installation that you can execute to accomplish these two things. The only trick is that if you happen to miss this console output, it can be a pain to scroll back and find the commands.

    I haven’t tweaked any shared memory params and haven’t needed to, but I’m not really pushing the db yet anyway.

    I really like MacPorts because it simplifies package management, and installs everything cleanly under /opt/, which makes it trivial to remove everything if you decide things have gone horribly wrong and need a pristine machine. It also reminds me in that way of the excellent FreeBSD port system.

  • #2.   Adrian 04.23.2008

    Thanks for your comments Pierre!
    Indeed I use MacPorts as often as possible, but in many cases I’ve installed software using the classic “./configure - make - make install” or using package installers. It depends; if I need the latest version of a specific library, I prefer to install from source; but sometimes (or if I just need the binaries), then I use the installers. And finally there’s Fink and MacPorts; I think it’s great to work on a platform that offers so many choices.

  • #3.   Erick 07.15.2008

    I tried MacPorts too, and the console stuff is pretty cumbersome. If I wanted that stuff, I’d rather install from source.

    The folders inside MacPorts are HUGE and eat up way more space than necessary. And no, the install is not as clean as remove /opt. There are several other folders to uninstall:

    http://trac.macports.org/wiki/FAQ#HowdoIremoveoruninstallMacPorts

    I loved the “Postgresql for Mac” software. Will write a blog entry, just to increase the traffic to that site! I want to run Postgresql for trying out my PHP and Python projects on Apache. For the latter, it’s a breeze to install with XAMPP, but the Postgresql and PHP working in tandem is tricky. Any thoughts on making that work easily?

    Thanks for this excellent recommendation otherwise! The packaging is superlative.

Commenting