PostgreSQL server won't stop

Parker Hutchinson picture Parker Hutchinson · Jul 29, 2013 · Viewed 72.3k times · Source

Having a bit of an issue with PostgreSQL on Mac OS X 10.8.4. I accidentally did brew rm postgresql --force while the postgres server was running. When I installed using brew install postgresql and ran pg_ctl -D /usr/local/var/postgres start I get:

pg_ctl: another server might be running; trying to start server anyway
server starting
FATAL:  lock file "postmaster.pid" already exists                                                                       
HINT:  Is another postmaster (PID 752) running in data directory "/usr/local/var/postgres"?

when I run "ps -ef | grep postgres" I get:

501   752   235   0 12:42PM ??         0:00.01 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
501   754   752   0 12:42PM ??         0:00.00 postgres: checkpointer process       
501   755   752   0 12:42PM ??         0:00.34 postgres: writer process       
501   756   752   0 12:42PM ??         0:00.02 postgres: wal writer process       
501   757   752   0 12:42PM ??         0:00.01 postgres: autovacuum launcher process       
501   758   752   0 12:42PM ??         0:00.01 postgres: stats collector process       
501   945   452   0 12:58PM ttys000    0:00.00 grep postgres

when I try to stop the server with pg_ctl stop -D /usr/local/var/postgres -m fast or pg_ctl -D /usr/local/var/postgres stop -mi I get:

waiting for server to shut down........................................... Failed
pg_ctl: server does not shut down

EDIT

which pg_ctl
/usr/local/bin/pg_ctl
pg_ctl --version
pg_ctl (PostgreSQL) 9.2.4

Gist of server.log: https://gist.github.com/anonymous/6106182

Answer

Neara picture Neara · Jun 10, 2014

Had same issue, pg_ctl: server does not shut down. Furthermore, ps auxwww | grep postgres showed no postgres running, while pg_ctl -D /usr/local/var/postgres status showed that postgres is running. Restarting my mac didn't help, i even went as far as to reset SMC, but this SO Q/A gave me an idea what to look for next: brew issues.

Following this line of thought, i found this helpful blog post, that came down to following commands that solved this issue for me:

$ brew services list
$ brew services restart postgresql

Hope this will help someone.

Update - Unknown command: services

After a bit of investigation following one of the comments ('Unknown command: services'), i found out that the authors of Homebrew decided to remove services from the repo, seeing as no one wants to maintain this code.

You can read more about it here and here (related github tickets).

After some more digging, I found this repo that adds services on macs.

This is how I 'returned' services:

~ » brew tap gapple/services
~ » brew services
usage: [sudo] brew services [--help] <command> [<formula>]

Small wrapper around `launchctl` for supported formulae, commands available:
   cleanup Get rid of stale services and unused plists
   list    List all services managed by `brew services`
   restart Gracefully restart selected service
   start   Start selected service
   stop    Stop selected service

Options, sudo and paths:

  sudo   When run as root, operates on /Library/LaunchDaemons (run at boot!)
  Run at boot:  /Library/LaunchDaemons
  Run at login: /Users/user/Library/LaunchAgents

Here is another suggested solution: https://apple.stackexchange.com/questions/150300/need-help-using-homebrew-services-command. Didn't check it myself, so don't know if and how it works.