]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/pg_ctl-ref.sgml
Document new pg_ctl 'kill' command, specificially for Win32.
[postgresql] / doc / src / sgml / ref / pg_ctl-ref.sgml
1 <!--
2 $PostgreSQL: pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.27 2004/05/27 03:50:25 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    <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    <sbr>
69    <command>pg_ctl</command>
70    <arg choice="plain">kill</arg>
71    <arg><replaceable>signal_name</replaceable></arg>
72    <arg><replaceable>process_id</replaceable></arg>
73   </cmdsynopsis>
74  </refsynopsisdiv>
75
76
77  <refsect1 id="app-pg-ctl-description">
78   <title>Description</title>
79   <para>
80    <application>pg_ctl</application> is a utility for starting,
81    stopping, or restarting the <productname>PostgreSQL</productname>
82    backend server (<xref linkend="app-postmaster">), or displaying the
83    status of a running server.  Although the server can be started
84    manually, <application>pg_ctl</application> encapsulates tasks such
85    as redirecting log output and properly detaching from the terminal
86    and process group. It also provides convenient options for
87    controlled shutdown.
88   </para>
89
90   <para>
91    In <option>start</option> mode, a new server is launched.  The
92    server is started in the background, and standard input is attached to
93    <filename>/dev/null</filename>.  The standard output and standard
94    error are either appended to a log file (if the <option>-l</option>
95    option is used), or redirected to <application>pg_ctl</application>'s 
96    standard output (not standard error).  If no log file is chosen, the 
97    standard output of <application>pg_ctl</application> should be redirected 
98    to a file or piped to another process such as a log rotating program
99    like <application>rotatelogs</>; otherwise the <command>postmaster</command> 
100    will write its output to the controlling terminal (from the background) 
101    and will not leave the shell's process group.
102   </para>
103
104   <para>
105    In <option>stop</option> mode, the server that is running in
106    the specified data directory is shut down.  Three different
107    shutdown methods can be selected with the <option>-m</option>
108    option: <quote>Smart</quote> mode waits for all the clients to
109    disconnect.  This is the default.  <quote>Fast</quote> mode does
110    not wait for clients to disconnect.  All active transactions are
111    rolled back and clients are forcibly disconnected, then the
112    server is shut down.  <quote>Immediate</quote> mode will abort
113    all server processes without a clean shutdown.  This will lead to 
114    a recovery run on restart.
115   </para>
116
117   <para>
118    <option>restart</option> mode effectively executes a stop followed
119    by a start.  This allows changing the <command>postmaster</command>
120    command-line options.
121   </para>
122
123   <para>
124    <option>reload</option> mode simply sends the
125    <command>postmaster</command> process a <systemitem>SIGHUP</>
126    signal, causing it to reread its configuration files
127    (<filename>postgresql.conf</filename>,
128    <filename>pg_hba.conf</filename>, etc.).  This allows changing of
129    configuration-file options that do not require a complete restart
130    to take effect.
131   </para>
132
133   <para>
134    <option>status</option> mode checks whether a server is running in
135    the specified data directory. If it is, the <acronym>PID</acronym>
136    and the command line options that were used to invoke it are
137    displayed.
138   </para>
139
140   <para>
141    <option>kill</option> mode allows you to send a signal to a specified
142     process.  This is particularly valuable for <productname>MS Windows</>
143     which does not have a <application>kill</> command.
144   </para>
145  </refsect1>
146
147  <refsect1 id="app-pg-ctl-options">
148   <title>Options</title>
149
150   <para>
151
152     <variablelist>
153      <varlistentry>
154       <term><option>-D <replaceable class="parameter">datadir</replaceable></option></term>
155       <listitem>
156        <para>
157         Specifies the file system location of the database files.  If
158         this is omitted, the environment variable
159         <envar>PGDATA</envar> is used.
160        </para>
161       </listitem>
162      </varlistentry>
163
164      <varlistentry>
165       <term><option>-l <replaceable class="parameter">filename</replaceable></option></term>
166       <listitem>
167        <para>
168         Append the server log output to
169         <replaceable>filename</replaceable>.  If the file does not
170         exist, it is created.  The <systemitem>umask</> is set to 077, so access to
171         the log file from other users is disallowed by default.
172        </para>
173       </listitem>
174      </varlistentry>
175
176      <varlistentry>
177       <term><option>-m <replaceable class="parameter">mode</replaceable></option></term>
178       <listitem>
179        <para>
180         Specifies the shutdown mode.  <replaceable>mode</replaceable>
181         may be <literal>smart</literal>, <literal>fast</literal>, or
182         <literal>immediate</literal>, or the first letter of one of
183         these three.
184        </para>
185       </listitem>
186      </varlistentry>
187
188      <varlistentry>
189       <term><option>-o <replaceable class="parameter">options</replaceable></option></term>
190       <listitem>
191        <para>
192         Specifies options to be passed directly to the
193         <command>postmaster</command> command.
194        </para>
195        <para>
196         The options are usually surrounded by single or double
197         quotes to ensure that they are passed through as a group.
198        </para>
199       </listitem>
200      </varlistentry>
201
202      <varlistentry>
203       <term><option>-p <replaceable class="parameter">path</replaceable></option></term>
204       <listitem>
205        <para>
206         Specifies the location of the <filename>postmaster</filename>
207         executable.  By default the <filename>postmaster</filename> executable is taken from the same
208         directory as <command>pg_ctl</command>, or failing that, the hard-wired
209         installation directory.  It is not necessary to use this
210         option unless you are doing something unusual and get errors
211         that the <filename>postmaster</filename> executable was not found.
212        </para>
213       </listitem>
214      </varlistentry>
215
216      <varlistentry>
217       <term><option>-s</option></term>
218       <listitem>
219        <para>
220         Only print errors, no informational messages.
221        </para>
222       </listitem>
223      </varlistentry>
224
225      <varlistentry>
226       <term><option>-w</option></term>
227       <listitem>
228        <para>
229         Wait for the start or shutdown to complete.  Times out after
230         60 seconds.  This is the default for shutdowns. A successful 
231         shutdown is indicated by removal of the <acronym>PID</acronym> 
232         file. For starting up, a successful <command>psql -l</command> 
233         indicates success. <command>pg_ctl</command> will attempt to 
234         use the proper port for <application>psql</>. If the environment variable 
235         <envar>PGPORT</envar> exists, that is used. Otherwise, it will see if a port 
236         has been set in the <filename>postgresql.conf</filename> file. 
237         If neither of those is used, it will use the default port that 
238         <productname>PostgreSQL</productname> was compiled with 
239         (5432 by default).
240        </para>
241       </listitem>
242      </varlistentry>
243
244      <varlistentry>
245       <term><option>-W</option></term>
246       <listitem>
247        <para>
248         Do not wait for start or shutdown to complete.  This is the
249         default for starts and restarts.
250        </para>
251       </listitem>
252      </varlistentry>
253     </variablelist>
254    </para>
255  </refsect1>
256
257
258  <refsect1>
259   <title>Environment</title>
260
261   <variablelist>
262    <varlistentry>
263     <term><envar>PGDATA</envar></term>
264
265     <listitem>
266      <para>
267       Default data directory location.
268      </para>
269     </listitem>
270    </varlistentry>
271
272    <varlistentry>
273     <term><envar>PGPORT</envar></term>
274
275     <listitem>
276      <para>
277       Default port for <xref linkend="app-psql"> (used by the -w option).
278      </para>
279     </listitem>
280    </varlistentry>
281   </variablelist>
282
283   <para>
284    For others, see <xref linkend="app-postmaster">.
285   </para>
286  </refsect1>
287
288
289  <refsect1>
290   <title>Files</title>
291
292   <variablelist>
293    <varlistentry>
294     <term><filename>postmaster.pid</filename></term>
295
296     <listitem>
297      <para>
298       The existence of this file in the data directory is used to help
299       <application>pg_ctl</application> determine if the server is
300       currently running or not.
301      </para>
302     </listitem>
303    </varlistentry>
304
305    <varlistentry>
306     <term><filename>postmaster.opts.default</filename></term>
307
308     <listitem>
309      <para>
310       If this file exists in the data directory,
311       <application>pg_ctl</application> (in <option>start</option>
312       mode) will pass the contents of the file as options to the
313       <command>postmaster</command> command, unless overridden by the
314       <option>-o</option> option.
315      </para>
316     </listitem>
317    </varlistentry>
318
319    <varlistentry>
320     <term><filename>postmaster.opts</filename></term>
321
322     <listitem>
323      <para>If this file exists in the data directory,
324       <application>pg_ctl</application> (in <option>restart</option> mode) 
325       will pass the contents of the file as options to the 
326       <application>postmaster</application>, unless overridden 
327       by the <option>-o</option> option. The contents of this file 
328       are also displayed in <option>status</option> mode.
329      </para>
330     </listitem>
331    </varlistentry>
332
333    <varlistentry>
334     <term><filename>postgresql.conf</filename></term>
335
336     <listitem>
337      <para>
338       This file, located in the data directory, is parsed to find the
339       proper port to use with <application>psql</application> when the
340       <option>-w</option> is given in <option>start</option> mode.
341      </para>
342     </listitem>
343    </varlistentry>
344
345   </variablelist>
346  </refsect1>
347
348
349  <refsect1>
350   <title>Notes</title>
351
352   <para>
353    Waiting for complete start is not a well-defined operation and may
354    fail if access control is set up so that a local client cannot
355    connect without manual interaction (e.g., password authentication).
356   </para>
357  </refsect1>
358
359
360  <refsect1 id="R1-APP-PGCTL-2">
361   <title>Examples</title>
362
363   <refsect2 id="R2-APP-PGCTL-3">
364    <title>Starting the Server</title>
365
366    <para>
367     To start up a server:
368 <screen>
369 <prompt>$</prompt> <userinput>pg_ctl start</userinput>
370 </screen>
371    </para>
372
373    <para>
374     An example of starting the server, blocking until the server has
375     come up is:
376 <screen>
377 <prompt>$</prompt> <userinput>pg_ctl -w start</userinput>
378 </screen>
379    </para>
380
381    <para>
382     For a server using port 5433, and
383     running without <function>fsync</function>, use:
384 <screen>
385 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" start</userinput>
386 </screen>
387    </para>
388   </refsect2>
389
390   <refsect2 id="R2-APP-PGCTL-4">
391    <title>Stopping the Server</title>
392    <para>
393 <screen>
394 <prompt>$</prompt> <userinput>pg_ctl stop</userinput>
395 </screen>
396     stops the server. Using the <option>-m</option> switch allows one
397     to control <emphasis>how</emphasis> the backend shuts down.
398    </para>
399   </refsect2>
400
401   <refsect2 id="R2-APP-PGCTL-5">
402    <title>Restarting the Server</title>
403
404    <para>
405     Restarting the server is almost equivalent to stopping the
406     server and starting it again
407     except that <command>pg_ctl</command> saves and reuses the command line options that
408     were passed to the previously running instance.  To restart
409     the server in the simplest form, use:
410 <screen>
411 <prompt>$</prompt> <userinput>pg_ctl restart</userinput>
412 </screen>
413    </para>
414
415    <para>
416     To restart server,
417     waiting for it to shut down and to come up:
418 <screen>
419 <prompt>$</prompt> <userinput>pg_ctl -w restart</userinput>
420 </screen>
421    </para>
422
423    <para>
424     To restart using port 5433 and disabling <function>fsync</> after restarting:
425 <screen>
426 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" restart</userinput>
427 </screen>
428    </para>
429   </refsect2>
430
431   <refsect2 id="R2-APP-PGCTL-6">
432    <title>Showing the Server Status</title>
433
434    <para>
435     Here is a sample status output from
436     <application>pg_ctl</application>:
437 <screen>
438 <prompt>$</prompt> <userinput>pg_ctl status</userinput>
439 <computeroutput>
440 pg_ctl: postmaster is running (pid: 13718)
441 Command line was:
442 /usr/local/pgsql/bin/postmaster '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'
443 </computeroutput>
444 </screen>
445     This is the command line that would be invoked in restart mode.
446    </para>
447   </refsect2>
448  </refsect1>
449
450
451  <refsect1>
452   <title>See Also</title>
453
454   <para>
455    <xref linkend="app-postmaster">
456   </para>
457  </refsect1>
458
459 </refentry>
460
461 <!-- Keep this comment at the end of the file
462 Local variables:
463 mode:sgml
464 sgml-omittag:nil
465 sgml-shorttag:t
466 sgml-minimize-attributes:nil
467 sgml-always-quote-attributes:t
468 sgml-indent-step:1
469 sgml-indent-data:t
470 sgml-parent-document:nil
471 sgml-default-dtd-file:"../reference.ced"
472 sgml-exposed-tags:nil
473 sgml-local-catalogs:("/usr/lib/sgml/catalog")
474 sgml-local-ecat-files:nil
475 End:
476 -->