Thursday, August 11, 2011

PostgreSQL server doesn't start in OS X

My PostgreSQL server is an EnterpriseDB product. It was installed using their installer. Suddenly one day, while watching a YouTube video, my computer hung. I had to restart OS X Snow Leopard (10.6), and after the restart, I couldn't connect to my PostgreSQL server: it wouldn't start. Even restarting Snow Leopard didn't help.

So I checked Snow Leopard's launchctl, which was responsible for starting processes at startup. 

sudo launchctl list |grep post
549 1 com.edb.launchd.postgresql-9.0

Not good. The second number tells me that postmaster has exited with a value of 1. Which most Unix users will know is an exit with error.

So OS X is launching the postmaster, but postmaster keeps exiting with an error. So what's the error? I'll try to launch postmaster in the exact same way that OS X is trying to launch, but I'll do it on the command line, so I can see the error myself.

First, I got to find the command that Launchctl uses. I thus open "/Library/LaunchDaemons/com.edb.launchd.postgresql-9.0.plist":

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
<plist version="1.0">

This tells me the command to run is "sudo /Library/PostgresPlus/9.0SS/bin/postmaster -D/Library/PostgresPlus/9.0SS/data". So I run that:

"root" execution of the PostgreSQL server is not permitted.
The server must be started under an unprivileged user ID to prevent
possible system security compromise.  See the documentation for
more information on how to properly start the server.

Ok. Can't execute that command as root. I know that PostgreSQL server is started under the user "postgres". So I try that:

sudo -u postgres /Library/PostgresPlus/9.0SS/bin/postmaster -D/Library/PostgresPlus/9.0SS/data

GMT FATAL:  lock file "" already exists
GMT HINT:  Is another postmaster (PID 62) running in data directory "/Library/PostgresPlus/9.0SS/data"?

Ahhhh… Apparently another process has opened the pid lock file. Next step is to kill that offending process and try again. I can do it on the command line, but where possible, I try to do it using OS X's GUI :) Steve wants it done his way… So I open Activity Monitor, find PID = 62, and "Quit Process".

Everything is now fixed.

No comments:

Post a Comment