45

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

4 Answers 4

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.

5
  • I tried using pg_ctl it says that you have to install postgres-xc package. Commented Jun 29, 2015 at 9:56
  • And what is the problem with installing postgres-xc? How was this second instance stated? Commented Jun 29, 2015 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 Commented Jun 29, 2015 at 10:05
  • Call pg_ctl from /usr/lib/postgresql/9.4/bin/pg_ctl too. Commented Jan 18, 2019 at 13:21
  • 3
    pg_lsclusters to list clusters Commented Jun 13, 2019 at 17:02
14

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 
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 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.