]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/pg_ctl-ref.sgml
e131c3c929126fa1eaf0dcd2c1e26c21855bbb24
[postgresql] / doc / src / sgml / ref / pg_ctl-ref.sgml
1 <!--
2 $PostgreSQL: pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.25 2003/11/29 19:51:39 pgsql Exp $
3 PostgreSQL documentation
4 -->
5
6 <refentry id="app-pg-ctl">
7  <refmeta>
8   <refentrytitle id="app-pg-ctl-title"><application>pg_ctl</application></refentrytitle>
9   <manvolnum>1</manvolnum>
10   <refmiscinfo>Application</refmiscinfo>
11  </refmeta>
12
13  <refnamediv>
14   <refname>pg_ctl</refname>
15   <refpurpose>start, stop, or restart a <productname>PostgreSQL</productname> server</refpurpose>
16  </refnamediv>
17
18  <indexterm zone="app-pg-ctl">
19   <primary>pg_ctl</primary>
20  </indexterm>
21
22  <refsynopsisdiv>
23   <cmdsynopsis>
24    <command>pg_ctl</command>
25    <arg choice="plain">start</arg>
26    <arg>-w</arg>
27    <arg>-s</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>
32    <sbr>
33    <command>pg_ctl</command>
34    <arg choice="plain">stop</arg>
35    <arg>-W</arg>
36    <arg>-s</arg>
37    <arg>-D <replaceable>datadir</replaceable></arg>
38    <arg>-m
39      <group choice="plain">
40        <arg>s[mart]</arg>
41        <arg>f[ast]</arg>
42        <arg>i[mmediate]</arg>
43      </group>
44    </arg>
45    <sbr>
46    <command>pg_ctl</command>
47    <arg choice="plain">restart</arg>
48    <arg>-w</arg>
49    <arg>-s</arg>
50    <arg>-D <replaceable>datadir</replaceable></arg>
51    <arg>-m
52      <group choice="plain">
53        <arg>s[mart]</arg>
54        <arg>f[ast]</arg>
55        <arg>i[mmediate]</arg>
56      </group>
57    </arg>
58    <arg>-o <replaceable>options</replaceable></arg>
59    <sbr>
60    <command>pg_ctl</command>
61    <arg choice="plain">reload</arg>
62    <arg>-s</arg>
63    <arg>-D <replaceable>datadir</replaceable></arg>
64    <sbr>
65    <command>pg_ctl</command>
66    <arg choice="plain">status</arg>
67    <arg>-D <replaceable>datadir</replaceable></arg>
68   </cmdsynopsis>
69  </refsynopsisdiv>
70
71
72  <refsect1 id="app-pg-ctl-description">
73   <title>Description</title>
74   <para>
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
82    controlled shutdown.
83   </para>
84
85   <para>
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
96    process group.
97   </para>
98
99   <para>
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.
110   </para>
111
112   <para>
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.
116   </para>
117
118   <para>
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
125    to take effect.
126   </para>
127
128   <para>
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
132    displayed.
133   </para>
134  </refsect1>
135
136  <refsect1 id="app-pg-ctl-options">
137   <title>Options</title>
138
139   <para>
140
141     <variablelist>
142      <varlistentry>
143       <term><option>-D <replaceable class="parameter">datadir</replaceable></option></term>
144       <listitem>
145        <para>
146         Specifies the file system location of the database files.  If
147         this is omitted, the environment variable
148         <envar>PGDATA</envar> is used.
149        </para>
150       </listitem>
151      </varlistentry>
152
153      <varlistentry>
154       <term><option>-l <replaceable class="parameter">filename</replaceable></option></term>
155       <listitem>
156        <para>
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.
161        </para>
162       </listitem>
163      </varlistentry>
164
165      <varlistentry>
166       <term><option>-m <replaceable class="parameter">mode</replaceable></option></term>
167       <listitem>
168        <para>
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
172         these three.
173        </para>
174       </listitem>
175      </varlistentry>
176
177      <varlistentry>
178       <term><option>-o <replaceable class="parameter">options</replaceable></option></term>
179       <listitem>
180        <para>
181         Specifies options to be passed directly to the
182         <command>postmaster</command> command.
183        </para>
184        <para>
185         The options are usually surrounded by single or double
186         quotes to ensure that they are passed through as a group.
187        </para>
188       </listitem>
189      </varlistentry>
190
191      <varlistentry>
192       <term><option>-p <replaceable class="parameter">path</replaceable></option></term>
193       <listitem>
194        <para>
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.
201        </para>
202       </listitem>
203      </varlistentry>
204
205      <varlistentry>
206       <term><option>-s</option></term>
207       <listitem>
208        <para>
209         Only print errors, no informational messages.
210        </para>
211       </listitem>
212      </varlistentry>
213
214      <varlistentry>
215       <term><option>-w</option></term>
216       <listitem>
217        <para>
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 
228         (5432 by default).
229        </para>
230       </listitem>
231      </varlistentry>
232
233      <varlistentry>
234       <term><option>-W</option></term>
235       <listitem>
236        <para>
237         Do not wait for start or shutdown to complete.  This is the
238         default for starts and restarts.
239        </para>
240       </listitem>
241      </varlistentry>
242     </variablelist>
243    </para>
244  </refsect1>
245
246
247  <refsect1>
248   <title>Environment</title>
249
250   <variablelist>
251    <varlistentry>
252     <term><envar>PGDATA</envar></term>
253
254     <listitem>
255      <para>
256       Default data directory location.
257      </para>
258     </listitem>
259    </varlistentry>
260
261    <varlistentry>
262     <term><envar>PGPORT</envar></term>
263
264     <listitem>
265      <para>
266       Default port for <xref linkend="app-psql"> (used by the -w option).
267      </para>
268     </listitem>
269    </varlistentry>
270   </variablelist>
271
272   <para>
273    For others, see <xref linkend="app-postmaster">.
274   </para>
275  </refsect1>
276
277
278  <refsect1>
279   <title>Files</title>
280
281   <variablelist>
282    <varlistentry>
283     <term><filename>postmaster.pid</filename></term>
284
285     <listitem>
286      <para>
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.
290      </para>
291     </listitem>
292    </varlistentry>
293
294    <varlistentry>
295     <term><filename>postmaster.opts.default</filename></term>
296
297     <listitem>
298      <para>
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.
304      </para>
305     </listitem>
306    </varlistentry>
307
308    <varlistentry>
309     <term><filename>postmaster.opts</filename></term>
310
311     <listitem>
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.
318      </para>
319     </listitem>
320    </varlistentry>
321
322    <varlistentry>
323     <term><filename>postgresql.conf</filename></term>
324
325     <listitem>
326      <para>
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.
330      </para>
331     </listitem>
332    </varlistentry>
333
334   </variablelist>
335  </refsect1>
336
337
338  <refsect1>
339   <title>Notes</title>
340
341   <para>
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).
345   </para>
346  </refsect1>
347
348
349  <refsect1 id="R1-APP-PGCTL-2">
350   <title>Examples</title>
351
352   <refsect2 id="R2-APP-PGCTL-3">
353    <title>Starting the Server</title>
354
355    <para>
356     To start up a server:
357 <screen>
358 <prompt>$</prompt> <userinput>pg_ctl start</userinput>
359 </screen>
360    </para>
361
362    <para>
363     An example of starting the server, blocking until the server has
364     come up is:
365 <screen>
366 <prompt>$</prompt> <userinput>pg_ctl -w start</userinput>
367 </screen>
368    </para>
369
370    <para>
371     For a server using port 5433, and
372     running without <function>fsync</function>, use:
373 <screen>
374 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" start</userinput>
375 </screen>
376    </para>
377   </refsect2>
378
379   <refsect2 id="R2-APP-PGCTL-4">
380    <title>Stopping the Server</title>
381    <para>
382 <screen>
383 <prompt>$</prompt> <userinput>pg_ctl stop</userinput>
384 </screen>
385     stops the server. Using the <option>-m</option> switch allows one
386     to control <emphasis>how</emphasis> the backend shuts down.
387    </para>
388   </refsect2>
389
390   <refsect2 id="R2-APP-PGCTL-5">
391    <title>Restarting the Server</title>
392
393    <para>
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:
399 <screen>
400 <prompt>$</prompt> <userinput>pg_ctl restart</userinput>
401 </screen>
402    </para>
403
404    <para>
405     To restart server,
406     waiting for it to shut down and to come up:
407 <screen>
408 <prompt>$</prompt> <userinput>pg_ctl -w restart</userinput>
409 </screen>
410    </para>
411
412    <para>
413     To restart using port 5433 and disabling <function>fsync</> after restarting:
414 <screen>
415 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" restart</userinput>
416 </screen>
417    </para>
418   </refsect2>
419
420   <refsect2 id="R2-APP-PGCTL-6">
421    <title>Showing the Server Status</title>
422
423    <para>
424     Here is a sample status output from
425     <application>pg_ctl</application>:
426 <screen>
427 <prompt>$</prompt> <userinput>pg_ctl status</userinput>
428 <computeroutput>
429 pg_ctl: postmaster is running (pid: 13718)
430 Command line was:
431 /usr/local/pgsql/bin/postmaster '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'
432 </computeroutput>
433 </screen>
434     This is the command line that would be invoked in restart mode.
435    </para>
436   </refsect2>
437  </refsect1>
438
439
440  <refsect1>
441   <title>See Also</title>
442
443   <para>
444    <xref linkend="app-postmaster">
445   </para>
446  </refsect1>
447
448 </refentry>
449
450 <!-- Keep this comment at the end of the file
451 Local variables:
452 mode:sgml
453 sgml-omittag:nil
454 sgml-shorttag:t
455 sgml-minimize-attributes:nil
456 sgml-always-quote-attributes:t
457 sgml-indent-step:1
458 sgml-indent-data: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
464 End:
465 -->