3 PostgreSQL documentation
6 <refentry id=
"app-pg-ctl">
8 <refentrytitle id=
"app-pg-ctl-title"><application>pg_ctl
</application></refentrytitle>
9 <manvolnum>1</manvolnum>
10 <refmiscinfo>Application
</refmiscinfo>
14 <refname>pg_ctl
</refname>
15 <refpurpose>start, stop, or restart a
<productname>PostgreSQL
</productname> server
</refpurpose>
18 <indexterm zone=
"app-pg-ctl">
19 <primary>pg_ctl
</primary>
25 <command>pg_ctl
</command>
26 <arg choice=
"plain">start
</arg>
28 <arg>-t
<replaceable>seconds
</replaceable></arg>
30 <arg>-D
<replaceable>datadir
</replaceable></arg>
31 <arg>-l
<replaceable>filename
</replaceable></arg>
32 <arg>-o
<replaceable>options
</replaceable></arg>
33 <arg>-p
<replaceable>path
</replaceable></arg>
37 <command>pg_ctl
</command>
38 <arg choice=
"plain">stop
</arg>
40 <arg>-t
<replaceable>seconds
</replaceable></arg>
42 <arg>-D
<replaceable>datadir
</replaceable></arg>
44 <group choice=
"plain">
47 <arg>i[mmediate]
</arg>
52 <command>pg_ctl
</command>
53 <arg choice=
"plain">restart
</arg>
55 <arg>-t
<replaceable>seconds
</replaceable></arg>
57 <arg>-D
<replaceable>datadir
</replaceable></arg>
60 <group choice=
"plain">
63 <arg>i[mmediate]
</arg>
66 <arg>-o
<replaceable>options
</replaceable></arg>
69 <command>pg_ctl
</command>
70 <arg choice=
"plain">reload
</arg>
72 <arg>-D
<replaceable>datadir
</replaceable></arg>
75 <command>pg_ctl
</command>
76 <arg choice=
"plain">status
</arg>
77 <arg>-D
<replaceable>datadir
</replaceable></arg>
80 <command>pg_ctl
</command>
81 <arg choice=
"plain">kill
</arg>
82 <arg><replaceable>signal_name
</replaceable></arg>
83 <arg><replaceable>process_id
</replaceable></arg>
86 <command>pg_ctl
</command>
87 <arg choice=
"plain">register
</arg>
88 <arg>-N
<replaceable>servicename
</replaceable></arg>
89 <arg>-U
<replaceable>username
</replaceable></arg>
90 <arg>-P
<replaceable>password
</replaceable></arg>
91 <arg>-D
<replaceable>datadir
</replaceable></arg>
93 <arg>-t
<replaceable>seconds
</replaceable></arg>
94 <arg>-o
<replaceable>options
</replaceable></arg>
97 <command>pg_ctl
</command>
98 <arg choice=
"plain">unregister
</arg>
99 <arg>-N
<replaceable>servicename
</replaceable></arg>
105 <refsect1 id=
"app-pg-ctl-description">
106 <title>Description
</title>
108 <application>pg_ctl
</application> is a utility for starting,
109 stopping, or restarting the
<productname>PostgreSQL
</productname>
110 backend server (
<xref linkend=
"app-postgres">), or displaying the
111 status of a running server. Although the server can be started
112 manually,
<application>pg_ctl
</application> encapsulates tasks such
113 as redirecting log output and properly detaching from the terminal
114 and process group. It also provides convenient options for
119 In
<option>start
</option> mode, a new server is launched. The
120 server is started in the background, and standard input is attached to
121 <filename>/dev/null
</filename>. The standard output and standard
122 error are either appended to a log file (if the
<option>-l
</option>
123 option is used), or redirected to
<application>pg_ctl
</application>'s
124 standard output (not standard error). If no log file is chosen, the
125 standard output of
<application>pg_ctl
</application> should be redirected
126 to a file or piped to another process such as a log rotating program
127 like
<application>rotatelogs<
/>; otherwise
<command>postgres
</command>
128 will write its output to the controlling terminal (from the background)
129 and will not leave the shell's process group.
133 In
<option>stop
</option> mode, the server that is running in
134 the specified data directory is shut down. Three different
135 shutdown methods can be selected with the
<option>-m
</option>
136 option:
<quote>Smart
</quote> mode waits for online backup mode
137 to finish and all the clients to disconnect. This is the default.
138 <quote>Fast
</quote> mode does not wait for clients to disconnect and
139 will terminate an online backup in progress. All active transactions are
140 rolled back and clients are forcibly disconnected, then the
141 server is shut down.
<quote>Immediate
</quote> mode will abort
142 all server processes without a clean shutdown. This will lead to
143 a recovery run on restart.
147 <option>restart
</option> mode effectively executes a stop followed
148 by a start. This allows changing the
<command>postgres
</command>
149 command-line options.
153 <option>reload
</option> mode simply sends the
154 <command>postgres
</command> process a
<systemitem>SIGHUP<
/>
155 signal, causing it to reread its configuration files
156 (
<filename>postgresql.conf
</filename>,
157 <filename>pg_hba.conf
</filename>, etc.). This allows changing of
158 configuration-file options that do not require a complete restart
163 <option>status
</option> mode checks whether a server is running in
164 the specified data directory. If it is, the
<acronym>PID
</acronym>
165 and the command line options that were used to invoke it are
170 <option>kill
</option> mode allows you to send a signal to a specified
171 process. This is particularly valuable for
<productname>Microsoft Windows<
/>
172 which does not have a
<application>kill<
/> command. Use
173 <literal>--help<
/> to see a list of supported signal names.
177 <option>register
</option> mode allows you to register a system service
178 on
<productname>Microsoft Windows<
/>.
182 <option>unregister
</option> mode allows you to unregister a system service
183 on
<productname>Microsoft Windows<
/>, previously registered with the
184 <option>register
</option> command.
188 <refsect1 id=
"app-pg-ctl-options">
189 <title>Options
</title>
194 <term><option>-c
</option></term>
197 Attempt to allow server crashes to produce core files, on platforms
198 where this available, by lifting any soft resource limit placed on
200 This is useful in debugging or diagnosing problems by allowing a
201 stack trace to be obtained from a failed server process.
207 <term><option>-D
<replaceable class=
"parameter">datadir
</replaceable></option></term>
210 Specifies the file system location of the database files. If
211 this is omitted, the environment variable
212 <envar>PGDATA
</envar> is used.
218 <term><option>-l
<replaceable class=
"parameter">filename
</replaceable></option></term>
221 Append the server log output to
222 <replaceable>filename
</replaceable>. If the file does not
223 exist, it is created. The
<systemitem>umask<
/> is set to
077, so access to
224 the log file from other users is disallowed by default.
230 <term><option>-m
<replaceable class=
"parameter">mode
</replaceable></option></term>
233 Specifies the shutdown mode.
<replaceable>mode
</replaceable>
234 can be
<literal>smart
</literal>,
<literal>fast
</literal>, or
235 <literal>immediate
</literal>, or the first letter of one of
242 <term><option>-o
<replaceable class=
"parameter">options
</replaceable></option></term>
245 Specifies options to be passed directly to the
246 <command>postgres
</command> command.
249 The options are usually surrounded by single or double
250 quotes to ensure that they are passed through as a group.
256 <term><option>-p
<replaceable class=
"parameter">path
</replaceable></option></term>
259 Specifies the location of the
<filename>postgres
</filename>
260 executable. By default the
<filename>postgres
</filename> executable is taken from the same
261 directory as
<command>pg_ctl
</command>, or failing that, the hard-wired
262 installation directory. It is not necessary to use this
263 option unless you are doing something unusual and get errors
264 that the
<filename>postgres
</filename> executable was not found.
270 <term><option>-s
</option></term>
273 Only print errors, no informational messages.
279 <term><option>-t
</option></term>
282 The number of seconds to wait when waiting for start or shutdown
289 <term><option>-w
</option></term>
292 Wait for the start or shutdown to complete. The default wait time
293 is
60 seconds. This is the default option for shutdowns. A successful
294 shutdown is indicated by removal of the
<acronym>PID
</acronym>
295 file. For starting up, a successful
<command>psql -l
</command>
296 indicates success.
<command>pg_ctl
</command> will attempt to
297 use the proper port for
<application>psql<
/>. If the environment variable
298 <envar>PGPORT
</envar> exists, that is used. Otherwise, it will see if a port
299 has been set in the
<filename>postgresql.conf
</filename> file.
300 If neither of those is used, it will use the default port that
301 <productname>PostgreSQL
</productname> was compiled with
302 (
5432 by default). When waiting,
<command>pg_ctl
</command> will
303 return an accurate exit code based on the success of the startup
310 <term><option>-W
</option></term>
313 Do not wait for start or shutdown to complete. This is the
314 default for starts and restarts.
320 <refsect2 id=
"app-pg-ctl-windows-options">
321 <title>Options for Windows
</title>
325 <term><option>-N
<replaceable class=
"parameter">servicename
</replaceable></option></term>
328 Name of the system service to register. The name will be used
329 as both the service name and the display name.
335 <term><option>-P
<replaceable class=
"parameter">password
</replaceable></option></term>
338 Password for the user to start the service.
344 <term><option>-U
<replaceable class=
"parameter">username
</replaceable></option></term>
347 User name for the user to start the service. For domain users, use the
348 format
<literal>DOMAIN\username
</literal>.
359 <title>Environment
</title>
363 <term><envar>PGDATA
</envar></term>
367 Default data directory location.
373 <term><envar>PGPORT
</envar></term>
377 Default port for
<xref linkend=
"app-psql"> (used by the -w option).
384 For additional server variables, see
<xref linkend=
"app-postgres">.
385 This utility, like most other
<productname>PostgreSQL<
/> utilities,
386 also uses the environment variables supported by
<application>libpq<
/>
387 (see
<xref linkend=
"libpq-envars">).
397 <term><filename>postmaster.pid
</filename></term>
401 The existence of this file in the data directory is used to help
402 <application>pg_ctl
</application> determine if the server is
403 currently running or not.
409 <term><filename>postmaster.opts
</filename></term>
412 <para>If this file exists in the data directory,
413 <application>pg_ctl
</application> (in
<option>restart
</option> mode)
414 will pass the contents of the file as options to
415 <application>postgres
</application>, unless overridden
416 by the
<option>-o
</option> option. The contents of this file
417 are also displayed in
<option>status
</option> mode.
423 <term><filename>postgresql.conf
</filename></term>
427 This file, located in the data directory, is parsed to find the
428 proper port to use with
<application>psql
</application> when the
429 <option>-w
</option> is given in
<option>start
</option> mode.
442 Waiting for complete start is not a well-defined operation and might
443 fail if access control is set up so that a local client cannot
444 connect without manual interaction (e.g., password authentication). For
445 additional connection variables, see
<xref linkend=
"libpq-envars">,
446 and for passwords, also see
<xref linkend=
"libpq-pgpass">.
451 <refsect1 id=
"R1-APP-PGCTL-2">
452 <title>Examples
</title>
454 <refsect2 id=
"R2-APP-PGCTL-3">
455 <title>Starting the Server
</title>
458 To start up a server:
460 <prompt>$
</prompt> <userinput>pg_ctl start
</userinput>
465 An example of starting the server, blocking until the server has
468 <prompt>$
</prompt> <userinput>pg_ctl -w start
</userinput>
473 For a server using port
5433, and
474 running without
<function>fsync
</function>, use:
476 <prompt>$
</prompt> <userinput>pg_ctl -o
"-F -p 5433" start
</userinput>
481 <refsect2 id=
"R2-APP-PGCTL-4">
482 <title>Stopping the Server
</title>
485 <prompt>$
</prompt> <userinput>pg_ctl stop
</userinput>
487 stops the server. Using the
<option>-m
</option> switch allows one
488 to control
<emphasis>how
</emphasis> the backend shuts down.
492 <refsect2 id=
"R2-APP-PGCTL-5">
493 <title>Restarting the Server
</title>
496 Restarting the server is almost equivalent to stopping the
497 server and starting it again
498 except that
<command>pg_ctl
</command> saves and reuses the command line options that
499 were passed to the previously running instance. To restart
500 the server in the simplest form, use:
502 <prompt>$
</prompt> <userinput>pg_ctl restart
</userinput>
508 waiting for it to shut down and to come up:
510 <prompt>$
</prompt> <userinput>pg_ctl -w restart
</userinput>
515 To restart using port
5433 and disabling
<function>fsync<
/> after restarting:
517 <prompt>$
</prompt> <userinput>pg_ctl -o
"-F -p 5433" restart
</userinput>
522 <refsect2 id=
"R2-APP-PGCTL-6">
523 <title>Showing the Server Status
</title>
526 Here is a sample status output from
527 <application>pg_ctl
</application>:
529 <prompt>$
</prompt> <userinput>pg_ctl status
</userinput>
531 pg_ctl: server is running (pid:
13718)
533 /usr/local/pgsql/bin/postgres '-D' '/usr/local/pgsql/data' '-p' '
5433' '-B' '
128'
536 This is the command line that would be invoked in restart mode.
543 <title>See Also
</title>
546 <xref linkend=
"app-postgres">