A server utility for controlling the PostgreSQL server

pg_ctl is a server utility for starting, stopping and restarting the PostgreSQL server; it can also be used to execute initdb, reload the server configuration, promote a standby to primary, and display the server status. On Windows systems pg_ctl can also be used to register/unregister PostgreSQL as a service.

pg_ctl was added in PostgreSQL 7.0.


Shutdown modes

The basic command to shut down a PostgreSQL instance is:

pg_ctl -D /path/to/data/directory stop [ -m mode ]

note that pgctl stop shuts down a running PostgreSQL server in one of three modes - fast, smart, and immediate, which can optionally be specified via the -m option

  • fast rolls back active transactions, forcibly disconnects clients and stops any online backup; this is the default from PostgreSQL 9.5 and should execute quite quickly.
  • smart waits for until all active clients are disconnects and any online backups completed before shutting down; depending on system activity it can therefore take some time before the shutdown finally takes place. This was the default up until PostgreSQL 9.4.
  • immediate aborts all processes immediately and is effectively a server crash; PostgreSQL will initially run in crash recovery mode when next started. There is a risk of data loss when using this shutdown mode and it should only be used in emergencies.

Change history

  • PostgreSQL documentation: pg_ctl


Configuration, Management / adminstration, Server utility

See also

initdb, pg_reload_conf()