]> granicus.if.org Git - postgresql/blob - doc/src/sgml/ref/postmaster.sgml
d829a7e2d110f835321914d97bfd16b18720c8ee
[postgresql] / doc / src / sgml / ref / postmaster.sgml
1 <!--
2 $PostgreSQL: pgsql/doc/src/sgml/ref/postmaster.sgml,v 1.45 2004/02/03 17:34:02 tgl Exp $
3 PostgreSQL documentation
4 -->
5
6 <refentry id="app-postmaster">
7  <refmeta>
8   <refentrytitle id="APP-POSTMASTER-TITLE"><application>postmaster</application></refentrytitle>
9   <manvolnum>1</manvolnum>
10   <refmiscinfo>Application</refmiscinfo>
11  </refmeta>
12
13  <refnamediv>
14   <refname id="postmaster-ref">postmaster</refname>
15   <refpurpose><productname>PostgreSQL</productname> multiuser database server</refpurpose>
16  </refnamediv>
17
18  <indexterm zone="app-postmaster">
19   <primary>postmaster</primary>
20  </indexterm>
21
22  <refsynopsisdiv>
23   <cmdsynopsis>
24    <command>postmaster</command>
25    <arg>-A <group choice="plain"><arg>0</arg><arg>1</arg></group></arg>
26    <arg>-B <replaceable>nbuffers</replaceable></arg>
27    <arg>-c <replaceable>name</replaceable>=<replaceable>value</replaceable></arg>
28    <arg>-d <replaceable>debug-level</replaceable></arg>
29    <arg>-D <replaceable>datadir</replaceable></arg>
30    <arg>-F</arg>
31    <arg>-h <replaceable>hostname</replaceable></arg>
32    <arg>-i</arg>
33    <arg>-k <replaceable>directory</replaceable></arg>
34    <arg>-l</arg>
35    <arg>-N <replaceable>max-connections</replaceable></arg>
36    <arg>-o <replaceable>extra-options</replaceable></arg>
37    <arg>-p <replaceable>port</replaceable></arg>
38    <arg>-S</arg>
39    <arg>--<replaceable>name</replaceable>=<replaceable>value</replaceable></arg>
40    <group><arg>-n</arg><arg>-s</arg></group>
41   </cmdsynopsis>
42  </refsynopsisdiv>
43
44  <refsect1>
45   <title>Description</title>
46
47   <para>
48    <command>postmaster</command> is the
49    <productname>PostgreSQL</productname> multiuser database server.
50    In order for a client application to access a database it connects
51    (over a network or locally) to a running
52    <command>postmaster</command>.  The
53    <command>postmaster</command> then starts a separate server
54    process (<quote><xref linkend="app-postgres"></quote>) to handle
55    the connection.  The <command>postmaster</command> also
56    manages the communication among server processes.
57   </para>
58
59   <para>
60    By default the <command>postmaster</command> starts in the
61    foreground and prints log messages to the standard error stream.  In
62    practical applications the <command>postmaster</command>
63    should be started as a background process, perhaps at boot time.
64   </para>
65
66   <para>
67    One <command>postmaster</command> always manages the data
68    from exactly one database cluster.  A database cluster is a
69    collection of databases that is stored at a common file system
70    location.  When the <command>postmaster</command> starts it needs to know the location
71    of the database cluster files (<quote>data area</quote>).  This is
72    done with the <option>-D</option> invocation option or the
73    <envar>PGDATA</envar> environment variable; there is no default.
74    More than one <command>postmaster</command> process can run on a system at one time,
75    as long as they use different data areas and different
76    communication ports (see below).  A data area is created with <xref
77    linkend="app-initdb">.
78   </para>
79  </refsect1>
80
81  <refsect1 id="app-postmaster-options">
82   <title>Options</title>
83
84    <para>
85     <command>postmaster</command> accepts the following
86     command line arguments.  For a detailed discussion of the options
87     consult <xref linkend="runtime-config">.  You can also save typing most of these
88     options by setting up a configuration file.
89     
90     <variablelist>
91      <varlistentry>
92       <term><option>-A 0|1</option></term>
93       <listitem>
94        <para>
95         Enables run-time assertion checks, which is a debugging aid to
96         detect programming mistakes.  This is only available if it was
97         enabled during compilation.  If so, the default is on.
98        </para>
99       </listitem>
100      </varlistentry>
101
102      <varlistentry>
103       <term><option>-B <replaceable class="parameter">nbuffers</replaceable></option></term>
104       <listitem>
105        <para>
106         Sets the number of shared buffers for use by the server
107         processes.  This value defaults to 64 buffers, where each
108         buffer is 8 kB.
109        </para>
110       </listitem>
111      </varlistentry>
112
113      <varlistentry>
114       <term><option>-c <replaceable>name</replaceable>=<replaceable>value</replaceable></option></term>
115       <listitem>
116        <para>
117         Sets a named run-time parameter. Consult <xref linkend="runtime-config"> for
118         a list and descriptions.  Most of the other command line
119         options are in fact short forms of such a parameter
120         assignment.  <option>-c</> can appear multiple times to set
121         multiple parameters.
122        </para>
123       </listitem>
124      </varlistentry>
125
126      <varlistentry>
127       <term><option>-d <replaceable>debug-level</replaceable></option></term>
128       <listitem>
129        <para>
130         Sets the debug level.  The higher this value is set, the more
131         debugging output is written to the server log.  Values are from
132         1 to 5.
133        </para>
134       </listitem>
135      </varlistentry>
136
137      <varlistentry>
138       <term><option>-D <replaceable class="parameter">datadir</replaceable></option></term>
139       <listitem>
140        <para>
141         Specifies the file system location of the data directory.  See
142         discussion above.
143        </para>
144       </listitem>
145      </varlistentry>
146
147      <varlistentry>
148       <term><option>-F</option></term>
149       <listitem>
150        <para>
151         Disables <function>fsync</function> calls for performance
152         improvement, at the risk of data corruption in event of a
153         system crash.  This option corresponds to setting
154         <literal>fsync=false</> in <filename>postgresql.conf</>. Read the detailed
155         documentation before using this!
156        </para>
157        <para>
158         <option>--fsync=true</option> has the opposite effect
159         of this option.
160        </para>
161       </listitem>
162      </varlistentry>
163
164      <varlistentry>
165       <term><option>-h <replaceable class="parameter">hostname</replaceable></option></term>
166       <listitem>
167        <para>
168         Specifies the IP host name or address on which the
169         <command>postmaster</command> is to listen for
170         connections from client applications.  Defaults to
171         listening on all configured addresses (including
172         <systemitem class="systemname">localhost</systemitem>).
173        </para>
174       </listitem>
175      </varlistentry>
176
177      <varlistentry>
178       <term><option>-i</option></term>
179       <listitem>
180        <para>
181         Allows clients to connect via TCP/IP (Internet domain)
182         connections.  Without this option, only local Unix domain
183         socket connections are accepted. This option corresponds
184         to setting <literal>tcpip_socket=true</> in <filename>postgresql.conf</>.
185        </para>
186        <para>
187         <option>--tcpip-socket=false</option> has the opposite
188         effect of this option.
189        </para>
190       </listitem>
191      </varlistentry>
192
193      <varlistentry>
194       <term><option>-k <replaceable class="parameter">directory</replaceable></option></term>
195       <listitem>
196        <para>
197         Specifies the directory of the Unix-domain socket on which the
198         <command>postmaster</command> is to listen for
199         connections from client applications.  The default is normally
200         <filename>/tmp</filename>, but can be changed at build time.
201        </para>
202       </listitem>
203      </varlistentry>
204
205      <varlistentry>
206       <term><option>-l</option></term>
207       <listitem>
208        <para>
209         Enables secure connections using SSL.  The <option>-i</option>
210         option is also required.  You must have compiled with SSL
211         enabled to use this option.
212        </para>
213       </listitem>
214      </varlistentry>
215
216      <varlistentry>
217       <term><option>-N <replaceable class="parameter">max-connections</replaceable></option></term>
218       <listitem>
219        <para>
220         Sets the maximum number of client connections that this
221         <command>postmaster</command> will accept.  By
222         default, this value is 32, but it can be set as high as your
223         system will support.  (Note that
224         <option>-B</option> is required to be at least twice
225         <option>-N</option>.  See <xref linkend="kernel-resources"> for a discussion of
226         system resource requirements for large numbers of client
227         connections.)
228        </para>
229       </listitem>
230      </varlistentry>
231
232      <varlistentry>
233       <term><option>-o <replaceable class="parameter">extra-options</replaceable></option></term>
234       <listitem>
235        <para>
236         The command line-style options specified in <replaceable
237         class="parameter">extra-options</replaceable> are passed to
238         all server processes started by this
239         <command>postmaster</command>.  See <xref
240         linkend="app-postgres"> for possibilities.  If the option
241         string contains any spaces, the entire string must be quoted.
242        </para>
243       </listitem>
244      </varlistentry>
245
246      <varlistentry>
247       <term><option>-p <replaceable class="parameter">port</replaceable></option></term>
248       <listitem>
249        <para>
250         Specifies the TCP/IP port or local Unix domain socket file
251         extension on which the <command>postmaster</command>
252         is to listen for connections from client applications.
253         Defaults to the value of the <envar>PGPORT</envar> environment
254         variable, or if <envar>PGPORT</envar> is not set, then
255         defaults to the value established during compilation (normally
256         5432).  If you specify a port other than the default port,
257         then all client applications must specify the same port using
258         either command-line options or <envar>PGPORT</envar>.
259        </para>
260       </listitem>
261      </varlistentry>
262
263      <varlistentry>
264       <term><option>-S</option></term>
265       <listitem>
266        <para>
267         Specifies that the <command>postmaster</command>
268         process should start up in silent mode.  That is, it will
269         disassociate from the user's (controlling) terminal, start its
270         own process group, and redirect its standard output and
271         standard error to <filename>/dev/null</filename>.
272        </para>
273        <para>
274         Using this switch discards all logging output, which is
275         probably not what you want, since it makes it very difficult
276         to troubleshoot problems.  See below for a better way to start
277         the <command>postmaster</command> in the background.
278        </para>
279        <para>
280         <option>--silent-mode=false</option> has the opposite effect
281         of this option.
282        </para>
283       </listitem>
284      </varlistentry>
285
286      <varlistentry>
287       <term><option>--<replaceable>name</replaceable>=<replaceable>value</replaceable></option></term>
288       <listitem>
289        <para>
290         Sets a named run-time parameter; a shorter form of
291         <option>-c</>.
292        </para>
293       </listitem>
294      </varlistentry>
295
296     </variablelist>
297    </para>
298
299    <para>
300     Two additional command line options are available for debugging
301     problems that cause a server process to die abnormally.  The
302     ordinary strategy in this situation is to notify all other server
303     processes that they must terminate and then reinitialize the
304     shared memory and semaphores.  This is because an errant server
305     process could have corrupted some shared state before terminating.
306     These options select alternative behaviors of the
307     <command>postmaster</command> in this situation.
308     <emphasis>Neither option is intended for use in ordinary
309     operation.</emphasis>
310    </para>
311
312    <para>
313    </para>
314
315    <para>
316     These special-case options are:
317
318     <variablelist>
319      <varlistentry>
320       <term><option>-n</option></term>
321       <listitem>
322        <para>
323         <command>postmaster</command>
324         will not reinitialize shared data structures.  A knowledgeable system
325         programmer can then use a debugger
326         to examine shared memory and semaphore state.
327        </para>
328      </listitem>
329     </varlistentry>
330
331     <varlistentry>
332       <term><option>-s</option></term>
333       <listitem>
334        <para>
335         <command>postmaster</command>
336         will stop all other server processes by sending the signal
337         <literal>SIGSTOP</literal>,
338         but will not cause them to terminate.  This permits system programmers
339         to collect core dumps from all server processes by hand.
340        </para>
341       </listitem>
342      </varlistentry>
343     </variablelist>
344    </para>
345
346  </refsect1>
347
348  <refsect1>
349   <title>Environment</title>
350
351   <variablelist>
352    <varlistentry>
353     <term><envar>PGCLIENTENCODING</envar></term>
354
355     <listitem>
356      <para>
357       Default character encoding used by clients.  (The clients may
358       override this individually.)  This value can also be set in the
359       configuration file.
360      </para>
361     </listitem>
362    </varlistentry>
363
364    <varlistentry>
365     <term><envar>PGDATA</envar></term>
366
367     <listitem>
368      <para>
369       Default data direction location
370      </para>
371     </listitem>
372    </varlistentry>
373
374    <varlistentry>
375     <term><envar>PGDATESTYLE</envar></term>
376
377     <listitem>
378      <para>
379       Default value of the <varname>DateStyle</varname> run-time
380       parameter.  (The use of this environment variable is deprecated.)
381      </para>
382     </listitem>
383    </varlistentry>
384
385    <varlistentry>
386     <term><envar>PGPORT</envar></term>
387
388     <listitem>
389      <para>
390       Default port (preferably set in the configuration file)
391      </para>
392     </listitem>
393    </varlistentry>
394
395    <varlistentry>
396     <term><envar>TZ</envar></term>
397
398     <listitem>
399      <para>
400       Server time zone
401      </para>
402     </listitem>
403    </varlistentry>
404
405    <varlistentry>
406     <term>others</term>
407
408     <listitem>
409      <para>
410       Other environment variables may be used to designate alternative
411       data storage locations.  See <xref linkend="manage-ag-alternate-locs"> for more
412       information.
413      </para>
414     </listitem>
415    </varlistentry>
416
417   </variablelist>
418  </refsect1>
419
420  <refsect1>
421    <title>Diagnostics</title>
422
423    <para>
424     A failure message mentioning <literal>semget</> or <literal>shmget</>
425     probably indicates you need to configure your kernel to provide adequate
426     shared memory and semaphores.  For more discussion see <xref
427     linkend="kernel-resources">.
428    </para>
429
430    <tip>
431     <para>
432      You may be able to postpone reconfiguring your kernel by decreasing
433      <varname>shared_buffers</varname> to reduce the shared memory consumption
434      of <productname>PostgreSQL</>, and/or by reducing
435      <varname>max_connections</varname> to reduce the semaphore consumption.
436     </para>
437    </tip>
438
439    <para>
440     A failure message suggesting that another postmaster is already running
441     should be checked carefully, for example by using the command
442 <screen>
443 <prompt>$</prompt> <userinput>ps ax | grep postmaster</userinput>
444 </screen>
445         or
446 <screen>
447 <prompt>$</prompt> <userinput>ps -ef | grep postmaster</userinput>
448 </screen>
449     depending on your system.  If you are certain that no conflicting
450     postmaster is running, you may remove the lock file mentioned in the
451     message and try again.
452    </para>
453
454    <para>
455     A failure message indicating inability to bind to a port may
456     indicate that that port is already in use by some
457     non-<productname>PostgreSQL</productname> process.  You may also
458     get this error if you terminate the <command>postmaster</command>
459     and immediately restart it using the same port; in this case, you
460     must simply wait a few seconds until the operating system closes
461     the port before trying again.  Finally, you may get this error if
462     you specify a port number that your operating system considers to
463     be reserved.  For example, many versions of Unix consider port
464     numbers under 1024 to be <quote>trusted</quote> and only permit
465     the Unix superuser to access them.
466    </para>
467
468  </refsect1>
469
470  <refsect1>
471   <title>Notes</title>
472   
473   <para>
474    If at all possible, <emphasis>do not</emphasis> use
475    <literal>SIGKILL</literal> to kill the
476    <command>postmaster</command>.  Doing so will prevent
477    <command>postmaster</command> from freeing the system
478    resources (e.g., shared memory and semaphores) that it holds before
479    terminating.  This may cause problems for starting a fresh
480    <command>postmaster</command> run.
481   </para>
482
483   <para>
484    To terminate the <command>postmaster</command> normally,
485    the signals <literal>SIGTERM</literal>, <literal>SIGINT</literal>,
486    or <literal>SIGQUIT</literal> can be used.  The first will wait for
487    all clients to terminate before quitting, the second will
488    forcefully disconnect all clients, and the third will quit
489    immediately without proper shutdown, resulting in a recovery run
490    during restart.   The <literal>SIGHUP</literal> signal will 
491    reload the server configuration files.
492   </para>
493
494   <para>
495    The utility command <xref linkend="app-pg-ctl"> can be used to
496    start and shut down the <command>postmaster</command>
497    safely and comfortably.
498   </para>
499
500   <para>
501    The <option>--</> options will not work on <systemitem
502    class="osname">FreeBSD</> or <systemitem class="osname">OpenBSD</>.
503    Use <option>-c</> instead. This is a bug in the affected operating
504    systems; a future release of <productname>PostgreSQL</productname>
505    will provide a workaround if this is not fixed.
506   </para>
507
508  </refsect1>
509
510  <refsect1 id="app-postmaster-examples">
511   <title>Examples</title>
512   <para>
513    To start <command>postmaster</command> in the background
514    using default values, type:
515
516 <screen>
517 <prompt>$</prompt> <userinput>nohup postmaster &gt;logfile 2&gt;&amp;1 &lt;/dev/null &amp;</userinput>
518 </screen>
519   </para>
520
521   <para>
522    To start <command>postmaster</command> with a specific
523    port:
524 <screen>
525 <prompt>$</prompt> <userinput>postmaster -p 1234</userinput>
526 </screen>
527    This command will start up <command>postmaster</command>
528    communicating through the port 1234. In order to connect to this
529    <command>postmaster</command> using <application>psql</>, you would need to
530    run it as
531 <screen>
532 <prompt>$</prompt> <userinput>psql -p 1234</userinput>
533 </screen>
534    or set the environment variable <envar>PGPORT</envar>:
535 <screen>
536 <prompt>$</prompt> <userinput>export PGPORT=1234</userinput>
537 <prompt>$</prompt> <userinput>psql</userinput>
538 </screen>
539   </para>
540
541   <para>
542    Named run-time parameters can be set in either of these styles:
543 <screen>
544 <prompt>$</prompt> <userinput>postmaster -c work_mem=1234</userinput>
545 <prompt>$</prompt> <userinput>postmaster --work-mem=1234</userinput>
546 </screen>
547    Either form overrides whatever setting might exist for <varname>work_mem</>
548    in <filename>postgresql.conf</>.  Notice that underscores in parameter
549    names can be written as either underscore or dash on the command line.
550   </para>
551
552   <tip>
553   <para>
554    Except for short-term experiments,
555    it's probably better practice to edit the setting in
556    <filename>postgresql.conf</> than to rely on a command-line switch
557    to set a parameter.
558   </para>
559   </tip>
560  </refsect1>
561
562  <refsect1>
563   <title>See Also</title>
564
565   <para>
566    <xref linkend="app-initdb">,
567    <xref linkend="app-pg-ctl">
568   </para>
569  </refsect1>
570 </refentry>
571
572 <!-- Keep this comment at the end of the file
573 Local variables:
574 mode: sgml
575 sgml-omittag:nil
576 sgml-shorttag:t
577 sgml-minimize-attributes:nil
578 sgml-always-quote-attributes:t
579 sgml-indent-step:1
580 sgml-indent-data:t
581 sgml-parent-document:nil
582 sgml-default-dtd-file:"../reference.ced"
583 sgml-exposed-tags:nil
584 sgml-local-catalogs:"/usr/lib/sgml/catalog"
585 sgml-local-ecat-files:nil
586 End:
587 -->