]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/pg_ctl-ref.sgml
Remove tabs from SGML reference files, so their addition can be detected
[postgresql] / doc / src / sgml / ref / pg_ctl-ref.sgml
1 <!--
2 $PostgreSQL: pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.40 2007/02/21 23:21:11 momjian 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    <arg>-c</arg>
33    <sbr>
34    <command>pg_ctl</command>
35    <arg choice="plain">stop</arg>
36    <arg>-W</arg>
37    <arg>-s</arg>
38    <arg>-D <replaceable>datadir</replaceable></arg>
39    <arg>-m
40      <group choice="plain">
41        <arg>s[mart]</arg>
42        <arg>f[ast]</arg>
43        <arg>i[mmediate]</arg>
44      </group>
45    </arg>
46    <sbr>
47    <command>pg_ctl</command>
48    <arg choice="plain">restart</arg>
49    <arg>-w</arg>
50    <arg>-s</arg>
51    <arg>-D <replaceable>datadir</replaceable></arg>
52    <arg>-c</arg>
53    <arg>-m
54      <group choice="plain">
55        <arg>s[mart]</arg>
56        <arg>f[ast]</arg>
57        <arg>i[mmediate]</arg>
58      </group>
59    </arg>
60    <arg>-o <replaceable>options</replaceable></arg>
61    <sbr>
62    <command>pg_ctl</command>
63    <arg choice="plain">reload</arg>
64    <arg>-s</arg>
65    <arg>-D <replaceable>datadir</replaceable></arg>
66    <sbr>
67    <command>pg_ctl</command>
68    <arg choice="plain">status</arg>
69    <arg>-D <replaceable>datadir</replaceable></arg>
70    <sbr>
71    <command>pg_ctl</command>
72    <arg choice="plain">kill</arg>
73    <arg><replaceable>signal_name</replaceable></arg>
74    <arg><replaceable>process_id</replaceable></arg>
75    <sbr>
76    <command>pg_ctl</command>
77    <arg choice="plain">register</arg>
78    <arg>-N <replaceable>servicename</replaceable></arg>
79    <arg>-U <replaceable>username</replaceable></arg>
80    <arg>-P <replaceable>password</replaceable></arg>
81    <arg>-D <replaceable>datadir</replaceable></arg>
82    <arg>-w</arg>
83    <arg>-o <replaceable>options</replaceable></arg>
84    <sbr>
85    <command>pg_ctl</command>
86    <arg choice="plain">unregister</arg>
87    <arg>-N <replaceable>servicename</replaceable></arg>
88   </cmdsynopsis>
89  </refsynopsisdiv>
90
91
92  <refsect1 id="app-pg-ctl-description">
93   <title>Description</title>
94   <para>
95    <application>pg_ctl</application> is a utility for starting,
96    stopping, or restarting the <productname>PostgreSQL</productname>
97    backend server (<xref linkend="app-postgres">), or displaying the
98    status of a running server.  Although the server can be started
99    manually, <application>pg_ctl</application> encapsulates tasks such
100    as redirecting log output and properly detaching from the terminal
101    and process group. It also provides convenient options for
102    controlled shutdown.
103   </para>
104
105   <para>
106    In <option>start</option> mode, a new server is launched.  The
107    server is started in the background, and standard input is attached to
108    <filename>/dev/null</filename>.  The standard output and standard
109    error are either appended to a log file (if the <option>-l</option>
110    option is used), or redirected to <application>pg_ctl</application>'s 
111    standard output (not standard error).  If no log file is chosen, the 
112    standard output of <application>pg_ctl</application> should be redirected 
113    to a file or piped to another process such as a log rotating program
114    like <application>rotatelogs</>; otherwise <command>postgres</command> 
115    will write its output to the controlling terminal (from the background) 
116    and will not leave the shell's process group.
117   </para>
118
119   <para>
120    In <option>stop</option> mode, the server that is running in
121    the specified data directory is shut down.  Three different
122    shutdown methods can be selected with the <option>-m</option>
123    option: <quote>Smart</quote> mode waits for all the clients to
124    disconnect.  This is the default.  <quote>Fast</quote> mode does
125    not wait for clients to disconnect.  All active transactions are
126    rolled back and clients are forcibly disconnected, then the
127    server is shut down.  <quote>Immediate</quote> mode will abort
128    all server processes without a clean shutdown.  This will lead to 
129    a recovery run on restart.
130   </para>
131
132   <para>
133    <option>restart</option> mode effectively executes a stop followed
134    by a start.  This allows changing the <command>postgres</command>
135    command-line options.
136   </para>
137
138   <para>
139    <option>reload</option> mode simply sends the
140    <command>postgres</command> process a <systemitem>SIGHUP</>
141    signal, causing it to reread its configuration files
142    (<filename>postgresql.conf</filename>,
143    <filename>pg_hba.conf</filename>, etc.).  This allows changing of
144    configuration-file options that do not require a complete restart
145    to take effect.
146   </para>
147
148   <para>
149    <option>status</option> mode checks whether a server is running in
150    the specified data directory. If it is, the <acronym>PID</acronym>
151    and the command line options that were used to invoke it are
152    displayed.
153   </para>
154
155   <para>
156    <option>kill</option> mode allows you to send a signal to a specified
157     process.  This is particularly valuable for <productname>Microsoft Windows</>
158     which does not have a <application>kill</> command.  Use 
159     <literal>--help</> to see a list of supported signal names.
160   </para>
161
162   <para>
163    <option>register</option> mode allows you to register a system service
164    on <productname>Microsoft Windows</>.
165   </para>
166
167   <para>
168    <option>unregister</option> mode allows you to unregister a system service
169    on <productname>Microsoft Windows</>, previously registered with the
170    <option>register</option> command.
171   </para>
172  </refsect1>
173
174  <refsect1 id="app-pg-ctl-options">
175   <title>Options</title>
176
177     <variablelist>
178      <varlistentry>
179       <term><option>-D <replaceable class="parameter">datadir</replaceable></option></term>
180       <listitem>
181        <para>
182         Specifies the file system location of the database files.  If
183         this is omitted, the environment variable
184         <envar>PGDATA</envar> is used.
185        </para>
186       </listitem>
187      </varlistentry>
188
189      <varlistentry>
190       <term><option>-l <replaceable class="parameter">filename</replaceable></option></term>
191       <listitem>
192        <para>
193         Append the server log output to
194         <replaceable>filename</replaceable>.  If the file does not
195         exist, it is created.  The <systemitem>umask</> is set to 077, so access to
196         the log file from other users is disallowed by default.
197        </para>
198       </listitem>
199      </varlistentry>
200
201      <varlistentry>
202       <term><option>-m <replaceable class="parameter">mode</replaceable></option></term>
203       <listitem>
204        <para>
205         Specifies the shutdown mode.  <replaceable>mode</replaceable>
206         can be <literal>smart</literal>, <literal>fast</literal>, or
207         <literal>immediate</literal>, or the first letter of one of
208         these three.
209        </para>
210       </listitem>
211      </varlistentry>
212
213      <varlistentry>
214       <term><option>-o <replaceable class="parameter">options</replaceable></option></term>
215       <listitem>
216        <para>
217         Specifies options to be passed directly to the
218         <command>postgres</command> command.
219        </para>
220        <para>
221         The options are usually surrounded by single or double
222         quotes to ensure that they are passed through as a group.
223        </para>
224       </listitem>
225      </varlistentry>
226
227      <varlistentry>
228       <term><option>-p <replaceable class="parameter">path</replaceable></option></term>
229       <listitem>
230        <para>
231         Specifies the location of the <filename>postgres</filename>
232         executable.  By default the <filename>postgres</filename> executable is taken from the same
233         directory as <command>pg_ctl</command>, or failing that, the hard-wired
234         installation directory.  It is not necessary to use this
235         option unless you are doing something unusual and get errors
236         that the <filename>postgres</filename> executable was not found.
237        </para>
238       </listitem>
239      </varlistentry>
240
241      <varlistentry>
242       <term><option>-s</option></term>
243       <listitem>
244        <para>
245         Only print errors, no informational messages.
246        </para>
247       </listitem>
248      </varlistentry>
249
250      <varlistentry>
251       <term><option>-c</option></term>
252       <listitem>
253        <para>
254         Attempt to allow server crashes to produce core files, on platforms
255         where this available, by lifting any soft resource limit placed on 
256         them. 
257         This is useful in debugging or diagnosing problems by allowing a 
258         stack trace to be obtained from a failed server process.
259        </para>
260       </listitem>
261      </varlistentry>
262
263      <varlistentry>
264       <term><option>-w</option></term>
265       <listitem>
266        <para>
267         Wait for the start or shutdown to complete.  Times out after
268         60 seconds.  This is the default for shutdowns. A successful 
269         shutdown is indicated by removal of the <acronym>PID</acronym> 
270         file. For starting up, a successful <command>psql -l</command> 
271         indicates success. <command>pg_ctl</command> will attempt to 
272         use the proper port for <application>psql</>. If the environment variable 
273         <envar>PGPORT</envar> exists, that is used. Otherwise, it will see if a port 
274         has been set in the <filename>postgresql.conf</filename> file. 
275         If neither of those is used, it will use the default port that 
276         <productname>PostgreSQL</productname> was compiled with 
277         (5432 by default). When waiting, <command>pg_ctl</command> will
278         return an accurate exit code based on the success of the startup 
279         or shutdown.
280        </para>
281       </listitem>
282      </varlistentry>
283
284      <varlistentry>
285       <term><option>-W</option></term>
286       <listitem>
287        <para>
288         Do not wait for start or shutdown to complete.  This is the
289         default for starts and restarts.
290        </para>
291       </listitem>
292      </varlistentry>
293    </variablelist>
294
295   <refsect2 id="app-pg-ctl-windows-options">
296    <title>Options for Windows</title>
297
298    <variablelist>
299     <varlistentry>
300      <term><option>-N <replaceable class="parameter">servicename</replaceable></option></term>
301      <listitem>
302       <para>
303        Name of the system service to register. The name will be used
304        as both the service name and the display name.
305       </para>
306      </listitem>
307     </varlistentry>
308
309     <varlistentry>
310      <term><option>-P <replaceable class="parameter">password</replaceable></option></term>
311      <listitem>
312       <para>
313        Password for the user to start the service.
314       </para>
315      </listitem>
316     </varlistentry>
317
318     <varlistentry>
319      <term><option>-U <replaceable class="parameter">username</replaceable></option></term>
320      <listitem>
321       <para>
322        User name for the user to start the service. For domain users, use the
323        format <literal>DOMAIN\username</literal>.
324       </para>
325      </listitem>
326     </varlistentry>
327    </variablelist>
328   </refsect2>
329
330  </refsect1>
331
332
333  <refsect1>
334   <title>Environment</title>
335
336   <variablelist>
337    <varlistentry>
338     <term><envar>PGDATA</envar></term>
339
340     <listitem>
341      <para>
342       Default data directory location.
343      </para>
344     </listitem>
345    </varlistentry>
346
347    <varlistentry>
348     <term><envar>PGPORT</envar></term>
349
350     <listitem>
351      <para>
352       Default port for <xref linkend="app-psql"> (used by the -w option).
353      </para>
354     </listitem>
355    </varlistentry>
356   </variablelist>
357
358   <para>
359    For additional server variables, see <xref linkend="app-postgres">.
360    This utility, like most other <productname>PostgreSQL</> utilities,
361    also uses the environment variables supported by <xref 
362    linkend="libpq-envars" endterm="libpq">.
363   </para>
364  </refsect1>
365
366
367  <refsect1>
368   <title>Files</title>
369
370   <variablelist>
371    <varlistentry>
372     <term><filename>postmaster.pid</filename></term>
373
374     <listitem>
375      <para>
376       The existence of this file in the data directory is used to help
377       <application>pg_ctl</application> determine if the server is
378       currently running or not.
379      </para>
380     </listitem>
381    </varlistentry>
382
383    <varlistentry>
384     <term><filename>postmaster.opts.default</filename></term>
385
386     <listitem>
387      <para>
388       If this file exists in the data directory,
389       <application>pg_ctl</application> (in <option>start</option>
390       mode) will pass the contents of the file as options to the
391       <command>postgres</command> command, unless overridden by the
392       <option>-o</option> option.
393      </para>
394     </listitem>
395    </varlistentry>
396
397    <varlistentry>
398     <term><filename>postmaster.opts</filename></term>
399
400     <listitem>
401      <para>If this file exists in the data directory,
402       <application>pg_ctl</application> (in <option>restart</option> mode) 
403       will pass the contents of the file as options to
404       <application>postgres</application>, unless overridden 
405       by the <option>-o</option> option. The contents of this file 
406       are also displayed in <option>status</option> mode.
407      </para>
408     </listitem>
409    </varlistentry>
410
411    <varlistentry>
412     <term><filename>postgresql.conf</filename></term>
413
414     <listitem>
415      <para>
416       This file, located in the data directory, is parsed to find the
417       proper port to use with <application>psql</application> when the
418       <option>-w</option> is given in <option>start</option> mode.
419      </para>
420     </listitem>
421    </varlistentry>
422
423   </variablelist>
424  </refsect1>
425
426
427  <refsect1>
428   <title>Notes</title>
429
430   <para>
431    Waiting for complete start is not a well-defined operation and might
432    fail if access control is set up so that a local client cannot
433    connect without manual interaction (e.g., password authentication).  For
434    additional connection variables, see <xref linkend="libpq-envars">,
435    and for passwords, also see <xref linkend="libpq-pgpass">.
436   </para>
437  </refsect1>
438
439
440  <refsect1 id="R1-APP-PGCTL-2">
441   <title>Examples</title>
442
443   <refsect2 id="R2-APP-PGCTL-3">
444    <title>Starting the Server</title>
445
446    <para>
447     To start up a server:
448 <screen>
449 <prompt>$</prompt> <userinput>pg_ctl start</userinput>
450 </screen>
451    </para>
452
453    <para>
454     An example of starting the server, blocking until the server has
455     come up is:
456 <screen>
457 <prompt>$</prompt> <userinput>pg_ctl -w start</userinput>
458 </screen>
459    </para>
460
461    <para>
462     For a server using port 5433, and
463     running without <function>fsync</function>, use:
464 <screen>
465 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" start</userinput>
466 </screen>
467    </para>
468   </refsect2>
469
470   <refsect2 id="R2-APP-PGCTL-4">
471    <title>Stopping the Server</title>
472    <para>
473 <screen>
474 <prompt>$</prompt> <userinput>pg_ctl stop</userinput>
475 </screen>
476     stops the server. Using the <option>-m</option> switch allows one
477     to control <emphasis>how</emphasis> the backend shuts down.
478    </para>
479   </refsect2>
480
481   <refsect2 id="R2-APP-PGCTL-5">
482    <title>Restarting the Server</title>
483
484    <para>
485     Restarting the server is almost equivalent to stopping the
486     server and starting it again
487     except that <command>pg_ctl</command> saves and reuses the command line options that
488     were passed to the previously running instance.  To restart
489     the server in the simplest form, use:
490 <screen>
491 <prompt>$</prompt> <userinput>pg_ctl restart</userinput>
492 </screen>
493    </para>
494
495    <para>
496     To restart server,
497     waiting for it to shut down and to come up:
498 <screen>
499 <prompt>$</prompt> <userinput>pg_ctl -w restart</userinput>
500 </screen>
501    </para>
502
503    <para>
504     To restart using port 5433 and disabling <function>fsync</> after restarting:
505 <screen>
506 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" restart</userinput>
507 </screen>
508    </para>
509   </refsect2>
510
511   <refsect2 id="R2-APP-PGCTL-6">
512    <title>Showing the Server Status</title>
513
514    <para>
515     Here is a sample status output from
516     <application>pg_ctl</application>:
517 <screen>
518 <prompt>$</prompt> <userinput>pg_ctl status</userinput>
519 <computeroutput>
520 pg_ctl: server is running (pid: 13718)
521 Command line was:
522 /usr/local/pgsql/bin/postgres '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'
523 </computeroutput>
524 </screen>
525     This is the command line that would be invoked in restart mode.
526    </para>
527   </refsect2>
528  </refsect1>
529
530
531  <refsect1>
532   <title>See Also</title>
533
534   <para>
535    <xref linkend="app-postgres">
536   </para>
537  </refsect1>
538
539 </refentry>