Reputation: 501
I keep trying to kill a PostgreSQL process that is running on port 5432 to no avail. Whenever I type sudo lsof -i :5432
, I see something like the below:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 587 postgres 4u IPv6 0x218f97e9af5d0303 0t0 TCP *:postgresql (LISTEN)
postgres 587 postgres 5u IPv4 0x218f97e9ae0f6c63 0t0 TCP *:postgresql (LISTEN)
I then try to kill the process 587 in this example with sudo kill -9 587
, but then another process automatically restarts on the same port! I have tried killing it on activity monitor as well to no avail. Please help?
Thanks, Laura
Upvotes: 45
Views: 53131
Reputation: 1293
my suffering:
sudo lsof -PiTCP -sTCP:LISTEN
(replace 54011 with your PID)
ps -f -p 54011
pg_ctl status -D /opt/homebrew/var/postgres
pg_ctl -D /opt/homebrew/var/postgres stop
but failed for me :(
my issue is with the launchctl of macos, restarting the homebrew.mxcl.postgresql service, but the suggested solutions for removing the service didn't work
launchctl bootout gui/501/homebrew.mxcl.postgres
only removes the service until the next login
and editing
vi /var/db/com.apple.xpc.launchd//disabled.501.plist
by removing the lines
<key>homebrew.mxcl.postgres</key>
<false/>
didn't effect anything.
So I finally removed the postgres binary of the deamon
rm -r /opt/homebrew/Cellar/postgresql@14
the service homebrew.mxcl.postgres is still there but no process.
the issue was in the LaunchAgent, so I removed the file
rm ~/Library/LaunchAgent/homebrew.mxcl.postgresql.plist
or in root
rm /Library/LaunchAgent/homebrew.mxcl.postgresql.plist
and
launchctl bootout gui/501/homebrew.mxcl.postgres
finally worked for me, no more homebrew.mxcl.postgres
entry in launchctl list
, after relogin.
Upvotes: 2
Reputation: 33
For those who's still struggling.
You can give it a try with the steps below
brew install pstree // enables you to see structuralized tree process
pstree | grep postgre
Remember the path of the parent task
Example)
/opt/homebrew/var/postgres
Then you remove the .pid file located at the directory of the parent task
rm -rf <path of the parent task>/postmaster.pid
kill <PID of the parent task>
I hope it works for you too :)
Upvotes: 0
Reputation: 261
I had this issue and what I did to resolve it was first run
brew services
to see a list of the services that home brew is running. In my case the service was called 'postgresql@12' so I had to run
brew services stop postgres@12
Upvotes: 13
Reputation: 6508
If you installed postgres using brew, this command might be what you are looking for :
brew services stop postgres
Upvotes: 46
Reputation: 2288
I had this issue trying to stop postgres. I was unable to use pg_ctl stop
. I installed postgress using brew.
I eventually stumbled upon this post which solved the issue for me.
Upvotes: 0
Reputation: 1231
list your postgres pid:
pg_ctl status -D /usr/local/var/postgres
pg_ctl: server is running (PID: 715)
force kill it..
kill -9 715
Upvotes: 7
Reputation: 554
I have 9.5 and 9.6 installed, so
sudo su - postgres
/Library/PostgreSQL/9.6/bin/pg_ctl -D /Library/PostgreSQL/9.6/data stop
9.5 started ...
/Library/PostgreSQL/9.5/bin/pg_ctl -D /Library/PostgreSQL/9.5/data stop
Upvotes: 14
Reputation: 47169
The process is restarting likely because it's spawned from a launchd
daemon. You can try finding it and killing it through the launchctl
command:
$ launchctl list
To kill a process you would:
$ launchctl kill
Upvotes: 2