2 $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.24 2003/11/01 01:56:29 petere Exp $
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>
24 <command>pg_ctl</command>
25 <arg choice="plain">start</arg>
28 <arg>-D <replaceable>datadir</replaceable></arg>
29 <arg>-l <replaceable>filename</replaceable></arg>
30 <arg>-o <replaceable>options</replaceable></arg>
31 <arg>-p <replaceable>path</replaceable></arg>
33 <command>pg_ctl</command>
34 <arg choice="plain">stop</arg>
37 <arg>-D <replaceable>datadir</replaceable></arg>
39 <group choice="plain">
42 <arg>i[mmediate]</arg>
46 <command>pg_ctl</command>
47 <arg choice="plain">restart</arg>
50 <arg>-D <replaceable>datadir</replaceable></arg>
52 <group choice="plain">
55 <arg>i[mmediate]</arg>
58 <arg>-o <replaceable>options</replaceable></arg>
60 <command>pg_ctl</command>
61 <arg choice="plain">reload</arg>
63 <arg>-D <replaceable>datadir</replaceable></arg>
65 <command>pg_ctl</command>
66 <arg choice="plain">status</arg>
67 <arg>-D <replaceable>datadir</replaceable></arg>
72 <refsect1 id="app-pg-ctl-description">
73 <title>Description</title>
75 <application>pg_ctl</application> is a utility for starting,
76 stopping, or restarting the <productname>PostgreSQL</productname>
77 backend server (<xref linkend="app-postmaster">), or displaying the
78 status of a running server. Although the server can be started
79 manually, <application>pg_ctl</application> encapsulates tasks such
80 as redirecting log output and properly detaching from the terminal
81 and process group. It also provides convenient options for
86 In <option>start</option> mode, a new server is launched. The
87 server is started in the background, and standard input is attached to
88 <filename>/dev/null</filename>. The standard output and standard
89 error are either appended to a log file (if the <option>-l</option>
90 option is used), or redirected to <application>pg_ctl</application>'s
91 standard output (not standard error). If no log file is chosen, the
92 standard output of <application>pg_ctl</application> should be redirected
93 to a file or piped to another process, for example a log rotating program,
94 otherwise <command>postmaster</command> will write its output to the controlling
95 terminal (from the background) and will not leave the shell's
100 In <option>stop</option> mode, the server that is running in
101 the specified data directory is shut down. Three different
102 shutdown methods can be selected with the <option>-m</option>
103 option: <quote>Smart</quote> mode waits for all the clients to
104 disconnect. This is the default. <quote>Fast</quote> mode does
105 not wait for clients to disconnect. All active transactions are
106 rolled back and clients are forcibly disconnected, then the
107 server is shut down. <quote>Immediate</quote> mode will abort
108 all server processes without a clean shutdown. This will lead to
109 a recovery run on restart.
113 <option>restart</option> mode effectively executes a stop followed
114 by a start. This allows changing the <command>postmaster</command>
115 command-line options.
119 <option>reload</option> mode simply sends the
120 <command>postmaster</command> process a <systemitem>SIGHUP</>
121 signal, causing it to reread its configuration files
122 (<filename>postgresql.conf</filename>,
123 <filename>pg_hba.conf</filename>, etc.). This allows changing of
124 configuration-file options that do not require a complete restart
129 <option>status</option> mode checks whether a server is running in
130 the specified data directory. If it is, the <acronym>PID</acronym>
131 and the command line options that were used to invoke it are
136 <refsect1 id="app-pg-ctl-options">
137 <title>Options</title>
143 <term><option>-D <replaceable class="parameter">datadir</replaceable></option></term>
146 Specifies the file system location of the database files. If
147 this is omitted, the environment variable
148 <envar>PGDATA</envar> is used.
154 <term><option>-l <replaceable class="parameter">filename</replaceable></option></term>
157 Append the server log output to
158 <replaceable>filename</replaceable>. If the file does not
159 exist, it is created. The <systemitem>umask</> is set to 077, so access to
160 the log file from other users is disallowed by default.
166 <term><option>-m <replaceable class="parameter">mode</replaceable></option></term>
169 Specifies the shutdown mode. <replaceable>mode</replaceable>
170 may be <literal>smart</literal>, <literal>fast</literal>, or
171 <literal>immediate</literal>, or the first letter of one of
178 <term><option>-o <replaceable class="parameter">options</replaceable></option></term>
181 Specifies options to be passed directly to the
182 <command>postmaster</command> command.
185 The options are usually surrounded by single or double
186 quotes to ensure that they are passed through as a group.
192 <term><option>-p <replaceable class="parameter">path</replaceable></option></term>
195 Specifies the location of the <filename>postmaster</filename>
196 executable. By default the <filename>postmaster</filename> executable is taken from the same
197 directory as <command>pg_ctl</command>, or failing that, the hard-wired
198 installation directory. It is not necessary to use this
199 option unless you are doing something unusual and get errors
200 that the <filename>postmaster</filename> executable was not found.
206 <term><option>-s</option></term>
209 Only print errors, no informational messages.
215 <term><option>-w</option></term>
218 Wait for the start or shutdown to complete. Times out after
219 60 seconds. This is the default for shutdowns. A successful
220 shutdown is indicated by removal of the <acronym>PID</acronym>
221 file. For starting up, a successful <command>psql -l</command>
222 indicates success. <command>pg_ctl</command> will attempt to
223 use the proper port for <application>psql</>. If the environment variable
224 <envar>PGPORT</envar> exists, that is used. Otherwise, it will see if a port
225 has been set in the <filename>postgresql.conf</filename> file.
226 If neither of those is used, it will use the default port that
227 <productname>PostgreSQL</productname> was compiled with
234 <term><option>-W</option></term>
237 Do not wait for start or shutdown to complete. This is the
238 default for starts and restarts.
248 <title>Environment</title>
252 <term><envar>PGDATA</envar></term>
256 Default data directory location.
262 <term><envar>PGPORT</envar></term>
266 Default port for <xref linkend="app-psql"> (used by the -w option).
273 For others, see <xref linkend="app-postmaster">.
283 <term><filename>postmaster.pid</filename></term>
287 The existence of this file in the data directory is used to help
288 <application>pg_ctl</application> determine if the server is
289 currently running or not.
295 <term><filename>postmaster.opts.default</filename></term>
299 If this file exists in the data directory,
300 <application>pg_ctl</application> (in <option>start</option>
301 mode) will pass the contents of the file as options to the
302 <command>postmaster</command> command, unless overridden by the
303 <option>-o</option> option.
309 <term><filename>postmaster.opts</filename></term>
312 <para>If this file exists in the data directory,
313 <application>pg_ctl</application> (in <option>restart</option> mode)
314 will pass the contents of the file as options to the
315 <application>postmaster</application>, unless overridden
316 by the <option>-o</option> option. The contents of this file
317 are also displayed in <option>status</option> mode.
323 <term><filename>postgresql.conf</filename></term>
327 This file, located in the data directory, is parsed to find the
328 proper port to use with <application>psql</application> when the
329 <option>-w</option> is given in <option>start</option> mode.
342 Waiting for complete start is not a well-defined operation and may
343 fail if access control is set up so that a local client cannot
344 connect without manual interaction (e.g., password authentication).
349 <refsect1 id="R1-APP-PGCTL-2">
350 <title>Examples</title>
352 <refsect2 id="R2-APP-PGCTL-3">
353 <title>Starting the Server</title>
356 To start up a server:
358 <prompt>$</prompt> <userinput>pg_ctl start</userinput>
363 An example of starting the server, blocking until the server has
366 <prompt>$</prompt> <userinput>pg_ctl -w start</userinput>
371 For a server using port 5433, and
372 running without <function>fsync</function>, use:
374 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" start</userinput>
379 <refsect2 id="R2-APP-PGCTL-4">
380 <title>Stopping the Server</title>
383 <prompt>$</prompt> <userinput>pg_ctl stop</userinput>
385 stops the server. Using the <option>-m</option> switch allows one
386 to control <emphasis>how</emphasis> the backend shuts down.
390 <refsect2 id="R2-APP-PGCTL-5">
391 <title>Restarting the Server</title>
394 Restarting the server is almost equivalent to stopping the
395 server and starting it again
396 except that <command>pg_ctl</command> saves and reuses the command line options that
397 were passed to the previously running instance. To restart
398 the server in the simplest form, use:
400 <prompt>$</prompt> <userinput>pg_ctl restart</userinput>
406 waiting for it to shut down and to come up:
408 <prompt>$</prompt> <userinput>pg_ctl -w restart</userinput>
413 To restart using port 5433 and disabling <function>fsync</> after restarting:
415 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" restart</userinput>
420 <refsect2 id="R2-APP-PGCTL-6">
421 <title>Showing the Server Status</title>
424 Here is a sample status output from
425 <application>pg_ctl</application>:
427 <prompt>$</prompt> <userinput>pg_ctl status</userinput>
429 pg_ctl: postmaster is running (pid: 13718)
431 /usr/local/pgsql/bin/postmaster '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'
434 This is the command line that would be invoked in restart mode.
441 <title>See Also</title>
444 <xref linkend="app-postmaster">
450 <!-- Keep this comment at the end of the file
455 sgml-minimize-attributes:nil
456 sgml-always-quote-attributes:t
459 sgml-parent-document:nil
460 sgml-default-dtd-file:"../reference.ced"
461 sgml-exposed-tags:nil
462 sgml-local-catalogs:("/usr/lib/sgml/catalog")
463 sgml-local-ecat-files:nil