'Cannot kill Postgres process

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



Solution 1:[1]

If you installed postgres using brew, this command might be what you are looking for :

brew services stop postgres

Solution 2:[2]

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

Solution 3:[3]

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

Solution 4:[4]

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

Solution 5:[5]

Try to run this command:

sudo pkill -u postgres

Solution 6:[6]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 BHendricks
Solution 2 Community
Solution 3 Steven Shi
Solution 4 l'L'l
Solution 5
Solution 6 Daniel