PostgreSQL – PG_CTL Utility

PostgreSQL – PG_CTL Utility

pg_ctl is a utility for initializing, starting, stopping, or restarting the PostgreSQL database server or displaying the status of a running server.

#pg_ctl --help
pg_ctl is a utility to initialize, start, stop, or control a PostgreSQL server.

Usage:
pg_ctl init[db] [-D DATADIR] [-s] [-o "OPTIONS"]
pg_ctl start [-w] [-t SECS] [-D DATADIR] [-s] [-l FILENAME] [-o "OPTIONS"]
pg_ctl stop [-W] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]
pg_ctl restart [-w] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]
[-o "OPTIONS"]
pg_ctl reload [-D DATADIR] [-s]
pg_ctl status [-D DATADIR]
pg_ctl promote [-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 until operation completes
-W do not wait until operation completes
-?, --help show this help, then exit
(The default is to wait for shutdown, but not for start or restart.)

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 command line options to pass to postgres
(PostgreSQL server executable) or initdb
-p PATH-TO-POSTGRES normally not necessary

Options for stop or restart:
-m, --mode=MODE MODE can be "smart", "fast", or "immediate"

Shutdown modes are:
smart quit after all clients have disconnected
fast quit directly, with proper shutdown
immediate quit without complete shutdown; will lead to recovery on restart

I wanted to test the difference in effect between “pg_ctl restart” and “pg_ctl reload”.

In session1, I run the following:

session1=# start transaction;
START TRANSACTION
session1=# update customer set title='Mrs' where customer_id='20';
UPDATE 1

PG_CTL RELOAD

Now, I execute “reload command” in session2.

session2$ pg_ctl reload
server signaled

Back to session1.

session1=# end;
COMMIT

It works. The connection was not dropped or affected.

PG_CTL RESTART

Now, I execute “restart¬†command” in session2.

session2$ pg_ctl restart -m immediate
waiting for server to shut down.... done
server stopped
server starting

Back to session1.

session1# end;
server closed the connection unexpectedly
This probably means the server terminated abnormally
before or while processing the request.
The connection to the server was lost. Attempting reset: Succeeded.

Summary

pg_ctl restart will cause the a full restart of the postgres server while pg_ ctl reload will only allow postmaster to reread the configuration files and reload the settings. This effect is similar to Linux service reload.

Regards,
Wei Shan

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: