Stop postgreSQL service on Mac via terminal

Running postgreSQL 9.4.5_2 currently

I have tried

pg_ctl stop -W -t 1 -s -D /usr/local/var/postgres -m f 

Normally no news is good news but after I will run

pg_ctl status -D /usr/local/var/postgres 

and get pg_ctl: server is running (PID: 536)

I have also tried

pg_ctl restart -w -D /usr/local/var/postgres -c -m i 

Response message is:

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

I've also checked my /Library/LaunchDaemons/ to see why the service is starting at login but no luck so far. Anyone have any ideas on where I should check next? Force quit in the activity monitor also isn't helping me any.

5 Answers

I tried various options; finally, the below command worked.

sudo -u postgres ./pg_ctl -D /your/data/directory/path stop 

example

sudo -u postgres ./pg_ctl -D /Library/PostgreSQL/11/data stop 

As per the comments, the recommended command is without the ./ when calling pg_ctl:

sudo -u postgres pg_ctl -D /Library/PostgreSQL/11/data stop 
2

Tried sudo and su but no such luck. Just found this gui

If anyone can help with the terminal commands that would be very much appreciated, but till then the gui will get the job done.

you can stop the server using this command

{pg_ctl -D /usr/local/var/postgres stop -s -m fast} 

Sadly none of the previous answers help me, it worked for me with:

brew services stop postgresql 

Cheers

Had the same issue, I had installed postgres locally and wanted to wrap in a docker container instead.

I solved it pretty radically by 1) uninstalling postgres 2) kill the leftover process on postgres port. If you don't un-install the process restarts and grabs the port again - look at your Brewfile form brew bundle dump to check for a restart_service: true flag.

I reasoned that, as I am using containers, I should not need the local one anyway, but !! attention this will remove postgres from your system.

brew uninstall postgres ... lsof -i :5432 # this to find the PID for the process kill - 9 <the PID you found at previous command> 

Note: if you still want to used psql you can brew install libpq, and add psql to your PATH (the command output shows you what to add to your .zshrc, or similar)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like