January 5, 2020

How to start and stop PostgreSQL server - pg_ctl tool

Postgres pg_ctl commands

pg_ctl -- initialize, start, stop, or control a PostgreSQL server

pg_ctl [ status | start | stop | restart | reload | init ] [-U username] [-P password] [--help]


pg_ctl --version
pg_ctl --help
Usage:
  pg_ctl init[db]   [-D DATADIR] [-s] [-o OPTIONS]
  pg_ctl start      [-D DATADIR] [-l FILENAME] [-W] [-t SECS] [-s] [-o OPTIONS] [-p PATH] [-c]
  pg_ctl stop       [-D DATADIR] [-m SHUTDOWN-MODE] [-W] [-t SECS] [-s]
  pg_ctl restart    [-D DATADIR] [-m SHUTDOWN-MODE] [-W] [-t SECS] [-s] [-o OPTIONS] [-c]
  pg_ctl reload     [-D DATADIR] [-s]
  pg_ctl status     [-D DATADIR]
  pg_ctl promote    [-D DATADIR] [-W] [-t SECS] [-s]
  pg_ctl logrotate  [-D DATADIR] [-s]
  pg_ctl kill       SIGNALNAME PID

Common options:
  -D, --pgdata=DATADIR   location of the database storage area
  -s, --silent            only print errors, no informational messages
  -t, --timeout=SECS  seconds to wait when using -w option
  -V, --version          output version information, then exit
  -w, --wait              wait until operation completes (default)
  -W, --no-wait          do not wait until operation completes
  -?, --help              show this help, then exit
If the -D option is omitted, the environment variable PGDATA is used.

Options for start or restart:
  -c, --core-files        allow postgres to produce core files
  -l, --log=FILENAME      write (or append) server log to FILENAME
  -o, --options=OPTIONS  command line options to pass to postgres (PostgreSQL server executable) or initdb
  -p PATH-TO-POSTGRES    normally not necessary

Allowed signal names for kill:
  ABRT HUP INT KILL QUIT TERM USR1 USR2


pg_ctl init[db] [-s] [-D datadir] [-o initdb-options]
pg_ctl -D /usr/local/pgsql/data initdb

pg_ctl start [-w] [-t seconds] [-s] [-D datadir] [-l filename] [-o options] [-p path] [-c]
pg_ctl start
pg_ctl -w start
pg_ctl -D /data/postgres/13.6/5304 start
pg_ctl start -l /data/logs
pg_ctl -o "-F -p 5433" start

pg_ctl stop [-W] [-t seconds] [-s] [-D datadir] [-m s[mart] | f[ast] | i[mmediate] ]
pg_ctl stop
pg_ctl stop -D /Library/PostgreSQL/14.5/data
pg_ctl --pgdata /usr/local/var/postgres stop
pg_ctl stop -m fast
pg_ctl stop -m smart
pg_ctl stop -m immediate
pg_ctl stop -w -l /home/pg/logs
pg_ctl -D /usr/local/pgsql/data stop -m fast

pg_ctl status [-D datadir]
pg_ctl status
pg_ctl -D /data/postgres/12.7/5301 status
pg_ctl -D /opt/data/pg9-9.5.0/data/5361 status 

pg_ctl reload [-s] [-D datadir]
pg_ctl reload
pg_ctl -D /u01/data/pg/15.3/5310 reload

pg_ctl promote [-s] [-D datadir]
pg_ctl -D /data/postgresql/14/5308 promote                --Failover to standby

pg_ctl restart [-w] [-t seconds] [-s] [-D datadir] [-c] [-m s[mart] | f[ast] | i[mmediate] ] [-o options]
pg_ctl restart
pg_ctl -w restart
pg_ctl -o "-F -p 5433" restart
pg_ctl -D /usr/local/pgsql/data restart

pg_ctl kill signal_name process_id
pg_ctl register [-N servicename] [-U username] [-P password] [-D datadir] [-S a[uto] | d[emand] ] [-w] [-t seconds] [-s] [-o options]
pg_ctl unregister [-N servicename]


Related PostgreSQL Articles:  PostgreSQL psql utility  PostgreSQL DBA Interview Questions and answers

No comments:

Post a Comment