How to shut down Postgres 9.6.11 without pg_ctl on MacOS?

3k Views Asked by At

I have multiple installations of Postgres on my MacOS Mojave machine. Version 10.7 is running, and I want to shut it down, in order to start 9.6.

It's definitely running:

$ psql -h localhost -U postgres
Password for user postgres:
psql (9.6.11, server 10.7)

But I can't stop it:

/Library/PostgreSQL/10 $ bin/pg_ctl stop
pg_ctl: PID file "/usr/local/var/[email protected]/postmaster.pid" does not exist
Is server running?

Nor with the 9.6 version of pg_ctl:

$ pg_ctl stop
pg_ctl: PID file "/usr/local/var/[email protected]/postmaster.pid" does not exist
Is server running?
$ which pg_ctl
/usr/local/opt/[email protected]/bin/pg_ctl

How can I shut down the server, when pg_ctl doesn't seem to be able to control it? I don't recall starting it - perhaps it automatically started when the machine last rebooted. I think I installed it with Homebrew but I'm not certain.

1

There are 1 best solutions below

0
On BEST ANSWER

This ended up working:

First, get the pid:

$ sudo lsof -i:5432
Password:
COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
postgres  73 postgres    4u  IPv6 0x8880707cadb2d1ab      0t0  TCP *:postgresql (LISTEN)
postgres  73 postgres    5u  IPv4 0x8880707cadac18ab      0t0  TCP *:postgresql (LISTEN)

Now shut it down (SIGTERM):

$ sudo kill -15 73