Postgres on OSX with homebrew not running after OSX crash
OSX Mavericks has been crashing randomly recent to me. Just very random. Not quite good because it doesn't give it the chance for processes like Postgres, etc... to shut down properly, leaving process ids (PIDs) behind.
Now got this issue where my postgres won't boot up.
Running postgres manually doesn't work
> pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
> pg_ctl: another server might be running; trying to start server anyway
So here's a quick fix.
1) Check the log
$ tail -f /usr/local/var/postgres/server.log
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 326) running in data directory "/usr/local/var/postgres"?
FATAL: lock file "postmaster.pid" already exists
HINT: Is another postmaster (PID 326) running in data directory "/usr/local/var/postgres"?
2) Delete the PID file.
$ rm /usr/local/var/postgres/postmaster.pid
3) Run pg_ctl manually
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
4) Make sure it's running
$ ps x | grep postgres
This should appear from the output above
8352 ?? S 0:00.02 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
8354 ?? Ss 0:00.00 postgres: checkpointer process
8355 ?? Ss 0:00.03 postgres: writer process
8356 ?? Ss 0:00.01 postgres: wal writer process
8357 ?? Ss 0:00.00 postgres: autovacuum launcher process
8358 ?? Ss 0:00.00 postgres: stats collector process
Also, this also happens to other processes like mongodb or anything that relies on PID files.
Written by Jason Torres
Related protips
8 Responses
Thx, saved my life.
how to make it permanent? so i won't have to repeat this process each time i start the terminal :/
+1 Thanks!
Many thanks!
Yeah this is super annoying, i guess I need to write a bash script that deletes postmaster.pid and restarts postgres after sleeping.
Thanks a lot for this post. Saved me a few times. BTW, if you are using launchctl you only need to delete the postmaster.pid file and the rest will take care of itself.
quick reference for on launchctl: https://robots.thoughtbot.com/starting-and-stopping-background-services-with-homebrew
Thank you !