Feb 06 2008
Starting PostgreSQL 8.3 through launchd on Mac OS X 10.5.1 Leopard
Based upon a couple of other blogs that I’ve found on the web, I now finally have a working .plist file to start PostgreSQL 8.3 via launchd at boot time on Leopard.
This is what the file looks like:
<?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>/PostgreSQL</string>
</dict>
<key>ProgramArguments</key>
<array>
<string>/usr/local/pgsql/bin/postgres</string>
<string>-e</string>
<string>-i</string>
</array>
<key>StandardOutPath</key>
<string>/PostgreSQL/logfile</string>
<key>StandardErrorPath</key>
<string>/PostgreSQL/logfile</string>
<key>ServiceDescription</key>
<string>PostgreSQL Server</string>
</dict>
</plist>
Make sure that this file is in /Library/LaunchDaemons. I named it ‘org.postgresql.postgres.plist’.
Run these commands in Terminal:
sudo chown root /Library/LaunchDaemons/org.postgresql.postgres.plist sudo launchctl load /Library/LaunchDaemons/org.postgresql.postgres.plist
Other notes for compiling and installing PostgreSQL 8.3 from source on Leopard:
- I manually added a user “postgres” using the user preference pane.
- On OS X, you will use ‘make’ instead of ‘gmake’ (as far as I can tell, it’s actually the same thing).
- The ‘su’ thing does not work as documented in the PostgreSQL 8.3 INSTALL file. You can use ‘sudo -s’ to switch to a root shell, or you can just prefix the commands with ‘sudo’ to run them with super user privileges. However, when you are in a root shell after ‘sudo -s’, the ‘su – postgres’ command will work.
- As you can see above, I created my database directory in /PostgreSQL. Do whatever you want on your system, just make sure that the user ‘postgres’ is the owner of that directory, as documented.
- I did a lot of ‘ln -s’ to create symbolic links for the stuff in /usr/local/pgsql/bin’ in ‘/usr/local/bin’, so that calling all PostgreSQL commands and tools like psql works without having to provide a path. There’s probably a much more efficient way for this, but I have not dug into it yet.
For the BlitzMax folks out there that use Brucey’s PostgreSQL module:
- Copy /usr/local/pgsql/lib/libpq.a to /Applications/BlitzMax/mod/bah.mod/dbpostgresql.mod/lib.
- The easiest way to try the module with your current user account might be to create a database for your user in Terminal:
- createuser <username>
- createdb <username>
- Change the connection parameters in the source code. If you don’t assign a password to your database user account, just pass an empty string (“”) in the LoadDatabase() call. In my case, it looks like this:
- Local db:TDBConnection = LoadDatabase(“POSTGRESQL”, “Winni”, Null, 0, “Winni”, “”)