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