LinuxCommandLibrary

pg_ctl

TLDR

Start PostgreSQL

$ pg_ctl start -D [/var/lib/postgresql/data]
copy
Stop PostgreSQL
$ pg_ctl stop -D [/var/lib/postgresql/data]
copy
Restart PostgreSQL
$ pg_ctl restart -D [/var/lib/postgresql/data]
copy
Reload configuration
$ pg_ctl reload -D [/var/lib/postgresql/data]
copy
Check status
$ pg_ctl status -D [/var/lib/postgresql/data]
copy

SYNOPSIS

pg_ctl action [-D datadir] [options]

DESCRIPTION

pg_ctl is a utility for initializing, starting, stopping, and controlling a PostgreSQL database server. It's the preferred method for managing PostgreSQL services.

PARAMETERS

start

Start the server.
stop
Stop the server.
restart
Stop then start.
reload
Reload configuration.
status
Check server status.
-D directory
Data directory.
-m mode
Shutdown mode (smart, fast, immediate).
-l file
Log file.
-w
Wait for completion.

EXAMPLES

$ # Start with logging
pg_ctl start -D /data -l /var/log/postgresql.log

# Fast shutdown
pg_ctl stop -D /data -m fast

# Initialize new cluster
pg_ctl initdb -D /data

# Promote standby
pg_ctl promote -D /data
copy

SHUTDOWN MODES

$ smart     - Wait for clients to disconnect
fast      - Rollback active transactions (default)
immediate - Abort immediately (may corrupt)
copy

CAVEATS

Must run as PostgreSQL user. Data directory required. Use systemctl on systemd systems.

HISTORY

pg_ctl is part of PostgreSQL, the open source database originally from UC Berkeley's POSTGRES project.

SEE ALSO

Copied to clipboard