Stopping a postgresql instance

Solution 1:

pg_ctl is the postreSQL way to stop postgreSQL (in Ubuntu and Debian we should use pg_ctlcluster which is a wrapper for pg_ctl). The example in that link uses option `-p 5433".

As suggested by naoko in the comments below, use pg_lsclusters to list clusters.

Another way is to give a kill signal to the process running postgresqld. To stop both at once, killall postgresqld might work.

Finally as suggested in the comment by psyCHOder, pgAdmin can also stop the server, but of course that means installing that package.

Solution 2:

In Ubuntu use systemctl:

:~/github/kafka/postgres-kafka-demo$ pg_lsclusters
Ver Cluster Port Status Owner    Data directory              Log file
12  main    5432 online postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log

:~/github/kafka/postgres-kafka-demo$ sudo -u postgres pg_ctlcluster 12 main stop
[sudo] password for : 

Warning: stopping the cluster using pg_ctlcluster will mark the systemd unit as failed. Consider using systemctl: sudo systemctl stop postgresql@12-main

:~/github/kafka/postgres-kafka-demo$ sudo systemctl stop postgresql@12-main

:~/github/kafka/postgres-kafka-demo$ pg_lsclusters
Ver Cluster Port Status Owner    Data directory              Log file
12  main    5432 down   postgres /var/lib/postgresql/12/main /var/log/postgresql/postgresql-12-main.log

Solution 3:

Use systemctl

sudo systemctl stop postgresql