]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/pg_ctl-ref.sgml
Fix markup problem with recent pg_ctl change.
[postgresql] / doc / src / sgml / ref / pg_ctl-ref.sgml
1 <!--
2 $PostgreSQL: pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.43 2007/11/10 14:07:18 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
179      <varlistentry>
180       <term><option>-c</option></term>
181       <listitem>
182        <para>
183         Attempt to allow server crashes to produce core files, on platforms
184         where this available, by lifting any soft resource limit placed on 
185         them. 
186         This is useful in debugging or diagnosing problems by allowing a 
187         stack trace to be obtained from a failed server process.
188        </para>
189       </listitem>
190      </varlistentry>
191
192      <varlistentry>
193       <term><option>-D <replaceable class="parameter">datadir</replaceable></option></term>
194       <listitem>
195        <para>
196         Specifies the file system location of the database files.  If
197         this is omitted, the environment variable
198         <envar>PGDATA</envar> is used.
199        </para>
200       </listitem>
201      </varlistentry>
202
203      <varlistentry>
204       <term><option>-l <replaceable class="parameter">filename</replaceable></option></term>
205       <listitem>
206        <para>
207         Append the server log output to
208         <replaceable>filename</replaceable>.  If the file does not
209         exist, it is created.  The <systemitem>umask</> is set to 077, so access to
210         the log file from other users is disallowed by default.
211        </para>
212       </listitem>
213      </varlistentry>
214
215      <varlistentry>
216       <term><option>-m <replaceable class="parameter">mode</replaceable></option></term>
217       <listitem>
218        <para>
219         Specifies the shutdown mode.  <replaceable>mode</replaceable>
220         can be <literal>smart</literal>, <literal>fast</literal>, or
221         <literal>immediate</literal>, or the first letter of one of
222         these three.
223        </para>
224       </listitem>
225      </varlistentry>
226
227      <varlistentry>
228       <term><option>-o <replaceable class="parameter">options</replaceable></option></term>
229       <listitem>
230        <para>
231         Specifies options to be passed directly to the
232         <command>postgres</command> command.
233        </para>
234        <para>
235         The options are usually surrounded by single or double
236         quotes to ensure that they are passed through as a group.
237        </para>
238       </listitem>
239      </varlistentry>
240
241      <varlistentry>
242       <term><option>-p <replaceable class="parameter">path</replaceable></option></term>
243       <listitem>
244        <para>
245         Specifies the location of the <filename>postgres</filename>
246         executable.  By default the <filename>postgres</filename> executable is taken from the same
247         directory as <command>pg_ctl</command>, or failing that, the hard-wired
248         installation directory.  It is not necessary to use this
249         option unless you are doing something unusual and get errors
250         that the <filename>postgres</filename> executable was not found.
251        </para>
252       </listitem>
253      </varlistentry>
254
255      <varlistentry>
256       <term><option>-s</option></term>
257       <listitem>
258        <para>
259         Only print errors, no informational messages.
260        </para>
261       </listitem>
262      </varlistentry>
263
264      <varlistentry>
265       <term><option>-w</option></term>
266       <listitem>
267        <para>
268         Wait for the start or shutdown to complete.  Times out after
269         60 seconds.  This is the default for shutdowns. A successful 
270         shutdown is indicated by removal of the <acronym>PID</acronym> 
271         file. For starting up, a successful <command>psql -l</command> 
272         indicates success. <command>pg_ctl</command> will attempt to 
273         use the proper port for <application>psql</>. If the environment variable 
274         <envar>PGPORT</envar> exists, that is used. Otherwise, it will see if a port 
275         has been set in the <filename>postgresql.conf</filename> file. 
276         If neither of those is used, it will use the default port that 
277         <productname>PostgreSQL</productname> was compiled with 
278         (5432 by default). When waiting, <command>pg_ctl</command> will
279         return an accurate exit code based on the success of the startup 
280         or shutdown.
281        </para>
282       </listitem>
283      </varlistentry>
284
285      <varlistentry>
286       <term><option>-W</option></term>
287       <listitem>
288        <para>
289         Do not wait for start or shutdown to complete.  This is the
290         default for starts and restarts.
291        </para>
292       </listitem>
293      </varlistentry>
294    </variablelist>
295
296   <refsect2 id="app-pg-ctl-windows-options">
297    <title>Options for Windows</title>
298
299    <variablelist>
300     <varlistentry>
301      <term><option>-N <replaceable class="parameter">servicename</replaceable></option></term>
302      <listitem>
303       <para>
304        Name of the system service to register. The name will be used
305        as both the service name and the display name.
306       </para>
307      </listitem>
308     </varlistentry>
309
310     <varlistentry>
311      <term><option>-P <replaceable class="parameter">password</replaceable></option></term>
312      <listitem>
313       <para>
314        Password for the user to start the service.
315       </para>
316      </listitem>
317     </varlistentry>
318
319     <varlistentry>
320      <term><option>-U <replaceable class="parameter">username</replaceable></option></term>
321      <listitem>
322       <para>
323        User name for the user to start the service. For domain users, use the
324        format <literal>DOMAIN\username</literal>.
325       </para>
326      </listitem>
327     </varlistentry>
328    </variablelist>
329   </refsect2>
330
331  </refsect1>
332
333
334  <refsect1>
335   <title>Environment</title>
336
337   <variablelist>
338    <varlistentry>
339     <term><envar>PGDATA</envar></term>
340
341     <listitem>
342      <para>
343       Default data directory location.
344      </para>
345     </listitem>
346    </varlistentry>
347
348    <varlistentry>
349     <term><envar>PGPORT</envar></term>
350
351     <listitem>
352      <para>
353       Default port for <xref linkend="app-psql"> (used by the -w option).
354      </para>
355     </listitem>
356    </varlistentry>
357   </variablelist>
358
359   <para>
360    For additional server variables, see <xref linkend="app-postgres">.
361    This utility, like most other <productname>PostgreSQL</> utilities,
362    also uses the environment variables supported by <application>libpq</>
363    (see <xref linkend="libpq-envars">).
364   </para>
365  </refsect1>
366
367
368  <refsect1>
369   <title>Files</title>
370
371   <variablelist>
372    <varlistentry>
373     <term><filename>postmaster.pid</filename></term>
374
375     <listitem>
376      <para>
377       The existence of this file in the data directory is used to help
378       <application>pg_ctl</application> determine if the server is
379       currently running or not.
380      </para>
381     </listitem>
382    </varlistentry>
383
384    <varlistentry>
385     <term><filename>postmaster.opts.default</filename></term>
386
387     <listitem>
388      <para>
389       If this file exists in the data directory,
390       <application>pg_ctl</application> (in <option>start</option>
391       mode) will pass the contents of the file as options to the
392       <command>postgres</command> command, unless overridden by the
393       <option>-o</option> option.
394      </para>
395     </listitem>
396    </varlistentry>
397
398    <varlistentry>
399     <term><filename>postmaster.opts</filename></term>
400
401     <listitem>
402      <para>If this file exists in the data directory,
403       <application>pg_ctl</application> (in <option>restart</option> mode) 
404       will pass the contents of the file as options to
405       <application>postgres</application>, unless overridden 
406       by the <option>-o</option> option. The contents of this file 
407       are also displayed in <option>status</option> mode.
408      </para>
409     </listitem>
410    </varlistentry>
411
412    <varlistentry>
413     <term><filename>postgresql.conf</filename></term>
414
415     <listitem>
416      <para>
417       This file, located in the data directory, is parsed to find the
418       proper port to use with <application>psql</application> when the
419       <option>-w</option> is given in <option>start</option> mode.
420      </para>
421     </listitem>
422    </varlistentry>
423
424   </variablelist>
425  </refsect1>
426
427
428  <refsect1>
429   <title>Notes</title>
430
431   <para>
432    Waiting for complete start is not a well-defined operation and might
433    fail if access control is set up so that a local client cannot
434    connect without manual interaction (e.g., password authentication).  For
435    additional connection variables, see <xref linkend="libpq-envars">,
436    and for passwords, also see <xref linkend="libpq-pgpass">.
437   </para>
438  </refsect1>
439
440
441  <refsect1 id="R1-APP-PGCTL-2">
442   <title>Examples</title>
443
444   <refsect2 id="R2-APP-PGCTL-3">
445    <title>Starting the Server</title>
446
447    <para>
448     To start up a server:
449 <screen>
450 <prompt>$</prompt> <userinput>pg_ctl start</userinput>
451 </screen>
452    </para>
453
454    <para>
455     An example of starting the server, blocking until the server has
456     come up is:
457 <screen>
458 <prompt>$</prompt> <userinput>pg_ctl -w start</userinput>
459 </screen>
460    </para>
461
462    <para>
463     For a server using port 5433, and
464     running without <function>fsync</function>, use:
465 <screen>
466 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" start</userinput>
467 </screen>
468    </para>
469   </refsect2>
470
471   <refsect2 id="R2-APP-PGCTL-4">
472    <title>Stopping the Server</title>
473    <para>
474 <screen>
475 <prompt>$</prompt> <userinput>pg_ctl stop</userinput>
476 </screen>
477     stops the server. Using the <option>-m</option> switch allows one
478     to control <emphasis>how</emphasis> the backend shuts down.
479    </para>
480   </refsect2>
481
482   <refsect2 id="R2-APP-PGCTL-5">
483    <title>Restarting the Server</title>
484
485    <para>
486     Restarting the server is almost equivalent to stopping the
487     server and starting it again
488     except that <command>pg_ctl</command> saves and reuses the command line options that
489     were passed to the previously running instance.  To restart
490     the server in the simplest form, use:
491 <screen>
492 <prompt>$</prompt> <userinput>pg_ctl restart</userinput>
493 </screen>
494    </para>
495
496    <para>
497     To restart server,
498     waiting for it to shut down and to come up:
499 <screen>
500 <prompt>$</prompt> <userinput>pg_ctl -w restart</userinput>
501 </screen>
502    </para>
503
504    <para>
505     To restart using port 5433 and disabling <function>fsync</> after restarting:
506 <screen>
507 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" restart</userinput>
508 </screen>
509    </para>
510   </refsect2>
511
512   <refsect2 id="R2-APP-PGCTL-6">
513    <title>Showing the Server Status</title>
514
515    <para>
516     Here is a sample status output from
517     <application>pg_ctl</application>:
518 <screen>
519 <prompt>$</prompt> <userinput>pg_ctl status</userinput>
520 <computeroutput>
521 pg_ctl: server is running (pid: 13718)
522 Command line was:
523 /usr/local/pgsql/bin/postgres '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'
524 </computeroutput>
525 </screen>
526     This is the command line that would be invoked in restart mode.
527    </para>
528   </refsect2>
529  </refsect1>
530
531
532  <refsect1>
533   <title>See Also</title>
534
535   <para>
536    <xref linkend="app-postgres">
537   </para>
538  </refsect1>
539
540 </refentry>