2 $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.9 2001/09/21 21:10:56 tgl Exp $
6 <refentry id="app-pg-ctl">
8 <date>2001-02-08</date>
12 <refentrytitle id="app-pg-ctl-title"><application>pg_ctl</application></refentrytitle>
13 <manvolnum>1</manvolnum>
14 <refmiscinfo>Application</refmiscinfo>
18 <refname>pg_ctl</refname>
19 <refpurpose>start, stop, or restart a <productname>PostgreSQL</productname> server</refpurpose>
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 <xref linkend="app-postmaster">, the
77 <productname>PostgreSQL</productname> backend server, or displaying
78 the status of a running postmaster. Although the postmaster can be
79 started manually, <application>pg_ctl</application> encapulates
80 tasks such as redirecting log output, properly detaching from the
81 terminal and process group, and it provides convenient options for
86 In <option>start</option> mode, a new postmaster is launched. The
87 server is started in the background, the standard input 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 are redirected to
91 <application>pg_ctl</application>'s standard output (not standard
92 error). If no log file is chosen, the standard output of
93 <application>pg_ctl</application> should be redirected to a file or
94 piped to another process, for example a log rotating program,
95 otherwise the postmaster will write its output the the controlling
96 terminal (from the background) and will not leave the shell's
101 In <option>stop</option> mode, the postmaster that is running in
102 the specified data directory is shut down. Three different
103 shutdown methods can be selected with the <option>-m</option>
104 option: <quote>Smart</quote> mode waits for all the clients to
105 disconnect. This is the default. <quote>Fast</quote> mode does
106 not wait for clients to disconnect. All active transactions will
107 be rolled back. <quote>Immediate</quote> mode will abort without
108 complete shutdown. This will lead to a recovery run on restart.
112 <option>restart</option> mode effectively executes a stop followed
113 by a start. This allows the changing of postmaster command line
118 <option>reload</option> mode simply sends the postmaster a SIGHUP signal,
119 causing it to reread its configuration files
120 (<filename>postgresql.conf</filename>, <filename>pg_hba.conf</filename>,
121 etc). This allows changing of configuration-file options that do not
122 require a complete restart to take effect.
126 <option>status</option> mode checks whether a postmaster is running
127 and if so displays the <acronym>PID</acronym> and the command line
128 options that were used to invoke it.
131 <refsect2 id="app-pg-ctl-options">
132 <title>Options</title>
137 <term>-D <replaceable class="parameter">datadir</replaceable></term>
140 Specifies the file system location of the database files. If
141 this is omitted, the environment variable
142 <envar>PGDATA</envar> is used.
148 <term>-l <replaceable class="parameter">filename</replaceable></term>
151 Append the server log output to
152 <replaceable>filename</replaceable>. If the file does not
153 exist, it is created. The umask is set to 077, so access to
154 the log file from other users is disallowed by default.
160 <term>-m <replaceable class="parameter">mode</replaceable></term>
163 Specifies the shutdown mode. <replaceable>mode</replaceable>
164 may be <literal>smart</literal>, <literal>fast</literal>, or
165 <literal>immediate</literal>, or the first letter of one of
172 <term>-o <replaceable class="parameter">options</replaceable></term>
175 Specifies options to be passed directly to
176 <application>postmaster</application>.
179 The parameters are usually surrounded by single or double
180 quotes to ensure that they are passed through as a group.
186 <term>-p <replaceable class="parameter">path</replaceable></term>
189 Specifies the location of the <filename>postmaster</filename>
190 executable. By default the postmaster is taken from the same
191 directory as pg_ctl, or failing that, the hard-wired
192 installation directory. It is not necessary to use this
193 option unless you are doing something unusual and get errors
194 that the postmaster was not found.
203 Wait for the start or shutdown to complete. Times out after
204 60 seconds. This is the default for shutdowns.
213 Do not wait for start or shutdown to complete. This is the
214 default for starts and restarts.
223 Only print errors, no informational messages.
235 If the file <filename>postmaster.opts.default</filename> exists in
236 the data directory, the contents of the file will be passed as
237 options to the <application>postmaster</application>, unless
238 overridden by the <option>-o</option> option.
245 <refsect1 id="R1-APP-PGCTL-2">
246 <title>Examples</title>
248 <refsect2 id="R2-APP-PGCTL-3">
249 <title>Starting the postmaster</title>
252 To start up <application>postmaster</application>:
254 <prompt>$</prompt> <userinput>pg_ctl start</userinput>
259 An example of starting the <application>postmaster</application>,
260 blocking until postmaster comes up is:
262 <prompt>$</prompt> <userinput>pg_ctl -w start</userinput>
267 For a <application>postmaster</application> using port 5433, and
268 running without <function>fsync</function>, use:
270 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" start</userinput>
275 <refsect2 id="R2-APP-PGCTL-4">
276 <title>Stopping the postmaster</title>
279 <prompt>$</prompt> <userinput>pg_ctl stop</userinput>
281 stops postmaster. Using the <option>-m</option> switch allows one
282 to control <emphasis>how</emphasis> the backend shuts down.
286 <refsect2 id="R2-APP-PGCTL-5">
287 <title>Restarting the postmaster</title>
290 This is almost equivalent to stopping the
291 <application>postmaster</application> then starting it again
292 except that pg_ctl saves and reuses the command line options that
293 were passed to the previously running instance. To restart
294 <application>postmaster</application> in the simplest form:
296 <prompt>$</prompt> <userinput>pg_ctl restart</userinput>
301 To restart <application>postmaster</application>,
302 waiting for it to shut down and to come up:
304 <prompt>$</prompt> <userinput>pg_ctl -w restart</userinput>
309 To restart using port 5433 and disabling fsync after restarting:
311 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" restart</userinput>
316 <refsect2 id="R2-APP-PGCTL-6">
317 <title>Showing postmaster status</title>
320 Here is a sample status output from
321 <application>pg_ctl</application>:
323 <prompt>$</prompt> <userinput>pg_ctl status</userinput>
325 pg_ctl: postmaster is running (pid: 13718)
327 /usr/local/pgsql/bin/postmaster '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'
330 This is the command line that would be invoked in restart mode.
339 Waiting for complete start is not a well-defined operation and may
340 fail if access control is set up in way that a local client cannot
341 connect without manual interaction. It should be avoided.
346 <title>See Also</title>
349 <xref linkend="app-postmaster">, <citetitle>PostgreSQL Administrator's Guide</citetitle>
355 <!-- Keep this comment at the end of the file
360 sgml-minimize-attributes:nil
361 sgml-always-quote-attributes:t
364 sgml-parent-document:nil
365 sgml-default-dtd-file:"../reference.ced"
366 sgml-exposed-tags:nil
367 sgml-local-catalogs:("/usr/lib/sgml/catalog")
368 sgml-local-ecat-files:nil