Upgrading to 64-bit PostgreSQL 8.3.7 from KyngChaos

PostgreSQL.jpg

With the problems I had getting PostgreSQL support in PHP, and the desire to take control of my toolset, I went looking for a 64-bit version of PostgreSQL rather than resort to building it myself. What I found was that William Kyngesburye (a.k.a. KyngChaos) maintains a dual-build of PostgreSQL - i386 and x86_64 that's even Snow Leopard compatible! Marc seems to be out of it, and even the EnterpriseDB guys have no plans for building a 64-bit version.

While I don't need a 64-bit version per se, I do need the 64-bit libraries and this was an easy way to get them.

The upgrade was pretty easy - dump the database, move/remove the old install, and then follow the package installer. It should "just work", but it was missing the launchd file. I found something close to it on the net, and just fiddled the parameters to make it work:

  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
  <dict>
    <key>Label</key>
      <string>PostgreSQL</string>
    <key>UserName</key>
      <string>postgres</string>
    <key>RunAtLoad</key>
      <true/>
    <key>EnvironmentVariables</key>
      <dict>
        <key>PGDATA</key>
        <string>/usr/local/pgsql/data</string>
      </dict>
    <key>ProgramArguments</key>
      <array>
        <string>/usr/local/pgsql/bin/postgres</string>
        <string>-e</string>
        <string>-i</string>
      </array>
    <key>StandardOutPath</key>
      <string>/usr/local/pgsql/var/logfile</string>
    <key>StandardErrorPath</key>
      <string>/usr/local/pgsql/var/logfile</string>
    <key>ServiceDescription</key>
      <string>PostgreSQL Server</string>
  </dict>
  </plist>

Once I created that file as /Library/LaunchDaemons/org.postgresql.postgres.plist, I was ready to go. The instructions in the package work perfectly for starting it up, but now that I have the file there, the installer is supposed to restart PostgreSQL.

Once I had this installed, it was a simple matter of rebuilding the pgsql.so file using the provided libraries and it worked like a champ!

Now I feel I can move forward with this guy's PostgreSQL packages and making the PHP library each time I upgrade. Not a bad place to be.

[9/20] UPDATE: well, when trying to upgrade the PostgreSQL on my 20-inch iMac with 2GB RAM, I got a ton of errors about the SHMMAX value not being large enough to complete the operation. Basically, PostgreSQL wasn't able to get the shared memory to complete the operations. I did a bit of googling and found this post about setting the SHMMAX value.

When I set the SHMMAX sufficiently high, I was able to get the initdb command to work, and then I had to set these parameters in the startup by creating /etc/sysctl.conf which is read by the 10.4+ kernel on initialization. The file contains:

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

and after a reboot, I was able to finish the migration by loading up the database and things were working perfectly. I then compiled the PHP PostgreSQL extension and added it to the config and all was working quite nicely.

Quite an adventure!