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