Postgres Is Now Running

Published September 20, 2017 | #postgres | ± 1 min

My Macbook has OSX Mavericks installed and sometimes it crashes for no reason, breaking my local postgres server. After restarting and running again "$ brew services postgres", Postgres becomes yellow and I end up spending sometime looking confused and frustrated.

Looking at the logs you can get a sense of whats happening:

1
2
$ tail -f /usr/local/var/postgres/server.log
FATAL:  lock file "postmaster.pid" already exists

Simply removing the lock file that Postgres generates solves this issue:

1
$ rm -f /usr/local/var/postgres/postmaster.pid

If you can’t find your postmaster.pid, just run the following snippet on your terminal:

$ find ~ -name postmaster.pid\*

Now a simple restart puts the server back online!

1
$ brew services start postgresql

Why do we need to do this?

If your computer crashes and Postgres it's abruptly stopped, its cleanup procedures don’t run so the postmaster.pid file is kept intact on your local hard drive.

Also, whenever we start postgres (pg_ctl start) the program checks if there is an already running server by looking for an existing postmaster.pid.

You can read more about this issue on Postgres mailing list


comments powered by Disqus
Previous Post: ◀ 💰 Personal Finance
Next Post: ▶ SSH ForwardAgent Gotchas