pg_ctl
pg_ctl
pg_ctl
pg_ctl
pg_ctl
pg_ctl
+
On Microsoft Windows, also:
+
pg_ctl
The init or initdb mode creates a new
-
PostgreSQL database cluster
. A database
- cluster is a collection of databases that ar e managed by a single
+
PostgreSQL database cluster
, that is,
+ a collection of databases that will b e managed by a single
server instance. This mode invokes the initdb
command. See for details.
- In start mode, a new server is launched . The
+ start mode launches a new server . The
server is started in the background, and its standard input is attached
to /dev/null (or nul> on Windows).
On Unix-like systems, by default, the server's standard output and
- In stop mode, the server that is running in
- the specified data directory is shut down . Three different
+ stop mode shuts down the server that is running in
+ the specified data directory. Three different
shutdown methods can be selected with the -m
option. Smart
mode waits for all active
clients to disconnect and any online backup to finish.
will terminate an online backup in progress. All active transactions are
rolled back and clients are forcibly disconnected, then the
server is shut down. Immediate
mode will abort
- all server processes immediately, without a clean shutdown.
- This will lead to a crash-recovery run on the next re start.
+ all server processes immediately, without a clean shutdown. This choice
+ will lead to a crash-recovery cycle during the next server start.
restart mode effectively executes a stop followed
by a start. This allows changing the postgres
- command-line options. restart might fail if
- relative paths specified were specified on the command-line during
- server start.
+ command-line options, or changing configuration-file options that
+ cannot be changed without restarting the server.
+ If relative paths were used on the command line during server
+ start, restart might fail unless
+
pg_ctl is executed in the same current
+ directory as it was during server start.
reload mode simply sends the
- postgres process a SIGHUP>
+ postgres server process a SIGHUP>
signal, causing it to reread its configuration files
(postgresql.conf ,
- pg_hba.conf , etc.). This allows changing of
- configuration-file options that do not require a complete restart
+ pg_hba.conf , etc.). This allows changing
+ configuration-file options that do not require a full server restart
to take effect.
status mode checks whether a server is running in
- the specified data directory. If it is, the
PID
- and the command line options that were used to invoke it are
- displayed. If the server is not running, the process returns an
- exit status of 3. If an accessible data directory is not specified,
- the process returns an exit status of 4.
+ the specified data directory. If it is, the
server's PID
+ and the command line options that were used to invoke it are displayed.
+ If the server is not running,
pg_ctl returns
+ an exit status of 3. If an accessible data directory is not
+
specified, pg_ctl returns an exit status of 4.
- In promote mode, the standby server that is
- running in the specified data directory is commanded to exit
- recovery and begin read-write operations.
+ promote mode commands the standby server that is
+ running in the specified data directory to end standby mode
+ and begin read-write operations.
- kill mode allows you to send a signal to a specified
-
process. This is particularly valuable for Microsoft Windows>
-
which does not have a kill> command. Use
- --help> to see a list of supported signal names.
+ kill mode sends a signal to a specified process.
+
This is primarily valuable on Microsoft Windows>
+
which does not have a built-in kill> command. Use
+ --help> to see a list of supported signal names.
- register mode allows you to register a system service
- on
Microsoft Windows>. The -S option
- allows selection of service start type, either auto
(start
- service automatically on system startup) or demand
(start
- service on demand).
+
register mode
registers the PostgreSQL>
+ server as a system service on
Microsoft Windows>.
+ The -S option allows selection of service start type,
+ either auto
(start service automatically on system startup)
+ or demand
(start service on demand).
- unregister mode allows you to unregister a system service
+ unregister mode unregisters a system service
on
Microsoft Windows>. This undoes the effects of the
register command.
-c
- --core-file
+ --core-files
Attempt to allow server crashes to produce core files, on platforms
Specifies the file system location of the database configuration files. If
- this is omitted, the environment variable
+ this option is omitted, the environment variable
PGDATA is used.
Specifies the shutdown mode. mode
can be smart , fast , or
immediate , or the first letter of one of
- these three. If this is omitted, fast is used.
+ these three. If this option is omitted, fast is
+ the default.
Specifies options to be passed directly to the
- postgres command; multiple
- option invocations are appended.
+ postgres command.
+ -o> can be specified multiple times, with all the given
+ options being passed through.
- The options should usually be surrounded by single or double
- quotes to ensure that they are passed through as a group.
+ The options> should usually be surrounded by single or
+ double quotes to ensure that they are passed through as a group.
Specifies options to be passed directly to the
initdb command.
+ -o> can be specified multiple times, with all the given
+ options being passed through.
- The options should usually be surrounded by single or double
- quotes to ensure that they are passed through as a group.
+ The options> should usually be surrounded by single or
+ double quotes to ensure that they are passed through as a group.
- -t
- --timeout
+ -t seconds
+ --timeout=seconds
- The maximum number of seconds to wait when waiting for an operatio n
- to complete (see option -w ). Defaults to the value of the
- PGCTLTIMEOUT> environment variable or, if not set, to 60
- seconds.
+ Specifies the maximum number of seconds to wait when waiting for a n
+ operation to complete (see option -w ). Defaults to
+ the value of the PGCTLTIMEOUT> environment variable or, if
+ not set, to 60 seconds.
--wait
- Wait for an operation to complete. This is supported for the
+ Wait for the operation to complete. This is supported for the
modes start , stop ,
restart , promote ,
and register , and is the default for those modes.
attempts to connect to the server.
When waiting for shutdown, pg_ctl waits for
the server to remove its
PID file.
- This option allows the entry of an
SSL> passphrase on startup.
pg_ctl returns an exit code based on the
success of the startup or shutdown.
--no-wait
- Do not wait for an operation to complete. This is the opposite of the
- option -w .
+ Do not wait for the operation to complete. This is the opposite of
+ the option -w .
+ If an option is specified that is valid, but not relevant to the selected
+ operating mode,
pg_ctl ignores it.
+
+
Options for Windows
Name of the event source for
pg_ctl to use
for logging to the event log when running as a Windows service. The
default is PostgreSQL . Note that this only controls
-
the logging from
pg_ctl itself; once
+
messages sent from
pg_ctl itself; once
started, the server will use the event source specified
- by . Should the server fail during
- early startup, it might also log using the default event
- source PostgreSQL .
+ by its parameter. Should the server
+ fail very early in startup, before that parameter has been set,
+ it might also log using the default event
+ source name PostgreSQL .
-N servicename
- Name of the system service to register. The name will be used
+ Name of the system service to register. This name will be used
as both the service name and the display name.
+ The default is PostgreSQL .
-P password
- Password for the user to start the service .
+ Password for the user to run the service as .
-S start-type
- Start type of the system service to register. start-type can
+ Start type of the system service. start-type> can
be auto , or demand , or
- the first letter of one of these two. If this is omitted,
- auto is used .
+ the first letter of one of these two. If this option is omitted,
+ auto is the default .
-U username
- User name for the user to start the service . For domain users, use the
+ User name for the user to run the service as . For domain users, use the
format DOMAIN\username .
+ Most pg_ctl modes require knowing the data directory
+ location; therefore, the -D> option is required
+ unless PGDATA is set.
+
+
pg_ctl , like most other
PostgreSQL>
utilities,
also uses the environment variables supported by
libpq>
(see ).
- For additional server variables, see .
+
+
+ For additional variables that affect the server,
+ see .
- The existence of this file in the data directory is used to help
-
pg_ctl determine if the server is
- currently running.
+
pg_ctl examines this file in the data
+ directory to determine whether the server is currently running.
Starting the Server
- To start the server:
-
-
-
-
To start the server, waiting until the server is
accepting connections:
Restarting the server is almost equivalent to stopping the
- server and starting it again,
- except that pg_ctl saves and reuses the command line options that
- were passed to the previously running instance. To restart
- the server in the simplest form, use:
-
-
-
-
- To restart the server,
- waiting for it to shut down and restart:
+ server and starting it again, except that by default,
+ pg_ctl saves and reuses the command line options that
+ were passed to the previously-running instance. To restart
+ the server using the same options as before, use:
+ But if -o> is specified, that replaces any previous options.
To restart using port 5433, disabling fsync> upon restart:
$ pg_ctl -o "-F -p 5433" restart
/usr/local/pgsql/bin/postgres "-D" "/usr/local/pgsql/data" "-p" "5433" "-B" "128"
- This is the command line that would be invoked in restart mode.
+ The second line is the command that would be invoked in restart mode.
{
printf(_("%s is a utility to initialize, start, stop, or control a PostgreSQL server.\n\n"), progname);
printf(_("Usage:\n"));
- printf(_(" %s init[db] [-D DATADIR] [-s] [-o \"OPTIONS\"]\n"), progname);
- printf(_(" %s start [-w] [-t SECS] [-D DATADIR] [-s] [-l FILENAME] [-o \"OPTIONS\"]\n"), progname);
- printf(_(" %s stop [-W] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]\n"), progname);
- printf(_(" %s restart [-w] [-t SECS] [-D DATADIR] [-s] [-m SHUTDOWN-MODE]\n"
- " [-o \"OPTIONS\"]\n"), progname);
- printf(_(" %s reload [-D DATADIR] [-s]\n"), progname);
- printf(_(" %s status [-D DATADIR]\n"), progname);
- printf(_(" %s promote [-w] [-t SECS] [-D DATADIR] [-s]\n"), progname);
- printf(_(" %s kill SIGNALNAME PID\n"), progname);
+ printf(_(" %s init[db] [-D DATADIR] [-s] [-o OPTIONS]\n"), progname);
+ printf(_(" %s start [-D DATADIR] [-l FILENAME] [-W] [-t SECS] [-s]\n"
+ " [-o OPTIONS] [-p PATH] [-c]\n"), progname);
+ printf(_(" %s stop [-D DATADIR] [-m SHUTDOWN-MODE] [-W] [-t SECS] [-s]\n"), progname);
+ printf(_(" %s restart [-D DATADIR] [-m SHUTDOWN-MODE] [-W] [-t SECS] [-s]\n"
+ " [-o OPTIONS] [-c]\n"), progname);
+ printf(_(" %s reload [-D DATADIR] [-s]\n"), progname);
+ printf(_(" %s status [-D DATADIR]\n"), progname);
+ printf(_(" %s promote [-D DATADIR] [-W] [-t SECS] [-s]\n"), progname);
+ printf(_(" %s kill SIGNALNAME PID\n"), progname);
#ifdef WIN32
- printf(_(" %s register [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR ]\n"
- " [-S START-TYPE] [-w] [-t SECS] [-o \"OPTIONS\" ]\n"), progname);
+ printf(_(" %s register [-D DATADIR] [-N SERVICENAME] [-U USERNAME] [-P PASSWORD ]\n"
+ " [-S START-TYPE] [-e SOURCE] [-W] [-t SECS] [-s] [-o OPTIONS ]\n"), progname);
printf(_(" %s unregister [-N SERVICENAME]\n"), progname);
#endif
printf(_(" -w, --wait wait until operation completes (default)\n"));
printf(_(" -W, --no-wait do not wait until operation completes\n"));
printf(_(" -?, --help show this help, then exit\n"));
- printf(_("(The default is to wait for shutdown, but not for start or restart.)\n\n"));
printf(_("If the -D option is omitted, the environment variable PGDATA is used.\n"));
printf(_("\nOptions for start or restart:\n"));
printf(_("\nShutdown modes are:\n"));
printf(_(" smart quit after all clients have disconnected\n"));
- printf(_(" fast quit directly, with proper shutdown\n"));
+ printf(_(" fast quit directly, with proper shutdown (default) \n"));
printf(_(" immediate quit without complete shutdown; will lead to recovery on restart\n"));
printf(_("\nAllowed signal names for kill:\n"));
/* process command-line options */
while (optind < argc)
{
- while ((c = getopt_long(argc, argv, "cD:e:l:m:N:o:p:P:sS:t:U:wW", long_options, &option_index)) != -1)
+ while ((c = getopt_long(argc, argv, "cD:e:l:m:N:o:p:P:sS:t:U:wW",
+ long_options, &option_index)) != -1)
{
switch (c)
{