58

I installed PostgreSQL using Homebrew on Lion. It starts okay but wouldn't shutdown. I tried:

$ #started with
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
$ #tried stoping with
$ pg_ctl -D /usr/local/var/postgres stop -m immediate
waiting for server to shut down................................... failed
pg_ctl: server does not shut down

I fixed this issue by deleting the Launch Agent:

launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
rm ~/Library/LaunchAgents/org.postgresql.postgres.plist
3
  • 7
    That is the correct fix. It worked for me on OS X Snow Leopard as well. You don't need to delete the plist though, you just have to do the unload. You can re-start it by issuing: $ launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
    – stantonk
    Dec 23, 2011 at 6:37
  • @Greg: Please add your solution as an answer and accept it, so that this questions doesn't show up on the list of unanswered questions.
    – kgrittn
    Apr 30, 2012 at 16:39
  • 1
    if installed with homebrew it may look something like this: ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist Nov 16, 2013 at 18:56

4 Answers 4

64
launchctl unload -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
rm ~/Library/LaunchAgents/org.postgresql.postgres.plist
5
  • 33
    This worked for me too, except my Launch Agent path was: ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    – Shevaun
    Apr 18, 2013 at 22:59
  • Thanks, this worked for me too. I also had to use the homebrew path posted by Shevaun May 4, 2013 at 4:20
  • 2
    What causes this issue to happen in the first place?
    – Kyle Macey
    May 7, 2014 at 2:16
  • 1
    Rather obscure way of shutting down a server. Sep 22, 2014 at 1:05
  • 1
    launchctl unload + rebooting did it form me, no need to remove the LaunchAgent
    – Arnaud
    Oct 22, 2015 at 16:37
12

Shutting down PostgreSQL Server with -m immediate is a dangerous way to do it, because “Immediate” mode will abort all server processes without a clean shutdown.

This will lead to a recovery run on restart. Try to shutdown PostgreSQL with parameter -m fast instead. "Fast” mode does not wait for clients to disconnect and will terminate an online backup in progress. All active transactions are rolled back and clients are forcibly disconnected

pg_ctl stop -D /usr/local/var/postgres -m fast 

For more information about pg_ctl please visit http://www.postgresql.org/docs/9.0/static/app-pg-ctl.html

1
  • The problem was about clean shutdown but rather about the server shutting down. Any way, its fixed and I've updated the solution in the question.
    – Greg
    Aug 5, 2011 at 6:43
2

This works for me

 pg_ctl -D /Library/PostgreSQL/9.2/data/ start
 pg_ctl -D /Library/PostgreSQL/9.2/data/ stop

Source https://sites.google.com/site/amaosblog/database/postgresql/how-to-start-stop-postgresql-9-2-on-mac-os-x-10-8-x

1

If you used Homebrew to install postgresql, then as Shevauns comment on Greg's answer indicates, the correct procedure is

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.