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