]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/pg_ctl-ref.sgml
Assorted reference page updates
[postgresql] / doc / src / sgml / ref / pg_ctl-ref.sgml
1 <!--
2 $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_ctl-ref.sgml,v 1.17 2002/10/11 23:03:48 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 <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, properly detaching from the
77    terminal and process group, and it 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, the standard input 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 are redirected to
87    <application>pg_ctl</application>'s standard output (not standard
88    error).  If no log file is chosen, the standard output of
89    <application>pg_ctl</application> should be redirected to a file or
90    piped to another process, for example a log rotating program,
91    otherwise the postmaster will write its output the the controlling
92    terminal (from the background) and will not leave the shell's
93    process group.
94   </para>
95
96   <para>
97    In <option>stop</option> mode, the postmaster that is running in
98    the specified data directory is shut down.  Three different
99    shutdown methods can be selected with the <option>-m</option>
100    option: <quote>Smart</quote> mode waits for all the clients to
101    disconnect.  This is the default.  <quote>Fast</quote> mode does
102    not wait for clients to disconnect.  All active transactions are
103    rolled back and clients are forcibly disconnected, then the
104    database is shut down.  <quote>Immediate</quote> mode will abort
105    all server processes without clean shutdown.  This will lead to a recovery
106    run on restart.
107   </para>
108
109   <para>
110    <option>restart</option> mode effectively executes a stop followed
111    by a start.  This allows the changing of postmaster command line
112    options.
113   </para>
114
115   <para>
116    <option>reload</option> mode simply sends the postmaster a <systemitem>SIGHUP</> signal,
117    causing it to reread its configuration files
118    (<filename>postgresql.conf</filename>, <filename>pg_hba.conf</filename>,
119    etc.).  This allows changing of configuration-file options that do not
120    require a complete restart to take effect.
121   </para>
122
123   <para>
124    <option>status</option> mode checks whether a postmaster is running
125    and if so displays the <acronym>PID</acronym> and the command line
126    options that were used to invoke it.
127   </para>
128  </refsect1>
129
130  <refsect1 id="app-pg-ctl-options">
131   <title>Options</title>
132
133   <para>
134
135     <variablelist>
136      <varlistentry>
137       <term>-D <replaceable class="parameter">datadir</replaceable></term>
138       <listitem>
139        <para>
140         Specifies the file system location of the database files.  If
141         this is omitted, the environment variable
142         <envar>PGDATA</envar> is used.
143        </para>
144       </listitem>
145      </varlistentry>
146
147      <varlistentry>
148       <term>-l <replaceable class="parameter">filename</replaceable></term>
149       <listitem>
150        <para>
151         Append the server log output to
152         <replaceable>filename</replaceable>.  If the file does not
153         exist, it is created.  The <systemitem>umask</> is set to 077, so access to
154         the log file from other users is disallowed by default.
155        </para>
156       </listitem>
157      </varlistentry>
158
159      <varlistentry>
160       <term>-m <replaceable class="parameter">mode</replaceable></term>
161       <listitem>
162        <para>
163         Specifies the shutdown mode.  <replaceable>mode</replaceable>
164         may be <literal>smart</literal>, <literal>fast</literal>, or
165         <literal>immediate</literal>, or the first letter of one of
166         these three.
167        </para>
168       </listitem>
169      </varlistentry>
170
171      <varlistentry>
172       <term>-o <replaceable class="parameter">options</replaceable></term>
173       <listitem>
174        <para>
175         Specifies options to be passed directly to
176         <application>postmaster</application>.
177        </para>
178        <para>
179         The parameters are usually surrounded by single or double
180         quotes to ensure that they are passed through as a group.
181        </para>
182       </listitem>
183      </varlistentry>
184
185      <varlistentry>
186       <term>-p <replaceable class="parameter">path</replaceable></term>
187       <listitem>
188        <para>
189         Specifies the location of the <filename>postmaster</filename>
190         executable.  By default the postmaster is taken from the same
191         directory as <command>pg_ctl</>, or failing that, the hard-wired
192         installation directory.  It is not necessary to use this
193         option unless you are doing something unusual and get errors
194         that the postmaster was not found.
195        </para>
196       </listitem>
197      </varlistentry>
198
199      <varlistentry>
200       <term>-s</term>
201       <listitem>
202        <para>
203         Only print errors, no informational messages.
204        </para>
205       </listitem>
206      </varlistentry>
207
208      <varlistentry>
209       <term>-w</term>
210       <listitem>
211        <para>
212         Wait for the start or shutdown to complete.  Times out after
213         60 seconds.  This is the default for shutdowns.
214        </para>
215       </listitem>
216      </varlistentry>
217
218      <varlistentry>
219       <term>-W</term>
220       <listitem>
221        <para>
222         Do not wait for start or shutdown to complete.  This is the
223         default for starts and restarts.
224        </para>
225       </listitem>
226      </varlistentry>
227     </variablelist>
228    </para>
229  </refsect1>
230
231
232  <refsect1>
233   <title>Environment</title>
234
235   <variablelist>
236    <varlistentry>
237     <term><envar>PGDATA</envar></term>
238
239     <listitem>
240      <para>
241       Default data direction location
242      </para>
243     </listitem>
244    </varlistentry>
245   </variablelist>
246
247   <para>
248    For others, see <xref linkend="app-postmaster">.
249   </para>
250  </refsect1>
251
252
253  <refsect1>
254   <title>Files</title>
255
256    <para>
257     If the file <filename>postmaster.opts.default</filename> exists in
258     the data directory, the contents of the file will be passed as
259     options to the <application>postmaster</application>, unless
260     overridden by the <option>-o</option> option.
261    </para>
262  </refsect1>
263
264
265  <refsect1>
266   <title>Notes</title>
267
268   <para>
269    Waiting for complete start is not a well-defined operation and may
270    fail if access control is set up so that a local client cannot
271    connect without manual interaction.  It should be avoided.
272   </para>
273  </refsect1>
274
275
276  <refsect1 id="R1-APP-PGCTL-2">
277   <title>Examples</title>
278
279   <refsect2 id="R2-APP-PGCTL-3">
280    <title>Starting the postmaster</title>
281
282    <para>
283     To start up a <application>postmaster</application>:
284 <screen>
285 <prompt>$</prompt> <userinput>pg_ctl start</userinput>
286 </screen>
287    </para>
288
289    <para>
290     An example of starting the <application>postmaster</application>,
291     blocking until the postmaster comes up is:
292 <screen>
293 <prompt>$</prompt> <userinput>pg_ctl -w start</userinput>
294 </screen>
295    </para>
296
297    <para>
298     For a <application>postmaster</application> using port 5433, and
299     running without <function>fsync</function>, use:
300 <screen>
301 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" start</userinput>
302 </screen>
303    </para>
304   </refsect2>
305
306   <refsect2 id="R2-APP-PGCTL-4">
307    <title>Stopping the postmaster</title>
308    <para>
309 <screen>
310 <prompt>$</prompt> <userinput>pg_ctl stop</userinput>
311 </screen>
312     stops the postmaster. Using the <option>-m</option> switch allows one
313     to control <emphasis>how</emphasis> the backend shuts down.
314    </para>
315   </refsect2>
316
317   <refsect2 id="R2-APP-PGCTL-5">
318    <title>Restarting the postmaster</title>
319
320    <para>
321     This is almost equivalent to stopping the
322     <application>postmaster</application> and starting it again
323     except that <command>pg_ctl</command> saves and reuses the command line options that
324     were passed to the previously running instance.  To restart
325     the <application>postmaster</application> in the simplest form:
326 <screen>
327 <prompt>$</prompt> <userinput>pg_ctl restart</userinput>
328 </screen>
329    </para>
330
331    <para>
332     To restart <application>postmaster</application>,
333     waiting for it to shut down and to come up:
334 <screen>
335 <prompt>$</prompt> <userinput>pg_ctl -w restart</userinput>
336 </screen>
337    </para>
338
339    <para>
340     To restart using port 5433 and disabling <function>fsync</> after restarting:
341 <screen>
342 <prompt>$</prompt> <userinput>pg_ctl -o "-F -p 5433" restart</userinput>
343 </screen>
344    </para>
345   </refsect2>
346
347   <refsect2 id="R2-APP-PGCTL-6">
348    <title>Showing postmaster status</title>
349
350    <para>
351     Here is a sample status output from
352     <application>pg_ctl</application>:
353 <screen>
354 <prompt>$</prompt> <userinput>pg_ctl status</userinput>
355 <computeroutput>
356 pg_ctl: postmaster is running (pid: 13718)
357 Command line was:
358 /usr/local/pgsql/bin/postmaster '-D' '/usr/local/pgsql/data' '-p' '5433' '-B' '128'
359 </computeroutput>
360 </screen>
361     This is the command line that would be invoked in restart mode.
362    </para>
363   </refsect2>
364  </refsect1>
365
366
367  <refsect1>
368   <title>See Also</title>
369
370   <para>
371    <xref linkend="app-postmaster">, <citetitle>PostgreSQL Administrator's Guide</citetitle>
372   </para>
373  </refsect1>
374
375 </refentry>
376
377 <!-- Keep this comment at the end of the file
378 Local variables:
379 mode:sgml
380 sgml-omittag:nil
381 sgml-shorttag:t
382 sgml-minimize-attributes:nil
383 sgml-always-quote-attributes:t
384 sgml-indent-step:1
385 sgml-indent-data:t
386 sgml-parent-document:nil
387 sgml-default-dtd-file:"../reference.ced"
388 sgml-exposed-tags:nil
389 sgml-local-catalogs:("/usr/lib/sgml/catalog")
390 sgml-local-ecat-files:nil
391 End:
392 -->