43

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)

Beatles1692
  • 535
  • 1
  • 4
  • 7

4 Answers4

22

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.

rocky
  • 807
13

Use systemctl

sudo systemctl stop postgresql
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

Haili Sun
  • 121
2

You can run

sudo systemctl stop postgresql[@version-main]

For example, if you are trying to stop version 10 run

sudo systemctl stop postgresql@10-main
Gino
  • 123
  • 6