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…