pg_ctl
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.
Usage
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 12
- PostgreSQL 11
kill
option added (commit 2e83db3a)
- PostgreSQL 10
- defaults to waiting (command line option
-w
/--wait
) for all actions, includingstart
(commit 05cd12ed) - long option
--option
for existing option-o
added (commit caf936b0) - now checks for postmaster startup 10 times per second, instead of once (commit c61559ec)
- checks postmaster.pid for postmaster status, rather than attempting to connect (commit f13ea95f)
- always exits with a non-zero status if an operation does not complete within the specified timeout (commit 1bac5f55)
- defaults to waiting (command line option
- PostgreSQL 9.5
- PostgreSQL 9.4
- now returns exit code
4
if the specified data directory is inaccessible (commit 11d205e2)
- now returns exit code
- PostgreSQL 9.1
promote
option added (commit 4695da5a)
- PostgreSQL 9.0
- PostgreSQL 8.4
restart
option preserves command-line arguments (commit 067f1e5f)
- PostgreSQL 8.3
- PostgreSQL 8.0
- PostgreSQL 7.2
reload
option added to to sendSIGHUP
(commit 196700c3)
- PostgreSQL 7.0
- added (commit 5b912b08)
References
- PostgreSQL documentation: pg_ctl