37

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
19

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
  • I tried using pg_ctl it says that you have to install postgres-xc package. Jun 29 '15 at 9:56
  • And what is the problem with installing postgres-xc? How was this second instance stated?
    – rocky
    Jun 29 '15 at 10:01
  • I have started it by running /usr/lib/postgresql/9.4/bin/postgres -D /path/to/pgdata -c config_file=/path/to/config Jun 29 '15 at 10:05
  • Call pg_ctl from /usr/lib/postgresql/9.4/bin/pg_ctl too.
    – plomovtsev
    Jan 18 '19 at 13:21
  • 3
    pg_lsclusters to list clusters
    – naoko
    Jun 13 '19 at 17:02
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
1

Use systemctl

sudo systemctl stop postgresql

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.