Documentation Source: Link
Utility command to interact with Postgres Database server/cluster
- Start/Stop/restart Postgres Database server/cluster
- Display status of running server
- pg_ctl init/initdb [ -D -s -o] – creates a new PostgreSQL database cluster.
Invokes the initfb command.
- pg_ctl start [-D -l -W -t -s -o -p -c] – Turns on server
- pg_ctl stop [-D -l -m -W -t -s] – Shuts down the server that is running in the specified data directory. Three different shutdown methods can be selected with the -m option:
- Smart – waits for all active clients to disconnect and any online backup to finish.
- Fast – (the default) does not wait for clients to disconnect and will terminate an online backup in progress. All active transactions are rolled back and clients are forcibly disconnected, then the server is shut down.
- Immediate – mode will abort all server processes immediately, without a clean shutdown. This choice will lead to a crash-recovery cycle during the next server start.
- pg_ctl restart [-D -m -W -t -s] – restarts with options on how to start up again
- pg_ctl reload [-D -s] – self explanatory
- pg_ctl status [-D] – checks whether a server is running in the specified data directory. If it is, the server’s PID and the command line options that were used to invoke it are displayed. If the server is not running, pg_ctl returns an exit status of 3. If an accessible data directory is not specified, pg_ctl returns an exit status of 4.
- pg_ctl promote [-D -W -t -s] – Commands the standby server that is running in the specified data directory to end standby mode and begin read-write operations.
- pg_ctl kill [SIGNITURE PID] – N/A
- pg_ctl register [-D -N -U -P -S -e -W -t -s -o] – Registers server
- pg_ctl unregister [-N SERVICENAME] – Unregisters server
- -c/–core-files – Core Files
- -D/–pgdata= – datadir. Specifies location of the database configuration files. If this option is not used the PGDATA environment is used.
- -l/–log= – filename. append server out put to the filename given.
- -m/–mode – mode. specifies shut down mode. options are smart, fast & immediate. Fast is the default mode
- -o/–options – options. Extra options to be passed in the postgres command. Can be used multiple times in one command.
- -p – path. Location of file we want to execute. By default it will be the same file directory as pg_ctl.
- -s/–silent – silent. Print only errors and no other details or descriptions.
- -t/–timout= – seconds. How many seconds to wait before we timeout.
- -V/–version – Version.Print version of pg_ctl we are using
- -w/–wait – Wait
- -W/–no-wait – Dont Wait
- -?/–help – Give me info on the command
Command options Just for windows:
- -e – source.
- -N – servicename
- -P – Password for user to run service as.
- -S – startype
- -U – username. username for the user to run service as.
pg_ctl commands require knowing the filepath to your data directory.
PGDATA – Default file-path for data directory.
- postmaster.id – pg_ctl checks this file to see if the server is currently running.