In this article, we will see how to start stop PostgreSQL server using pg_ctl.
We can start or stop or promote PostgreSQL server(cluster) by using following three methods.
1. Using pg_ctl
2. Using Systemctl
3. Using service
Last two methods are straight forward.
How to start stop restart PostgreSQL server using pg_ctl
pg_ctl is the utility used to start stop status or promote/failover of PostgreSQL cluster(server).
To use pg_ctl to start the PostgreSQL, we must have an already existing or newly initialized data directory.
We have to use PostgreSQL server data directory location while using pg_ctl.
Before going to examples, set the PostgreSQL environment variables using this link
Syntax of pg_ctl:
pg_ctl -D
start | stop | status | promote
Where data_directory can be $PGDATA if it is set in Environment variables otherwise give the data directory path which contains postgresql.conf.
Check the status PostgreSQL server using pg_ctl
pg_ctl -D $PGDATA status
Check the stop PostgreSQL server using pg_ctl
pg_ctl -D $PGDATA stop
Check the start PostgreSQL server using pg_ctl
pg_ctl -D $PGDATA start
How to promote standby PostgreSQL server as Primary using pg_ctl
pg_ctl -D $PGDATA promote
So in this article, we have seen how to start stop and promote PostgreSQL server. Also seen how to check PostgreSQL server is running or not by using pg_ctl utility.