Stopping a postgresql instance

For the sake of educational purposes I have two identical instances of postgresql running on my machine.

I can easily stop the service of the instance that is running on port 5432 like this :

sudo service postgresql stop

What I like to know is that how I can stop the other instance (it is running on port 5433)

1

3 Answers

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.

5

Use systemctl

sudo systemctl stop postgresql

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

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