]> granicus.if.org Git - postgresql/blob - doc/src/sgml/runtime.sgml
This patch updates doc/src/sgml/runtime.sgml to refer to "MacOS X", not
[postgresql] / doc / src / sgml / runtime.sgml
1 <!--
2 $Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.163 2002/12/09 21:03:30 momjian Exp $
3 -->
4
5 <Chapter Id="runtime">
6  <Title>Server Run-time Environment</Title>
7
8  <Para>
9   This chapter discusses how to set up and run the database server
10   and the interactions with the operating system.
11  </para>
12
13  <sect1 id="postgres-user">
14   <title>The <productname>PostgreSQL</productname> User Account</title>
15
16   <indexterm>
17    <primary>postgres user</primary>
18   </indexterm>
19
20   <para>
21    As with any other server daemon that is connected to outside world,
22    it is advisable to run <productname>PostgreSQL</productname> under a
23    separate user account. This user account should only own the data
24    that is managed by the server, and should not be shared with other
25    daemons. (For example, using the user <quote>nobody</quote> is a bad
26    idea.) It is not advisable to install executables owned by
27    this user because compromised systems could then modify their own 
28    binaries.
29   </para>
30
31   <para>
32    To add a Unix user account to your system, look for a command
33    <command>useradd</command> or <command>adduser</command>. The user
34    name <systemitem>postgres</systemitem> is often used but is by no
35    means required.
36   </para>
37  </sect1>
38
39  <sect1 id="creating-cluster">
40   <title>Creating a Database Cluster</title>
41
42   <indexterm>
43    <primary>database cluster</primary>
44   </indexterm>
45
46   <indexterm>
47    <primary>data area</primary>
48    <see>database cluster</see>
49   </indexterm>
50
51   <para>
52    Before you can do anything, you must initialize a database storage
53    area on disk. We call this a <firstterm>database cluster</firstterm>.
54    (<acronym>SQL</acronym> uses the term catalog cluster instead.) A
55    database cluster is a collection of databases is accessible by a
56    single instance of a running database server. After initialization, a
57    database cluster will contain a database named
58    <literal>template1</literal>. As the name suggests, this will be used
59    as a template for subsequently created databases; it should not be
60    used for actual work.  (See <xref linkend="managing-databases"> for information
61    about creating databases.)
62   </para>
63
64   <para>
65    In file system terms, a database cluster will be a single directory
66    under which all data will be stored. We call this the <firstterm>data
67    directory</firstterm> or <firstterm>data area</firstterm>. It is
68    completely up to you where you choose to store your data.  There is no
69    default, although locations such as
70    <filename>/usr/local/pgsql/data</filename> or
71    <filename>/var/lib/pgsql/data</filename> are popular. To initialize a
72    database cluster, use the command <command>initdb</command>, which is
73    installed with <productname>PostgreSQL</productname>. The desired
74    file system location of your database system is indicated by the
75    <option>-D</option> option, for example
76 <screen>
77 <prompt>$</> <userinput>initdb -D /usr/local/pgsql/data</userinput>
78 </screen>
79    Note that you must execute this command while logged into the
80    <productname>PostgreSQL</productname> user account, which is
81    described in the previous section.
82   </para>
83
84   <tip>
85    <para>
86     <indexterm>
87      <primary><envar>PGDATA</envar></primary>
88     </indexterm>
89     As an alternative to the <option>-D</option> option, you can set
90     the environment variable <envar>PGDATA</envar>.
91    </para>
92   </tip>
93
94   <para>
95    <command>initdb</command> will attempt to create the directory you
96    specify if it does not already exist. It is likely that it will not
97    have the permission to do so (if you followed our advice and created
98    an unprivileged account). In that case you should create the
99    directory yourself (as root) and change the owner to be the
100    <productname>PostgreSQL</productname> user. Here is how this might
101    be done:
102 <screen>
103 root# <userinput>mkdir /usr/local/pgsql/data</userinput>
104 root# <userinput>chown postgres /usr/local/pgsql/data</userinput>
105 root# <userinput>su postgres</userinput>
106 postgres$ <userinput>initdb -D /usr/local/pgsql/data</userinput>
107 </screen>
108   </para>
109
110   <para>
111    <command>initdb</command> will refuse to run if the data directory
112    looks like it it has already been initialized.</para>
113
114   <para>
115    Because the data directory contains all the data stored in the
116    database, it is essential that it be secured from unauthorized
117    access. <command>initdb</command> therefore revokes access
118    permissions from everyone but the
119    <productname>PostgreSQL</productname> user.
120   </para>
121
122   <para>
123    However, while the directory contents are secure, the default
124    client authentication setup allows any local user to connect to the
125    database and even become the database superuser. If you don't trust
126    other local users, we recommend you use <command>initdb</command>'s
127    <option>-W</option> or <option>--pwprompt</option> option to assign a
128    password to the database superuser. After <command>initdb</command>,
129    modify the <filename>pg_hba.conf</filename> file to use <literal>md5</> or
130    <literal>password</> instead of <literal>trust</> authentication
131    <emphasis>before</> you start the server for the first time. (Other,
132    approaches include using <literal>ident</literal> authentication or
133    file system permissions to restrict connections. See <xref
134    linkend="client-authentication"> for more information.)
135   </para>
136
137   <para>
138    <indexterm><primary>locale</></>
139    <indexterm><primary>LC_COLLATE</></>
140    <command>initdb</command> also initializes the default locale for
141    the database cluster.  Normally, it will just take the locale
142    settings in the environment and apply them to the initialized
143    database.  It is possible to specify a different locale for the
144    database; more information about that can be found in <xref
145    linkend="locale">.  One surprise you might encounter while running
146    <command>initdb</command> is a notice similar to this:
147 <screen>
148 The database cluster will be initialized with locale de_DE.
149 This locale setting will prevent the use of indexes for pattern matching
150 operations.  If that is a concern, rerun initdb with the collation order
151 set to "C".  For more information see the Administrator's Guide.
152 </screen>
153    This is intended to warn you that the currently selected locale
154    will cause indexes to be sorted in an order that prevents them from
155    being used for <literal>LIKE</> and regular-expression searches. If you need
156    good performance in such searches, you should set your current
157    locale to <literal>C</> and re-run <command>initdb</command>, e.g.,
158    by running <literal>initdb --lc-collate=C</literal>. The sort
159    order used within a particular database cluster is set by
160    <command>initdb</command> and cannot be changed later, short of
161    dumping all data, rerunning <command>initdb</command>, and
162    reloading the data. So it's important to make this choice correctly
163    the first time.
164   </para>
165  </sect1>
166
167  <sect1 id="postmaster-start">
168   <title>Starting the Database Server</title>
169
170   <para>
171    <indexterm>
172     <primary>postmaster</primary>
173    </indexterm>
174    Before anyone can access the database, you must start the database
175    server. The database server is called
176    <firstterm>postmaster</firstterm>. The postmaster must know where to
177    find the data it is supposed to use. This is done with the
178    <option>-D</option> option. Thus, the simplest way to start the
179    server is:
180 <screen>
181 $ <userinput>postmaster -D /usr/local/pgsql/data</userinput>
182 </screen>
183    which will leave the server running in the foreground. This must be
184    done while logged into the <productname>PostgreSQL</productname> user
185    account. Without <option>-D</option>, the server will try to use
186    the data directory in the environment variable <envar>PGDATA</envar>.
187    If neither of these succeed, it will fail.
188   </para>
189
190   <para>
191    To start the <application>postmaster</application> in the
192    background, use the usual shell syntax:
193 <screen>
194 $ <userinput>postmaster -D /usr/local/pgsql/data &gt; logfile 2&gt;&amp;1 &amp;</userinput>
195 </screen>
196    It is an important to store the server's <systemitem>stdout</> and
197    <systemitem>stderr</> output somewhere, as shown above. It will help
198    for auditing purposes and to diagnose problems. (See <xref
199    linkend="logfile-maintenance"> for a more thorough discussion of log
200    file handling.)
201   </para>
202
203   <para>
204    <indexterm>
205     <primary>TCP/IP</primary>
206    </indexterm>
207    The postmaster also takes a number of other command line options. For
208    more information, see the reference page and <xref
209    linkend="runtime-config"> below. In particular, in order for the
210    server to accept TCP/IP connections (rather than just Unix domain
211    socket ones), you must specify the <option>-i</option> option.
212   </para>
213
214   <para>
215    <indexterm>
216     <primary>pg_ctl</primary>
217    </indexterm>
218    This shell syntax can get tedious quickly.  Therefore the shell
219    script wrapper <application>pg_ctl</application> is provided to
220    simplify some tasks.  For example:
221 <programlisting>
222 pg_ctl start -l logfile
223 </programlisting>
224    will start the server in the background and put the output into the
225    named log file. The <option>-D</option> option has the same meaning
226    here as in the postmaster. <application>pg_ctl</application> is also
227    capable of stopping the server.
228   </para>
229
230   <para>
231    Normally, you will want to start the database server when the
232    computer boots. Autostart scripts are operating system-specific.
233    There are a few distributed with
234    <productname>PostgreSQL</productname> in the
235    <filename>/contrib/start-scripts</> directory. This may require root
236    privileges.
237   </para>
238
239   <para>
240    Different systems have different conventions for starting up daemons
241    at boot time. Many systems have a file
242    <filename>/etc/rc.local</filename> or
243    <filename>/etc/rc.d/rc.local</filename>. Others use
244    <filename>rc.d</> directories. Whatever you do, the server must be
245    run by the <productname>PostgreSQL</productname> user account
246    <emphasis>and not by root</emphasis> or any other user. Therefore you
247    probably should form your commands using <literal>su -c '...'
248    postgres</literal>.  For example:
249 <programlisting>
250 su -c 'pg_ctl start -D /usr/local/pgsql/data -l serverlog' postgres
251 </programlisting>
252   </para>
253
254   <para>
255    Here are a few more operating system specific suggestions. (Always
256    replace these with the proper installation directory and the user
257    name.)
258
259    <itemizedlist>
260     <listitem>
261      <para>
262       For <productname>FreeBSD</productname>, look at the file
263       <filename>contrib/start-scripts/freebsd</filename> in the
264       <productname>PostgreSQL</productname> source distribution.
265       <indexterm><primary>FreeBSD</></>
266      </para>
267     </listitem>
268
269     <listitem>
270      <para>
271       On <productname>OpenBSD</productname>, add the following lines
272       to the file <filename>/etc/rc.local</filename>:
273       <indexterm><primary>OpenBSD</></>
274 <programlisting>
275 if [ -x /usr/local/pgsql/bin/pg_ctl -a -x /usr/local/pgsql/bin/postmaster ]; then
276     su - -c '/usr/local/pgsql/bin/pg_ctl start -l /var/postgresql/log -s' postgres
277     echo -n ' postgresql'
278 fi
279 </programlisting>
280      </para>
281     </listitem>
282
283     <listitem>
284      <para>
285       On <productname>Linux</productname> systems either add
286       <indexterm><primary>Linux</></>
287 <programlisting>
288 /usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data
289 </programlisting>
290       to <filename>/etc/rc.d/rc.local</filename> or look at the file
291       <filename>contrib/start-scripts/linux</filename> in the
292       <productname>PostgreSQL</productname> source distribution.
293      </para>
294     </listitem>
295
296     <listitem>
297      <para>
298       On <productname>NetBSD</productname>, either use the
299       <productname>FreeBSD</productname> or
300       <productname>Linux</productname> start scripts, depending on
301       preference. <indexterm><primary>NetBSD</></>
302      </para>
303     </listitem>
304
305     <listitem>
306      <para>
307       On <productname>Solaris</productname>, create a file called
308       <filename>/etc/init.d/postgresql</filename> which should contain
309       the following line:
310       <indexterm><primary>Solaris</></>
311 <programlisting>
312 su - postgres -c "/usr/local/pgsql/bin/pg_ctl start -l logfile -D /usr/local/pgsql/data"
313 </programlisting>
314       Then, create a symbolic link to it in <filename>/etc/rc3.d</> as
315       <literal>S99postgresql</>.
316      </para>
317     </listitem>
318    </itemizedlist>
319
320   </para>
321
322    <para>
323     While the <application>postmaster</application> is running, its
324     <acronym>PID</acronym> is in the file
325     <filename>postmaster.pid</filename> in the data directory. This is
326     used to prevent multiple postmasters running in the same data
327     directory, and can also be used for shutting down the postmaster.
328    </para>
329
330    <sect2 id="postmaster-start-failures">
331     <title>Server Start-up Failures</title>
332
333     <para>
334      There are several common reasons the postmaster might fail to
335      start. Check the postmaster's log file, or start it by hand
336      (without redirecting standard output or standard error) and see
337      what error messages appear. Some of the error messages are
338      self-explanatory, but some are not, as shown below:
339     </para>
340
341     <para>
342 <screen>
343 FATAL: StreamServerPort: bind() failed: Address already in use
344         Is another postmaster already running on that port?
345 </screen>
346      This usually means just what it suggests: you tried to start
347      another postmaster on the same port where one is already running.
348      However, if the kernel error message is not <computeroutput>Address
349      already in use</computeroutput> or some variant of that, there may
350      be a different problem. For example, trying to start a postmaster
351      on a reserved port number may draw something like:
352 <screen>
353 $ <userinput>postmaster -i -p 666</userinput>
354 FATAL: StreamServerPort: bind() failed: Permission denied
355         Is another postmaster already running on that port?
356 </screen>
357     </para>
358
359     <para>
360      A message like:
361 <screen>
362 IpcMemoryCreate: shmget(key=5440001, size=83918612, 01600) failed: Invalid argument
363 FATAL 1:  ShmemCreate: cannot create region
364 </screen>
365      probably means your kernel's limit on the size of shared memory is
366      smaller than the buffer area <productname>PostgreSQL</productname>
367      is trying to create (83918612 bytes in this example). Or it could
368      mean that you don't have System-V-style shared memory support
369      configured into your kernel at all. As a temporary workaround, you
370      can try starting the postmaster with a smaller-than-normal number
371      of buffers (<option>-B</option> switch). You will eventually want
372      to reconfigure your kernel to increase the allowed shared memory
373      size. You may see this message when trying to start multiple
374      postmasters on the same machine if their total space requested
375      exceeds the kernel limit.
376     </para>
377
378     <para>
379      An error like:
380 <screen>
381 IpcSemaphoreCreate: semget(key=5440026, num=16, 01600) failed: No space left on device
382 </screen>
383      does <emphasis>not</emphasis> mean you've run out of disk space. It
384      means your kernel's limit on the number of System V semaphores is
385      smaller than the number <productname>PostgreSQL</productname> wants
386      to create. As above, you may be able to work around the problem by
387      starting the postmaster with a reduced number of allowed connections
388      (<option>-N</option> switch), but you'll eventually want to
389      increase the kernel limit.
390     </para>
391
392     <para>
393      If you get an <quote>illegal system call</> error, it is likely that
394      shared memory or semaphores are not supported in your kernel at
395      all. In that case your only option is to reconfigure the kernel to
396      enable these features.
397     </para>
398
399     <para>
400      Details about configuring <systemitem class="osname">System V</>
401      <acronym>IPC</> facilities are given in <xref linkend="sysvipc">.
402     </para>
403    </sect2>
404
405    <sect2 id="client-connection-problems">
406     <title>Client Connection Problems</title>
407
408     <para>
409      Although the error conditions possible on the client side are quite
410      varied and application-dependent, a few of them might be directly
411      related to how the server was started up. Conditions other than
412      those shown below should be documented with the respective client
413      application.
414     </para>
415
416     <para>
417 <screen>
418 psql: could not connect to server: Connection refused
419         Is the server running on host server.joe.com and accepting
420         TCP/IP connections on port 5432?
421 </screen>
422      This is the generic <quote>I couldn't find a server to talk
423      to</quote> failure. It looks like the above when TCP/IP
424      communication is attempted. A common mistake is to forget the
425      <option>-i</option> option to allow the postmaster to accept TCP/IP
426      connections.
427     </para>
428
429     <para>
430      Alternatively, you'll get this when attempting Unix-socket
431      communication to a local postmaster:
432 <screen>
433 psql: could not connect to server: Connection refused
434         Is the server running locally and accepting
435         connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
436 </screen>
437     </para>
438
439     <para>
440      The last line is useful in verifying that the client is trying to
441      connect to the right place. If there is in fact no postmaster
442      running there, the kernel error message will typically be either
443      <computeroutput>Connection refused</computeroutput> or
444      <computeroutput>No such file or directory</computeroutput>, as
445      illustrated. (It is important to realize that
446      <computeroutput>Connection refused</computeroutput> in this context
447      does <emphasis>not</emphasis> mean that the postmaster got your
448      connection request and rejected it -- that case will produce a
449      different message, as shown in <xref
450      linkend="client-authentication-problems">.) Other error messages
451      such as <computeroutput>Connection timed out</computeroutput> may
452      indicate more fundamental problems, like lack of network
453      connectivity.
454     </para>
455    </sect2>
456   </sect1>
457
458   <sect1 id="runtime-config">
459    <Title>Run-time Configuration</Title>
460
461    <indexterm>
462     <primary>configuration</primary>
463     <secondary>server</secondary>
464    </indexterm>
465
466    <para>
467     There are a lot of configuration parameters that affect the behavior
468     of the database system. Here we describe how to set them and the
469     following subsections will discuss each in detail.
470    </para>
471
472    <para>
473     All parameter names are case-insensitive. Every parameter takes a
474     value of one of the four types: Boolean, integer, floating point,
475     and string. Boolean values are <literal>ON</literal>,
476     <literal>OFF</literal>, <literal>TRUE</literal>,
477     <literal>FALSE</literal>, <literal>YES</literal>,
478     <literal>NO</literal>, <literal>1</literal>, <literal>0</literal>
479     (case-insensitive) or any non-ambiguous prefix of these.
480    </para>
481
482    <para>
483     One way to set these options is to edit the file
484     <filename>postgresql.conf</filename> in the data directory. (A
485     default file is installed there.) An example of what this file might
486     look like is:
487 <programlisting>
488 # This is a comment
489 log_connections = yes
490 syslog = 2
491 search_path = '$user, public'
492 </programlisting>
493     As you see, options are one per line. The equal sign between name
494     and value is optional. Whitespace is insignificant and blank lines
495     are ignored. Hash marks (<quote>#</quote>) introduce comments
496     anywhere.  Parameter values that are not simple identifiers or
497     numbers should be single-quoted.
498    </para>
499
500    <para>
501     <indexterm>
502      <primary>SIGHUP</primary>
503     </indexterm>
504     The configuration file is reread whenever the postmaster receives a
505     <systemitem>SIGHUP</> signal (which is most easily sent by means of
506     <literal>pg_ctl reload</>). The postmaster also propagates this
507     signal to all currently running backend processes so that existing
508     sessions also get the new value. Alternatively, you can send the
509     signal to a single backend process directly.
510    </para>
511
512    <para>
513     A second way to set these configuration parameters is to give them
514     as a command line option to the postmaster, such as:
515 <programlisting>
516 postmaster -c log_connections=yes -c syslog=2
517 </programlisting>
518     which would have the same effect as the previous example.
519     Command-line options override any conflicting settings in
520     <filename>postgresql.conf</filename>.
521    </para>
522
523    <para>
524     Occasionally it is also useful to give a command line option to
525     one particular backend session only. The environment variable
526     <envar>PGOPTIONS</envar> can be used for this purpose on the
527     client side:
528 <programlisting>
529 env PGOPTIONS='-c geqo=off' psql
530 </programlisting>
531     (This works for any <application>libpq</>-based client application, not just
532     <application>psql</application>.) Note that this won't work for
533     options that are fixed when the server is started, such as the port
534     number.
535    </para>
536
537    <para>
538     Some options can be changed in individual SQL sessions with the
539     <command>SET</command> command, for example:
540 <screen>
541 =&gt; <userinput>SET ENABLE_SEQSCAN TO OFF;</userinput>
542 </screen>
543     See the SQL command language reference for details on the syntax.
544    </para>
545
546    <para>
547     Furthermore, it is possible to assign a set of option settings to
548     a user or a database.  Whenever a session is started, the default
549     settings for the user and database involved are loaded.  The
550     commands <literal>ALTER DATABASE</literal> and <literal>ALTER
551     USER</literal>, respectively, are used to configure these settings.
552     Such per-database settings override anything received from the postmaster
553     or the configuration file, and in turn are overridden by per-user
554     settings.
555    </para>
556
557    <sect2 id="catalog-pg-settings">
558     <title>pg_settings</title>
559   
560     <para>
561      The <structname>pg_settings</structname> virtual table allows display and update
562      of current session run-time parameters. There is one entry for each of the 
563      available parameters provided by <command>SHOW ALL</command>. But it is
564      in a form that allows it to be joined with other relations and have a
565      selection criteria applied.
566     </para>
567   
568     <para>
569      An <command>UPDATE</command> performed on <structname>pg_settings</structname>
570      is equivalent to executing the <command>SET</command> command on that named
571      parameter. The change only affects the value used by the current session. If
572      an <command>UPDATE</command> is issued within a transaction that is later
573      aborted, the effects of the <command>UPDATE</command> command disappear when
574      the transaction is rolled back. Once the surrounding transaction is
575      committed, the effects will persist until the end of the session, unless
576      overridden by another <command>UPDATE</command> or <command>SET</command>.
577     </para>
578   
579     <table>
580     <title>pg_settings Columns</title>
581   
582     <tgroup cols=3>
583      <thead>
584       <row>
585        <entry>Name</entry>
586        <entry>Type</entry>
587        <entry>Description</entry>
588       </row>
589      </thead>
590  
591      <tbody>
592       <row>
593        <entry><literal>name</literal></entry>
594        <entry><type>text</type></entry>
595        <entry>The name of a current session run-time parameter</entry>
596       </row>
597  
598       <row>
599        <entry><literal>setting</literal></entry>
600        <entry><type>text</type></entry>
601        <entry>The value of a current session run-time parameter</entry>
602       </row>
603      </tbody>
604     </tgroup>
605     </table>
606
607    </sect2>
608
609    <sect2 id="runtime-config-optimizer">
610     <title>Planner and Optimizer Tuning</title>
611
612    <para>
613     <variablelist>
614      <varlistentry>
615       <term><varname>CPU_INDEX_TUPLE_COST</varname> (<type>floating point</type>)</term>
616       <listitem>
617        <para>
618         Sets the query optimizer's estimate of the cost of processing
619         each index tuple during an index scan. This is measured as a
620         fraction of the cost of a sequential page fetch.
621        </para>
622       </listitem>
623      </varlistentry>
624     
625      <varlistentry>
626       <term><varname>CPU_OPERATOR_COST</varname> (<type>floating point</type>)</term>
627       <listitem>
628        <para>
629         Sets the optimizer's estimate of the cost of processing each
630         operator in a <literal>WHERE</> clause. This is measured as a fraction of
631         the cost of a sequential page fetch.
632        </para>
633       </listitem>
634      </varlistentry>
635     
636      <varlistentry>
637       <term><varname>CPU_TUPLE_COST</varname> (<type>floating point</type>)</term>
638       <listitem>
639        <para>
640         Sets the query optimizer's estimate of the cost of processing
641         each tuple during a query. This is measured as a fraction of
642         the cost of a sequential page fetch.
643        </para>
644       </listitem>
645      </varlistentry>
646     
647      <varlistentry>
648       <term><varname>DEFAULT_STATISTICS_TARGET</varname> (<type>integer</type>)</term>
649       <listitem>
650        <para>
651         Sets the default statistics target for table columns that have not
652         had a column-specific target set via <command>ALTER TABLE SET
653         STATISTICS</>.  Larger values increase the time needed to do
654         <command>ANALYZE</>, but may improve the quality of the planner's
655         estimates. The default value is 10.
656        </para>
657       </listitem>
658      </varlistentry>
659     
660      <varlistentry>
661       <term><varname>EFFECTIVE_CACHE_SIZE</varname> (<type>floating point</type>)</term>
662       <listitem>
663        <para>
664         Sets the optimizer's assumption about the effective size of the
665         disk cache (that is, the portion of the kernel's disk cache that
666         will be used for <productname>PostgreSQL</productname> data
667         files). This is measured in disk pages, which are normally 8 kB
668         each.
669        </para>
670       </listitem>
671      </varlistentry>
672
673      <varlistentry>
674       <term><varname>ENABLE_HASHAGG</varname> (<type>boolean</type>)</term>
675       <listitem>
676        <para>
677         Enables or disables the query planner's use of hashed aggregation
678         plan types. The default is on. This is used for debugging the query
679         planner.
680        </para>
681       </listitem>
682      </varlistentry>
683
684      <varlistentry>
685       <term><varname>ENABLE_HASHJOIN</varname> (<type>boolean</type>)</term>
686       <listitem>
687        <para>
688         Enables or disables the query planner's use of hash-join plan
689         types. The default is on. This is used for debugging the
690         query planner.
691        </para>
692       </listitem>
693      </varlistentry>
694
695      <varlistentry>
696       <indexterm>
697        <primary>index scan</primary>
698       </indexterm>
699
700       <term><varname>ENABLE_INDEXSCAN</varname> (<type>boolean</type>)</term>
701       <listitem>
702        <para>
703         Enables or disables the query planner's use of index-scan plan
704         types. The default is on. This is used to debugging the
705         query planner.
706        </para>
707       </listitem>
708      </varlistentry>
709
710      <varlistentry>
711       <term><varname>ENABLE_MERGEJOIN</varname> (<type>boolean</type>)</term>
712       <listitem>
713        <para>
714         Enables or disables the query planner's use of merge-join plan
715         types. The default is on. This is used for debugging the
716         query planner.
717        </para>
718       </listitem>
719      </varlistentry>
720
721      <varlistentry>
722       <term><varname>ENABLE_NESTLOOP</varname> (<type>boolean</type>)</term>
723       <listitem>
724        <para>
725         Enables or disables the query planner's use of nested-loop join
726         plans. It's not possible to suppress nested-loop joins entirely,
727         but turning this variable off discourages the planner from using
728         one if there are other methods available. The default is
729         on. This is used for debugging the query planner.
730        </para>
731       </listitem>
732      </varlistentry>
733
734      <varlistentry>
735       <indexterm>
736        <primary>sequential scan</primary>
737       </indexterm>
738
739       <term><varname>ENABLE_SEQSCAN</varname> (<type>boolean</type>)</term>
740       <listitem>
741        <para>
742         Enables or disables the query planner's use of sequential scan
743         plan types. It's not possible to suppress sequential scans
744         entirely, but turning this variable off discourages the planner
745         from using one if there are other methods available. The
746         default is on. This is used for debugging the query planner.
747        </para>
748       </listitem>
749      </varlistentry>
750
751      <varlistentry>
752       <term><varname>ENABLE_SORT</varname> (<type>boolean</type>)</term>
753       <listitem>
754        <para>
755         Enables or disables the query planner's use of explicit sort
756         steps. It's not possible to suppress explicit sorts entirely,
757         but turning this variable off discourages the planner from
758         using one if there are other methods available. The default
759         is on. This is used for debugging the query planner.
760        </para>
761       </listitem>
762      </varlistentry>
763
764      <varlistentry>
765       <term><varname>ENABLE_TIDSCAN</varname> (<type>boolean</type>)</term>
766       <listitem>
767        <para>
768         Enables or disables the query planner's use of <acronym>TID</> scan plan
769         types. The default is on. This is used for debugging the
770         query planner.
771        </para>
772       </listitem>
773      </varlistentry>
774
775      <varlistentry>
776       <indexterm>
777        <primary>genetic query optimization</primary>
778       </indexterm>
779       <indexterm>
780        <primary>GEQO</primary>
781        <see>genetic query optimization</see>
782       </indexterm>
783
784       <term><varname>GEQO</varname> (<type>boolean</type>)</term>
785       <listitem>
786        <para>
787         Enables or disables genetic query optimization, which is an
788         algorithm that attempts to do query planning without exhaustive
789         searching. This is on by default. See also the various other
790         <varname>GEQO_</varname> settings.
791        </para>
792       </listitem>
793      </varlistentry>
794
795      <varlistentry>
796       <term><varname>GEQO_EFFORT</varname> (<type>integer</type>)</term>
797       <term><varname>GEQO_GENERATIONS</varname> (<type>integer</type>)</term>
798       <term><varname>GEQO_POOL_SIZE</varname> (<type>integer</type>)</term>
799       <term><varname>GEQO_RANDOM_SEED</varname> (<type>integer</type>)</term>
800       <term><varname>GEQO_SELECTION_BIAS</varname> (<type>floating point</type>)</term>
801       <listitem>
802        <para>
803         Various tuning parameters for the genetic query optimization
804         algorithm: The pool size is the number of individuals in one
805         population. Valid values are between 128 and 1024. If it is set
806         to 0 (the default) a pool size of 2^(QS+1), where QS is the
807         number of FROM items in the query, is taken. The effort is used
808         to calculate a default for generations. Valid values are between
809         1 and 80, 40 being the default. Generations specifies the number
810         of iterations in the algorithm. The number must be a positive
811         integer. If 0 is specified then <literal>Effort *
812         Log2(PoolSize)</literal> is used. The run time of the algorithm
813         is roughly proportional to the sum of pool size and generations.
814         The selection bias is the selective pressure within the
815         population. Values can be from 1.50 to 2.00; the latter is the
816         default. The random seed can be set to get reproducible results
817         from the algorithm. If it is set to -1 then the algorithm
818         behaves non-deterministically.
819        </para>
820       </listitem>
821      </varlistentry>
822
823      <varlistentry>
824       <term><varname>GEQO_THRESHOLD</varname> (<type>integer</type>)</term>
825       <listitem>
826        <para>
827         Use genetic query optimization to plan queries with at least
828         this many <literal>FROM</> items involved. (Note that a
829         <literal>JOIN</> construct counts as only one <literal>FROM</>
830         item.) The default is 11. For simpler queries it is usually best
831         to use the deterministic, exhaustive planner. This parameter
832         also controls how hard the optimizer will try to merge subquery
833         <literal>FROM</literal> clauses into the upper query.
834        </para>
835       </listitem>
836      </varlistentry>
837
838      <varlistentry>
839       <term><varname>RANDOM_PAGE_COST</varname> (<type>floating point</type>)</term>
840       <listitem>
841        <para>
842         Sets the query optimizer's estimate of the cost of a
843         nonsequentially fetched disk page. This is measured as a
844         multiple of the cost of a sequential page fetch. A higher
845         value makes it more likely a sequential scan will be used,
846         a lower value makes it more likely an index scan will be used.
847        </para>
848       </listitem>
849      </varlistentry>
850     </variablelist>
851    </para>
852
853    <note>
854     <para>
855      Unfortunately, there is no well-defined method for determining
856      ideal values for the family of <quote>COST</quote> variables that
857      were just described. You are encouraged to experiment and share
858      your findings.
859     </para>
860    </note>
861
862    </sect2>
863
864    <sect2 id="logging">
865     <title>Logging and Debugging</title>
866
867    <para>
868     <variablelist>
869      <varlistentry>
870       <term><varname>CLIENT_MIN_MESSAGES</varname> (<type>string</type>)</term>
871       <listitem>
872        <para>
873         This controls how much message detail is written to the
874         client.  Valid values are <literal>DEBUG5</>,
875         <literal>DEBUG4</>, <literal>DEBUG3</>, <literal>DEBUG2</>,
876         <literal>DEBUG1</>, <literal>LOG</>, <literal>NOTICE</>,
877         <literal>WARNING</>, and <literal>ERROR</>.  Later values send
878         less information to the client.  The default is
879         <literal>NOTICE</>.  Note that <literal>LOG</> has a different
880         precedence here than in <literal>LOG_MIN_MESSAGES</>. 
881        </para>
882
883        <para>
884         Here is a summary of the various message types:
885         <variablelist>
886          <varlistentry>
887           <term><literal>DEBUG[1-5]</literal></term>
888           <listitem>
889            <para>
890             Provides information for use by developers.
891            </para>
892           </listitem>
893          </varlistentry>
894
895          <varlistentry>
896           <term><literal>INFO</literal></term>
897           <listitem>
898            <para>
899             Provides information implicitly requested by the user,
900             e.g., during <command>VACUUM VERBOSE</>.
901            </para>
902           </listitem>
903          </varlistentry>
904
905          <varlistentry>
906           <term><literal>NOTICE</literal></term>
907           <listitem>
908            <para>
909             Provides information that may be helpful to users, e.g.,
910             truncation of long identifiers and index creation as part
911             of primary keys.
912            </para>
913           </listitem>
914          </varlistentry>
915
916          <varlistentry>
917           <term><literal>WARNING</literal></term>
918           <listitem>
919            <para>
920             Provides warnings to the user, e.g., <command>COMMIT</>
921             outside a transaction.
922            </para>
923           </listitem>
924          </varlistentry>
925
926          <varlistentry>
927           <term><literal>ERROR</literal></term>
928           <listitem>
929            <para>
930             Reports the error that caused a transaction to abort.
931            </para>
932           </listitem>
933          </varlistentry>
934
935          <varlistentry>
936           <term><literal>LOG</literal></term>
937           <listitem>
938            <para>
939             Reports information of interest to administrators, e.g.,
940             checkpoint activity.
941            </para>
942           </listitem>
943          </varlistentry>
944
945          <varlistentry>
946           <term><literal>FATAL</literal></term>
947           <listitem>
948            <para>
949             Reports why a backend session terminated.
950            </para>
951           </listitem>
952          </varlistentry>
953
954          <varlistentry>
955           <term><literal>PANIC</literal></term>
956           <listitem>
957            <para>
958             Reports why all backend sessions restarted.
959            </para>
960           </listitem>
961          </varlistentry>
962         </variablelist>
963        </para>
964       </listitem>
965      </varlistentry>
966
967      <varlistentry>
968       <term><varname>DEBUG_ASSERTIONS</varname> (<type>boolean</type>)</term>
969       <listitem>
970        <para>
971         Turns on various assertion checks. This is a debugging aid. If
972         you are experiencing strange problems or crashes you might want
973         to turn this on, as it might expose programming mistakes. To use
974         this option, the macro <literal>USE_ASSERT_CHECKING</literal>
975         must be defined when <productname>PostgreSQL</productname> is
976         built (accomplished by the <command>configure</command> option
977         <option>--enable-cassert</option>). Note that
978         <literal>DEBUG_ASSERTIONS</literal> defaults to on if
979         <productname>PostgreSQL</productname> has been built with
980         assertions enabled.
981        </para>
982       </listitem>
983      </varlistentry>
984
985      <varlistentry>
986       <term><varname>DEBUG_PRINT_PARSE</varname> (<type>boolean</type>)</term>
987       <term><varname>DEBUG_PRINT_REWRITTEN</varname> (<type>boolean</type>)</term>
988       <term><varname>DEBUG_PRINT_PLAN</varname> (<type>boolean</type>)</term>
989       <term><varname>DEBUG_PRETTY_PRINT</varname> (<type>boolean</type>)</term>
990       <listitem>
991        <para>
992         These flags enable various debugging output to be sent to the
993         server log. For each executed query, print the resulting parse
994         tree, the query rewriter output, or the execution plan.
995         <option>DEBUG_PRETTY_PRINT</option> indents these displays to
996         produce a more readable but much longer output format.
997        </para>
998       </listitem>
999      </varlistentry>
1000      <varlistentry>
1001       <term><varname>EXPLAIN_PRETTY_PRINT</varname> (<type>boolean</type>)</term>
1002       <listitem>
1003        <para>
1004         Determines whether <command>EXPLAIN VERBOSE</> uses the indented
1005         or non-indented format for displaying detailed query-tree dumps.
1006        </para>
1007       </listitem>
1008      </varlistentry>
1009
1010      <varlistentry>
1011       <term><varname>LOG_HOSTNAME</varname> (<type>boolean</type>)</term>
1012       <listitem>
1013        <para>
1014         By default, connection logs only show the IP address of the
1015         connecting host. If you want it to show the host name you can
1016         turn this on, but depending on your host name resolution setup
1017         it might impose a non-negligible performance penalty. This
1018         option can only be set at server start.
1019        </para>
1020       </listitem>
1021      </varlistentry>
1022
1023      <varlistentry>
1024       <term><varname>LOG_CONNECTIONS</varname> (<type>boolean</type>)</term>
1025       <listitem>
1026        <para>
1027         This outputs a line to the server logs detailing each successful
1028         connection. This is off by default, although it is probably very
1029         useful. This option can only be set at server start or in the
1030         <filename>postgresql.conf</filename> configuration file.
1031        </para>
1032       </listitem>
1033      </varlistentry>
1034
1035      <varlistentry>
1036       <term><varname>LOG_DURATION</varname> (<type>boolean</type>)</term>
1037       <listitem>
1038        <para>
1039         Causes the duration of every completed statement to be logged.
1040         To use this option, enable <varname>LOG_STATEMENT</> and
1041         <varname>LOG_PID</> so you can link the statement to the
1042         duration using the process ID.
1043        </para>
1044       </listitem>
1045      </varlistentry>
1046
1047      <varlistentry>
1048       <term><varname>LOG_MIN_ERROR_STATEMENT</varname> (<type>string</type>)</term>
1049       <listitem>
1050        <para>
1051         This controls for which message levels the SQL statement
1052         causing that message is to be recorded in the server log. All
1053         statements causing a message of the level of the setting or
1054         higher are logged. The default is <literal>PANIC</literal>
1055         (effectively turning this feature off). Valid values are
1056         <literal>DEBUG5</literal>, <literal>DEBUG4</literal>,
1057         <literal>DEBUG3</literal>, <literal>DEBUG2</literal>,
1058         <literal>DEBUG1</literal>, <literal>INFO</literal>,
1059         <literal>NOTICE</literal>, <literal>WARNING</literal>,
1060         <literal>ERROR</literal>, <literal>FATAL</literal>, and
1061         <literal>PANIC</literal>.  For example, if you set this to
1062         <literal>ERROR</literal> then all SQL statements causing
1063         errors, fatal errors, or panics will be logged.
1064        </para>
1065
1066        <para>
1067         It is recommended you enable <varname>LOG_PID</varname> as well
1068         so you can more easily match the error statement with the error
1069         message.
1070        </para>
1071       </listitem>
1072      </varlistentry>
1073
1074      <varlistentry>
1075       <term><varname>LOG_MIN_MESSAGES</varname> (<type>string</type>)</term>
1076       <listitem>
1077        <para>
1078         This controls how much message detail is written to the server
1079         logs.  Valid values are <literal>DEBUG5</>,
1080         <literal>DEBUG4</>, <literal>DEBUG3</>, <literal>DEBUG2</>,
1081         <literal>DEBUG1</>, <literal>INFO</>, <literal>NOTICE</>,
1082         <literal>WARNING</>, <literal>ERROR</>, <literal>LOG</>,
1083         <literal>FATAL</>, and <literal>PANIC</>. Later values send
1084         less detail to the logs.  The default is <literal>NOTICE</>.
1085         Note that <literal>LOG</> has a different precedence here than
1086         in <literal>CLIENT_MIN_MESSAGES</>.  Also see that section 
1087         for an explanation of the various values.
1088        </para>
1089
1090       </listitem>
1091      </varlistentry>
1092
1093      <varlistentry>
1094       <term><varname>LOG_PID</varname> (<type>boolean</type>)</term>
1095       <listitem>
1096        <para>
1097         Prefixes each server message in the log file with the process ID of
1098         the backend process. This is useful to sort out which messages
1099         pertain to which connection. The default is off.  This parameter
1100         does not affect messages logged via <application>syslog</>, which always contain
1101         the process ID.
1102        </para>
1103       </listitem>
1104      </varlistentry>
1105
1106      <varlistentry>
1107       <term><varname>LOG_STATEMENT</varname> (<type>boolean</type>)</term>
1108       <listitem>
1109        <para>
1110         Causes each SQL statement to be logged.
1111        </para>
1112       </listitem>
1113      </varlistentry>
1114
1115      <varlistentry>
1116       <term><varname>LOG_TIMESTAMP</varname> (<type>boolean</type>)</term>
1117       <listitem>
1118        <para>
1119         Prefixes each server log message with a time stamp. The default
1120         is off.
1121        </para>
1122       </listitem>
1123      </varlistentry>
1124
1125      <varlistentry>
1126       <term><varname>LOG_STATEMENT_STATS</varname> (<type>boolean</type>)</term>
1127       <term><varname>LOG_PARSER_STATS</varname> (<type>boolean</type>)</term>
1128       <term><varname>LOG_PLANNER_STATS</varname> (<type>boolean</type>)</term>
1129       <term><varname>LOG_EXECUTOR_STATS</varname> (<type>boolean</type>)</term>
1130       <listitem>
1131        <para>
1132         For each query, write performance statistics of the respective
1133         module to the server log. This is a crude profiling
1134         instrument.
1135        </para>
1136       </listitem>
1137      </varlistentry>
1138
1139      <varlistentry>
1140       <term><varname>LOG_SOURCE_PORT</varname> (<type>boolean</type>)</term>
1141       <listitem>
1142        <para>
1143         Shows the outgoing port number of the connecting host in the
1144         connection log messages. You could trace back the port number
1145         to find out what user initiated the connection. Other than
1146         that, it's pretty useless and therefore off by default. This
1147         option can only be set at server start.
1148        </para>
1149       </listitem>
1150      </varlistentry>
1151
1152      <varlistentry>
1153       <term><varname>STATS_COMMAND_STRING</varname> (<type>boolean</type>)</term>
1154       <term><varname>STATS_BLOCK_LEVEL</varname> (<type>boolean</type>)</term>
1155       <term><varname>STATS_ROW_LEVEL</varname> (<type>boolean</type>)</term>
1156       <listitem>
1157        <para>
1158         These flags determine what information backends send to the statistics
1159         collector process: current commands, block-level activity statistics,
1160         or row-level activity statistics.  All default to off.  Enabling
1161         statistics collection costs a small amount of time per query, but
1162         is invaluable for debugging and performance tuning.
1163        </para>
1164       </listitem>
1165      </varlistentry>
1166
1167      <varlistentry>
1168       <term><varname>STATS_RESET_ON_SERVER_START</varname> (<type>boolean</type>)</term>
1169       <listitem>
1170        <para>
1171         If on, collected statistics are zeroed out whenever the server
1172         is restarted. If off, statistics are accumulated across server
1173         restarts. The default is on. This option can only be set at
1174         server start.
1175        </para>
1176       </listitem>
1177      </varlistentry>
1178
1179      <varlistentry>
1180       <term><varname>STATS_START_COLLECTOR</varname> (<type>boolean</type>)</term>
1181       <listitem>
1182        <para>
1183         Controls whether the server should start the statistics-collection
1184         subprocess.  This is on by default, but may be turned off if you
1185         know you have no interest in collecting statistics.  This option
1186         can only be set at server start.
1187        </para>
1188       </listitem>
1189      </varlistentry>
1190
1191      <varlistentry>
1192       <term><varname>SYSLOG</varname> (<type>integer</type>)</term>
1193       <listitem>
1194        <para>
1195         <productname>PostgreSQL</productname> allows the use of
1196         <systemitem>syslog</systemitem> for logging. If this option is
1197         set to 1, messages go both to <systemitem>syslog</> and the
1198         standard output. A setting of 2 sends output only to
1199         <systemitem>syslog</>. (Some messages will still go to the
1200         standard output/error.) The default is 0, which means
1201         <systemitem>syslog</> is off. This option must be set at server
1202         start.
1203        </para>
1204       </listitem>
1205      </varlistentry>
1206
1207      <varlistentry>
1208       <term><varname>SYSLOG_FACILITY</varname> (<type>string</type>)</term>
1209        <listitem>
1210         <para>
1211           This option determines the <application>syslog</application>
1212           <quote>facility</quote> to be used when
1213           <application>syslog</application> is enabled. You may choose
1214           from <literal>LOCAL0</>, <literal>LOCAL1</>,
1215           <literal>LOCAL2</>, <literal>LOCAL3</>, <literal>LOCAL4</>,
1216           <literal>LOCAL5</>, <literal>LOCAL6</>, <literal>LOCAL7</>;
1217           the default is <literal>LOCAL0</>. See also the
1218           documentation of your system's
1219           <application>syslog</application>.
1220         </para>
1221        </listitem>
1222      </varlistentry>
1223      
1224      <varlistentry>
1225       <term><varname>SYSLOG_IDENT</varname> (<type>string</type>)</term>
1226        <listitem>
1227         <para>
1228          If logging to <application>syslog</> is enabled, this option
1229          determines the program name used to identify
1230          <productname>PostgreSQL</productname> messages in
1231          <application>syslog</application> log messages. The default is
1232          <literal>postgres</literal>.
1233         </para>
1234        </listitem>
1235       </varlistentry>
1236
1237      <varlistentry>
1238       <term><varname>TRACE_NOTIFY</varname> (<type>boolean</type>)</term>
1239       <listitem>
1240        <para>
1241         Generates a great amount of debugging output for the
1242         <command>LISTEN</command> and <command>NOTIFY</command>
1243         commands.
1244        </para>
1245       </listitem>
1246      </varlistentry>
1247     </variablelist>
1248    </para>
1249    </sect2>
1250
1251    <sect2 id="runtime-config-general">
1252     <title>General Operation</title>
1253
1254    <para>
1255     <variablelist>
1256      <varlistentry>
1257       <term><varname>AUTOCOMMIT</varname> (<type>boolean</type>)</term>
1258       <indexterm><primary>autocommit</></>
1259       <listitem>
1260        <para>
1261         If set to true, <productname>PostgreSQL</productname> will
1262         automatically do a <command>COMMIT</> after each successful command
1263         that is not inside an explicit transaction block (that is, unless a
1264         <command>BEGIN</> with no matching <command>COMMIT</> has been
1265         given).
1266         If set to false, <productname>PostgreSQL</productname> will
1267         commit only upon receiving an explicit
1268         <command>COMMIT</> command. This mode can also be thought of as
1269         implicitly issuing <command>BEGIN</> whenever a command is
1270         received that is not already inside a transaction block. The
1271         default is true, for compatibility with historical
1272         <productname>PostgreSQL</productname> behavior. However, for
1273         maximum compatibility with the SQL specification, set it to
1274         false.
1275        </para>
1276
1277        <note>
1278         <para>
1279          Even with <varname>autocommit</> set to false, <command>SET</>,
1280          <command>SHOW</>, and <command>RESET</> do not start new
1281          transaction blocks. They are run in their own transactions.
1282          Once another command is issued, a transaction block
1283          begins and any <command>SET</>, <command>SHOW</>, or
1284          <command>RESET</> commands are considered to be part of the
1285          transaction, i.e., they are committed or rolled back depending
1286          on the completion status of the transaction. To execute a
1287          <command>SET</>, <command>SHOW</>, or <command>RESET</>
1288          command at the start of a transaction block, use <command>BEGIN</>
1289          first.
1290         </para>
1291        </note>
1292
1293        <note>
1294         <para>
1295          As of <productname>PostgreSQL</productname> 7.3, setting
1296          <varname>autocommit</> to false is not well-supported.
1297          This is a new feature and is not yet handled by all client
1298          libraries and applications.  Before making it the default
1299          setting in your installation, test carefully.
1300         </para>
1301        </note>
1302
1303       </listitem>
1304      </varlistentry>
1305
1306      <varlistentry>
1307       <term><varname>AUSTRALIAN_TIMEZONES</varname> (<type>boolean</type>)</term>
1308       <indexterm><primary>Australian time zones</></>
1309       <listitem>
1310        <para>
1311         If set to true, <literal>CST</literal>, <literal>EST</literal>,
1312         and <literal>SAT</literal> are interpreted as Australian
1313         time zones rather than as North American Central/Eastern
1314         time zones and Saturday. The default is false.
1315        </para>
1316       </listitem>
1317      </varlistentry>
1318
1319      <varlistentry>
1320       <term><varname>AUTHENTICATION_TIMEOUT</varname> (<type>integer</type>)</term>
1321       <indexterm><primary>timeout</><secondary>authentication</></indexterm>
1322       <listitem>
1323        <para>
1324         Maximum time to complete client authentication, in seconds. If a
1325         would-be client has not completed the authentication protocol in
1326         this much time, the server breaks the connection. This prevents
1327         hung clients from occupying a connection indefinitely. This
1328         option can only be set at server start or in the
1329         <filename>postgresql.conf</filename> file.
1330        </para>
1331       </listitem>
1332      </varlistentry>
1333
1334      <varlistentry>
1335       <term><varname>CLIENT_ENCODING</varname> (<type>string</type>)</term>
1336       <indexterm><primary>character set encoding</></>
1337       <listitem>
1338        <para>
1339         Sets the client-side encoding for multibyte character sets.
1340         The default is to use the database encoding.
1341        </para>
1342       </listitem>
1343      </varlistentry>
1344
1345      <varlistentry>
1346       <term><varname>DATESTYLE</varname> (<type>string</type>)</term>
1347       <indexterm><primary>date style</></>
1348       <listitem>
1349        <para>
1350         Sets the display format for dates, as well as the rules for
1351         interpreting ambiguous input dates.
1352         The default is <literal>ISO, US</>.
1353        </para>
1354       </listitem>
1355      </varlistentry>
1356
1357      <varlistentry>
1358       <term><varname>DB_USER_NAMESPACE</varname> (<type>boolean</type>)</term>
1359       <listitem>
1360        <para>
1361         This allows per-database user names.  It is off by default.
1362        </para>
1363
1364        <para>
1365         If this is on, create users as <literal> username@dbname</>.
1366         When <literal>username</> is passed by a connecting client,
1367         <literal>@</> and the database name is appended to the user
1368         name and that database-specific user name is looked up by the
1369         server. Note that when you create users with names containing
1370         <literal>@</> within the SQL environment, you will need to
1371         quote the user name.
1372        </para>
1373
1374        <para>
1375         With this option enabled, you can still create ordinary global
1376         users.  Simply append <literal>@</> when specifying the user
1377         name in the client.  The <literal>@</> will be stripped off
1378         before the user name is looked up by the server.
1379        </para>
1380
1381        <note>
1382         <para>
1383          This feature is intended as a temporary measure until a
1384          complete solution is found.  At that time, this option will
1385          be removed.
1386         </para>
1387        </note>
1388       </listitem>
1389      </varlistentry>
1390
1391      <varlistentry>
1392       <indexterm>
1393        <primary>deadlock</primary>
1394        <secondary>timeout</secondary>
1395       </indexterm>
1396       <indexterm>
1397        <primary>timeout</primary>
1398        <secondary>deadlock</secondary>
1399       </indexterm>
1400
1401       <term><varname>DEADLOCK_TIMEOUT</varname> (<type>integer</type>)</term>
1402       <listitem>
1403        <para>
1404         This is the amount of time, in milliseconds, to wait on a lock
1405         before checking to see if there is a deadlock condition. The
1406         check for deadlock is relatively slow, so the server doesn't run
1407         it every time it waits for a lock. We (optimistically?) assume
1408         that deadlocks are not common in production applications and
1409         just wait on the lock for a while before starting check for a
1410         deadlock. Increasing this value reduces the amount of time
1411         wasted in needless deadlock checks, but slows down reporting of
1412         real deadlock errors. The default is 1000 (i.e., one second),
1413         which is probably about the smallest value you would want in
1414         practice. On a heavily loaded server you might want to raise it.
1415         Ideally the setting should exceed your typical transaction time,
1416         so as to improve the odds that the lock will be released before
1417         the waiter decides to check for deadlock. This option can only
1418         be set at server start.
1419        </para>
1420       </listitem>
1421      </varlistentry>
1422
1423      <varlistentry>
1424       <indexterm>
1425        <primary>transaction isolation level</primary>
1426       </indexterm>
1427
1428       <term><varname>DEFAULT_TRANSACTION_ISOLATION</varname> (<type>string</type>)</term>
1429       <listitem>
1430        <para>
1431         Each SQL transaction has an isolation level, which can be either
1432         <quote>read committed</quote> or <quote>serializable</quote>.
1433         This parameter controls the default isolation level of each new
1434         transaction. The default is <quote>read committed</quote>.
1435        </para>
1436
1437        <para>
1438         Consult the &cite-user; and
1439         the command <command>SET TRANSACTION</command> for more
1440         information.
1441        </para>
1442       </listitem>
1443      </varlistentry>
1444
1445      <varlistentry>
1446       <term><varname>DYNAMIC_LIBRARY_PATH</varname> (<type>string</type>)</term>
1447       <indexterm><primary>dynamic_library_path</></>
1448       <indexterm><primary>dynamic loading</></>
1449       <listitem>
1450        <para>
1451         If a dynamically loadable module needs to be opened and the
1452         specified name does not have a directory component (i.e. the
1453         name does not contain a slash), the system will search this
1454         path for the specified file.  (The name that is used is the
1455         name specified in the <command>CREATE FUNCTION</command> or
1456         <command>LOAD</command> command.)
1457        </para>
1458
1459        <para>
1460         The value for dynamic_library_path has to be a colon-separated
1461         list of absolute directory names. If a directory name starts
1462         with the special value <literal>$libdir</literal>, the
1463         compiled-in <productname>PostgreSQL</productname> package
1464         library directory is substituted. This where the modules
1465         provided by the <productname>PostgreSQL</productname>
1466         distribution are installed. (Use <literal>pg_config
1467         --pkglibdir</literal> to print the name of this directory.) For
1468         example:
1469 <programlisting>
1470 dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
1471 </programlisting>
1472        </para>
1473
1474        <para>
1475         The default value for this parameter is
1476         <literal>'$libdir'</literal>. If the value is set to an empty
1477         string, the automatic path search is turned off.
1478        </para>
1479
1480        <para>
1481         This parameter can be changed at run time by superusers, but a
1482         setting done that way will only persist until the end of the
1483         client connection, so this method should be reserved for
1484         development purposes. The recommended way to set this parameter
1485         is in the <filename>postgresql.conf</filename> configuration
1486         file.
1487        </para>
1488       </listitem>
1489      </varlistentry>
1490
1491      <varlistentry>
1492       <indexterm>
1493        <primary>significant digits</primary>
1494       </indexterm>
1495       <indexterm>
1496        <primary>display</primary>
1497        <secondary>of float numbers</secondary>
1498       </indexterm>
1499
1500       <term><varname>EXTRA_FLOAT_DIGITS</varname> (<type>integer</type>)</term>
1501       <listitem>
1502        <para>
1503         This parameter adjusts the number of digits displayed for
1504         floating-point values, including <type>float4</>, <type>float8</>,
1505         and geometric datatypes.  The parameter value is added to the
1506         standard number of digits (<literal>FLT_DIG</> or <literal>DBL_DIG</>
1507         as appropriate).  The value can be set as high as 2, to include
1508         partially-significant digits; this is especially useful for dumping
1509         float data that needs to be restored exactly.  Or it can be set
1510         negative to suppress unwanted digits.
1511        </para>
1512       </listitem>
1513      </varlistentry>
1514
1515      <varlistentry>
1516       <term><varname>KRB_SERVER_KEYFILE</varname> (<type>string</type>)</term>
1517       <listitem>
1518        <para>
1519         Sets the location of the Kerberos server key file. See
1520         <xref linkend="kerberos-auth"> for details.
1521        </para>
1522       </listitem>
1523      </varlistentry>
1524
1525      <varlistentry>
1526       <indexterm>
1527        <primary>fsync</primary>
1528       </indexterm>
1529
1530       <term><varname>FSYNC</varname> (<type>boolean</type>)</term>
1531       <listitem>
1532        <para>
1533         If this option is on, the <productname>PostgreSQL</> backend
1534         will use the <function>fsync()</> system call in several places
1535         to make sure that updates are physically written to disk. This
1536         insures that a database installation will recover to a
1537         consistent state after an operating system or hardware crash.
1538         (Crashes of the database server itself are <emphasis>not</>
1539         related to this.)
1540        </para>
1541
1542        <para>
1543         However, this operation does slow down
1544         <productname>PostgreSQL</> because at transaction commit it has
1545         wait for the operating system to flush the write-ahead log.
1546         Without <function>fsync</>, the operating system is allowed to
1547         do its best in buffering, sorting, and delaying writes, which
1548         can considerably increase performance. However, if the system
1549         crashes, the results of the last few committed transactions may
1550         be lost in part or whole. In the worst case, unrecoverable data
1551         corruption may occur.
1552        </para>
1553
1554        <para>
1555         For the above reasons, some administrators always leave it off,
1556         some turn it off only for bulk loads, where there is a clear
1557         restart point if something goes wrong, and some leave it on just
1558         to be on the safe side. Because it is always safe, the default
1559         is on. If you trust your operating system, your hardware, and
1560         your utility company (or better your UPS), you might want to
1561         disable <varname>fsync</varname>.
1562        </para>
1563
1564        <para>
1565         It should be noted that the performance penalty of doing
1566         <function>fsync</>s is considerably less in
1567         <productname>PostgreSQL</> version 7.1 and later. If you
1568         previously suppressed <function>fsync</>s for performance
1569         reasons, you may wish to reconsider your choice.
1570        </para>
1571
1572        <para>
1573         This option can only be set at server start or in the
1574         <filename>postgresql.conf</filename> file.
1575        </para>
1576       </listitem>
1577      </varlistentry>
1578
1579      <varlistentry>
1580       <term><varname>LC_MESSAGES</varname> (<type>string</type>)</term>
1581       <listitem>
1582        <para>
1583         Sets the language in which messages are displayed.  Acceptable
1584         values are system-dependent; see <xref linkend="locale"> for
1585         more information.  If this variable is set to the empty string
1586         (which is the default) then the value is inherited from the
1587         execution environment of the server in a system-dependent way.
1588        </para>
1589
1590        <para>
1591         On some systems, this locale category does not exist.  Setting
1592         this variable will still work, but there will be no effect.
1593         Also, there is a chance that no translated messages for the
1594         desired language exist.  In that case you will continue to see
1595         the English messages.
1596        </para>
1597       </listitem>
1598      </varlistentry>
1599
1600      <varlistentry>
1601       <term><varname>LC_MONETARY</varname> (<type>string</type>)</term>
1602       <listitem>
1603        <para>
1604         Sets the locale to use for formatting monetary amounts, for
1605         example with the <function>to_char()</function> family of
1606         functions.  Acceptable values are system-dependent; see <xref
1607         linkend="locale"> for more information.  If this variable is
1608         set to the empty string (which is the default) then the value
1609         is inherited from the execution environment of the server in a
1610         system-dependent way.
1611        </para>
1612       </listitem>
1613      </varlistentry>
1614
1615      <varlistentry>
1616       <term><varname>LC_NUMERIC</varname> (<type>string</type>)</term>
1617       <listitem>
1618        <para>
1619         Sets the locale to use for formatting numbers, for example
1620         with the <function>to_char()</function> family of
1621         functions. Acceptable values are system-dependent; see <xref
1622         linkend="locale"> for more information.  If this variable is
1623         set to the empty string (which is the default) then the value
1624         is inherited from the execution environment of the server in a
1625         system-dependent way.
1626        </para>
1627       </listitem>
1628      </varlistentry>
1629
1630      <varlistentry>
1631       <term><varname>LC_TIME</varname> (<type>string</type>)</term>
1632       <listitem>
1633        <para>
1634         Sets the locale to use for formatting date and time values.
1635         (Currently, this setting does nothing, but it may in the
1636         future.)  Acceptable values are system-dependent; see <xref
1637         linkend="locale"> for more information.  If this variable is
1638         set to the empty string (which is the default) then the value
1639         is inherited from the execution environment of the server in a
1640         system-dependent way.
1641        </para>
1642       </listitem>
1643      </varlistentry>
1644
1645      <varlistentry>
1646       <term><varname>MAX_CONNECTIONS</varname> (<type>integer</type>)</term>
1647       <listitem>
1648        <para>
1649         Determines the maximum number of concurrent connections to the
1650         database server. The default is 32 (unless altered while
1651         building the server). This parameter can only be set at server
1652         start.
1653        </para>
1654       </listitem>
1655      </varlistentry>
1656
1657      <varlistentry>
1658       <term><varname>MAX_EXPR_DEPTH</varname> (<type>integer</type>)</term>
1659       <listitem>
1660        <para>
1661         Sets the maximum expression nesting depth of the parser. The
1662         default value is high enough for any normal query, but you can
1663         raise it if needed. (But if you raise it too high, you run
1664         the risk of backend crashes due to stack overflow.)
1665        </para>
1666       </listitem>
1667      </varlistentry>
1668
1669      <varlistentry>
1670       <term><varname>MAX_FILES_PER_PROCESS</varname> (<type>integer</type>)</term>
1671       <listitem>
1672        <para>
1673         Sets the maximum number of simultaneously open files in each
1674         server subprocess. The default is 1000. The limit actually used
1675         by the code is the smaller of this setting and the result of
1676         <literal>sysconf(_SC_OPEN_MAX)</literal>. Therefore, on systems
1677         where <function>sysconf</> returns a reasonable limit, you don't
1678         need to worry about this setting. But on some platforms
1679         (notably, most BSD systems), <function>sysconf</> returns a
1680         value that is much larger than the system can really support
1681         when a large number of processes all try to open that many
1682         files. If you find yourself seeing <quote>Too many open files</>
1683         failures, try reducing this setting. This option can only be set
1684         at server start or in the <filename>postgresql.conf</filename>
1685         configuration file; if changed in the configuration file, it
1686         only affects subsequently-started server subprocesses.
1687        </para>
1688       </listitem>
1689      </varlistentry>
1690
1691      <varlistentry>
1692       <term><varname>MAX_FSM_RELATIONS</varname> (<type>integer</type>)</term>
1693       <listitem>
1694        <para>
1695         Sets the maximum number of relations (tables) for which free
1696         space will be tracked in the shared free-space map. The default
1697         is 100. This option can only be set at server start.
1698        </para>
1699       </listitem>
1700      </varlistentry>
1701
1702      <varlistentry>
1703       <term><varname>MAX_FSM_PAGES</varname> (<type>integer</type>)</term>
1704       <listitem>
1705        <para>
1706         Sets the maximum number of disk pages for which free space will
1707         be tracked in the shared free-space map. The default is 10000.
1708         This option can only be set at server start.
1709        </para>
1710       </listitem>
1711      </varlistentry>
1712
1713      <varlistentry>
1714       <term><varname>MAX_LOCKS_PER_TRANSACTION</varname> (<type>integer</type>)</term>
1715       <listitem>
1716        <para>
1717         The shared lock table is sized on the assumption that at most
1718         <varname>max_locks_per_transaction</> *
1719         <varname>max_connections</varname> distinct objects will need to
1720         be locked at any one time. The default, 64, which has historically
1721         proven sufficient, but you might need to raise this value if you
1722         have clients that touch many different tables in a single
1723         transaction. This option can only be set at server start.
1724        </para>
1725       </listitem>
1726      </varlistentry>
1727
1728      <varlistentry>
1729       <term><varname>PASSWORD_ENCRYPTION</varname> (<type>boolean</type>)</term>
1730       <listitem>
1731        <para>
1732         When a password is specified in <command>CREATE USER</> or
1733         <command>ALTER USER</> without writing either <literal>ENCRYPTED</> or
1734         <literal>UNENCRYPTED</>, this flag determines whether the password is to be
1735         encrypted. The default is on (encrypt the password).
1736        </para>
1737       </listitem>
1738      </varlistentry>
1739
1740      <varlistentry>
1741       <term><varname>PORT</varname> (<type>integer</type>)</term>
1742       <indexterm><primary>port</></>
1743       <listitem>
1744        <para>
1745         The TCP port the server listens on; 5432 by default. This
1746         option can only be set at server start.
1747        </para>
1748       </listitem>
1749      </varlistentry>
1750
1751      <varlistentry>
1752       <term><varname>SEARCH_PATH</varname> (<type>string</type>)</term>
1753       <indexterm><primary>search_path</></>
1754       <indexterm><primary>namespaces</></>
1755       <listitem>
1756        <para>
1757         This variable specifies the order in which schemas are searched
1758         when an object (table, data type, function, etc.) is referenced by a
1759         simple name with no schema component.  When there are objects of
1760         identical names in different schemas, the one found first
1761         in the search path is used.  An object that is not in any of the
1762         schemas in the search path can only be referenced by specifying
1763         its containing schema with a qualified (dotted) name.
1764        </para>
1765
1766        <para>
1767         The value for <varname>search_path</varname> has to be a comma-separated
1768         list of schema names.  If one of the list items is
1769         the special value <literal>$user</literal>, then the schema
1770         having the same name as the <function>SESSION_USER</> is substituted, if there
1771         is such a schema.  (If not, <literal>$user</literal> is ignored.)
1772        </para>
1773
1774        <para>
1775         The system catalog schema, <literal>pg_catalog</>, is always
1776         searched, whether it is mentioned in the path or not.  If it is
1777         mentioned in the path then it will be searched in the specified
1778         order.  If <literal>pg_catalog</> is not in the path then it will
1779         be searched <emphasis>before</> searching any of the path items.
1780         It should also be noted that the temporary-table schema,
1781         <literal>pg_temp_<replaceable>nnn</></>, is implicitly searched before any of
1782         these.
1783        </para>
1784
1785        <para>
1786         When objects are created without specifying a particular target
1787         schema, they will be placed in the first schema listed
1788         in the search path.  An error is reported if the search path is
1789         empty.
1790        </para>
1791
1792        <para>
1793         The default value for this parameter is
1794         <literal>'$user, public'</literal> (where the second part will be
1795         ignored if there is no schema named <literal>public</>).
1796         This supports shared use of a database (where no users
1797         have private schemas, and all share use of <literal>public</>),
1798         private per-user schemas, and combinations of these.  Other
1799         effects can be obtained by altering the default search path
1800         setting, either globally or per-user.
1801        </para>
1802
1803        <para>
1804          <indexterm>
1805           <primary>schemas</primary>
1806           <secondary>current schema</secondary>
1807          </indexterm>
1808         The current effective value of the search path can be examined
1809         via the SQL function <function>current_schemas()</>.  This is not
1810         quite the same as examining the value of
1811         <varname>search_path</varname>, since <function>current_schemas()</>
1812         shows how the requests appearing in <varname>search_path</varname>
1813         were resolved.
1814        </para>
1815
1816        <para>
1817         For more information on schema handling, see the &cite-user;.
1818        </para>
1819       </listitem>
1820      </varlistentry>
1821
1822      <varlistentry>
1823       <term><varname>STATEMENT_TIMEOUT</varname> (<type>integer</type>)</term>
1824       <listitem>
1825        <para>
1826         Aborts any statement that takes over the specified number of
1827         milliseconds.  A value of zero turns off the timer.
1828        </para>
1829       </listitem>
1830      </varlistentry>
1831
1832      <varlistentry>
1833       <term><varname>SHARED_BUFFERS</varname> (<type>integer</type>)</term>
1834       <listitem>
1835        <para>
1836         Sets the number of shared memory buffers used by the database
1837         server. The default is 64. Each buffer is typically 8192 bytes.
1838         This option can only be set at server start.
1839        </para>
1840       </listitem>
1841      </varlistentry>
1842
1843      <varlistentry>
1844       <term><varname>SILENT_MODE</varname> (<type>bool</type>)</term>
1845       <listitem>
1846        <para>
1847         Runs the server silently. If this option is set, the server
1848         will automatically run in background and any controlling ttys
1849         are disassociated, thus no messages are written to standard
1850         output or standard error (same effect as <command>postmaster</>'s <option>-S</option>
1851         option). Unless some logging system such as
1852         <application>syslog</> is enabled, using this option is
1853         discouraged since it makes it impossible to see error messages.
1854        </para>
1855       </listitem>
1856      </varlistentry>
1857
1858      <varlistentry>
1859       <term><varname>SORT_MEM</varname> (<type>integer</type>)</term>
1860       <listitem>
1861        <para>
1862         Specifies the amount of memory to be used by internal sorts and
1863         hashes before switching to temporary disk files. The value is
1864         specified in kilobytes, and defaults to 1024 kilobytes (1 MB).
1865         Note that for a complex query, several sorts might be running in
1866         parallel, and each one will be allowed to use as much memory as
1867         this value specifies before it starts to put data into temporary
1868         files. Also, each running backend could be doing one or more
1869         sorts simultaneously, so the total memory used could be many
1870         times the value of <varname>SORT_MEM</varname>. Sorts are used
1871         by <literal>ORDER BY</>, merge joins, and <command>CREATE INDEX</>.
1872        </para>
1873       </listitem>
1874      </varlistentry>
1875
1876      <varlistentry>
1877       <term><varname>SQL_INHERITANCE</varname> (<type>bool</type>)</term>
1878       <indexterm><primary>inheritance</></>
1879       <listitem>
1880        <para>
1881         This controls the inheritance semantics, in particular whether
1882         subtables are included by various commands by default. They were
1883         not included in versions prior to 7.1. If you need the old
1884         behavior you can set this variable to off, but in the long run
1885         you are encouraged to change your applications to use the
1886         <literal>ONLY</literal> keyword to exclude subtables. See the
1887         SQL language reference and the &cite-user; for more information about inheritance.
1888        </para>
1889       </listitem>
1890      </varlistentry>
1891
1892      <varlistentry>
1893       <indexterm>
1894        <primary>SSL</primary>
1895       </indexterm>
1896
1897       <term><varname>SSL</varname> (<type>boolean</type>)</term>
1898       <listitem>
1899        <para>
1900         Enables <acronym>SSL</> connections. Please read
1901         <xref linkend="ssl-tcp"> before using this. The default
1902         is off.
1903        </para>
1904       </listitem>
1905      </varlistentry>
1906
1907      <varlistentry>
1908       <term><varname>SUPERUSER_RESERVED_CONNECTIONS</varname>
1909       (<type>integer</type>)</term>
1910       <listitem>
1911        <para>
1912         Determines the number of <quote>connection slots</quote> that
1913         are reserved for connections by <productname>PostgreSQL</>
1914         superusers.  At most <varname>max_connections</> connections can
1915         ever be active simultaneously.  Whenever the number of active
1916         concurrent connections is at least <varname>max_connections</> minus
1917         <varname>superuser_reserved_connections</varname>, new connections
1918         will be accepted only from superuser accounts.
1919        </para>
1920
1921        <para>
1922         The default value is 2. The value must be less than the value of
1923         <varname>max_connections</varname>. This parameter can only be
1924         set at server start.
1925        </para>
1926       </listitem>
1927      </varlistentry>
1928
1929      <varlistentry>
1930       <term><varname>TCPIP_SOCKET</varname> (<type>boolean</type>)</term>
1931       <listitem>
1932        <para>
1933         If this is true, then the server will accept TCP/IP connections.
1934         Otherwise only local Unix domain socket connections are
1935         accepted. It is off by default. This option can only be set at
1936         server start.
1937        </para>
1938       </listitem>
1939      </varlistentry>
1940
1941      <varlistentry>
1942       <term><varname>TIMEZONE</varname> (<type>string</type>)</term>
1943       <indexterm><primary>time zone</></>
1944       <listitem>
1945        <para>
1946         Sets the time zone for displaying and interpreting timestamps.
1947         The default is to use whatever the system environment
1948         specifies as the time zone.
1949        </para>
1950       </listitem>
1951      </varlistentry>
1952
1953      <varlistentry>
1954       <term><varname>TRANSFORM_NULL_EQUALS</varname> (<type>boolean</type>)</term>
1955       <indexterm><primary>IS NULL</></>
1956       <listitem>
1957        <para>
1958         When turned on, expressions of the form
1959         <literal><replaceable>expr</> = NULL</literal> (or <literal>NULL
1960         = <replaceable>expr</></literal>) are treated as
1961         <literal><replaceable>expr</> IS NULL</literal>, that is, they
1962         return true if <replaceable>expr</> evaluates to the null value,
1963         and false otherwise. The correct behavior of
1964         <literal><replaceable>expr</> = NULL</literal> is to always
1965         return null (unknown). Therefore this option defaults to off.
1966        </para>
1967
1968        <para>
1969         However, filtered forms in <productname>Microsoft
1970         Access</productname> generate queries that appear to use
1971         <literal><replaceable>expr</> = NULL</literal> to test for
1972         null values, so if you use that interface to access the database you
1973         might want to turn this option on.  Since expressions of the
1974         form <literal><replaceable>expr</> = NULL</literal> always
1975         return the null value (using the correct interpretation) they are not
1976         very useful and do not appear often in normal applications, so
1977         this option does little harm in practice.  But new users are
1978         frequently confused about the semantics of expressions
1979         involving null values, so this option is not on by default.
1980        </para>
1981
1982        <para>
1983         Note that this option only affects the literal <literal>=</>
1984         operator, not other comparison operators or other expressions
1985         that are computationally equivalent to some expression
1986         involving the equals operator (such as <literal>IN</literal>).
1987         Thus, this option is not a general fix for bad programming.
1988        </para>
1989
1990        <para>
1991         Refer to the &cite-user; for related information.
1992        </para>
1993       </listitem>
1994      </varlistentry>
1995
1996      <varlistentry>
1997       <term><varname>UNIX_SOCKET_DIRECTORY</varname> (<type>string</type>)</term>
1998       <listitem>
1999        <para>
2000         Specifies the directory of the Unix-domain socket on which the
2001         server is to listen for
2002         connections from client applications.  The default is normally
2003         <filename>/tmp</filename>, but can be changed at build time.
2004        </para>
2005       </listitem>
2006      </varlistentry>
2007
2008      <varlistentry>
2009       <term><varname>UNIX_SOCKET_GROUP</varname> (<type>string</type>)</term>
2010       <listitem>
2011        <para>
2012         Sets the group owner of the Unix domain socket.  (The owning
2013         user of the socket is always the user that starts the
2014         server.)  In combination with the option
2015         <option>UNIX_SOCKET_PERMISSIONS</option> this can be used as
2016         an additional access control mechanism for this socket type.
2017         By default this is the empty string, which uses the default
2018         group for the current user.  This option can only be set at
2019         server start.
2020        </para>
2021       </listitem>
2022      </varlistentry>
2023
2024      <varlistentry>
2025       <term><varname>UNIX_SOCKET_PERMISSIONS</varname> (<type>integer</type>)</term>
2026       <listitem>
2027        <para>
2028         Sets the access permissions of the Unix domain socket.  Unix
2029         domain sockets use the usual Unix file system permission set.
2030         The option value is expected to be an numeric mode
2031         specification in the form accepted by the
2032         <function>chmod</function> and <function>umask</function>
2033         system calls.  (To use the customary octal format the number
2034         must start with a <literal>0</literal> (zero).)
2035        </para>
2036
2037        <para>
2038         The default permissions are <literal>0777</literal>, meaning
2039         anyone can connect. Reasonable alternatives are
2040         <literal>0770</literal> (only user and group, see also under
2041         <option>UNIX_SOCKET_GROUP</option>) and <literal>0700</literal>
2042         (only user). (Note that actually for a Unix domain socket, only write
2043         permission matters and there is no point in setting or revoking
2044         read or execute permissions.)
2045        </para>
2046
2047        <para>
2048         This access control mechanism is independent of the one
2049         described in <xref linkend="client-authentication">.
2050        </para>
2051
2052        <para>
2053         This option can only be set at server start.
2054        </para>
2055       </listitem>
2056      </varlistentry>
2057
2058      <varlistentry>
2059       <term><varname>VACUUM_MEM</varname> (<type>integer</type>)</term>
2060       <listitem>
2061        <para>
2062         Specifies the maximum amount of memory to be used by
2063         <command>VACUUM</command> to keep track of to-be-reclaimed
2064         tuples. The value is specified in kilobytes, and defaults to
2065         8192 kilobytes. Larger settings may improve the speed of
2066         vacuuming large tables that have many deleted tuples.
2067        </para>
2068       </listitem>
2069      </varlistentry>
2070
2071      <varlistentry>
2072       <term><varname>VIRTUAL_HOST</varname> (<type>string</type>)</term>
2073       <listitem>
2074        <para>
2075         Specifies the TCP/IP host name or address on which the
2076         <application>postmaster</application> is to listen for
2077         connections from client applications. Defaults to listening on
2078         all configured addresses (including <systemitem
2079         class="systemname">localhost</>).
2080        </para>
2081       </listitem>
2082      </varlistentry>
2083
2084     </variablelist>
2085    </para>
2086    </sect2>
2087
2088    <sect2 id="runtime-config-wal">
2089     <title>WAL</title>
2090
2091    <para>
2092     See also <xref linkend="wal-configuration"> for details on WAL
2093     tuning.
2094
2095     <variablelist>
2096      <varlistentry>
2097       <term><varname>CHECKPOINT_SEGMENTS</varname> (<type>integer</type>)</term>
2098       <listitem>
2099        <para>
2100         Maximum distance between automatic WAL checkpoints, in log file
2101         segments (each segment is normally 16 megabytes).
2102         This option can only be set at server start or in the
2103         <filename>postgresql.conf</filename> file.
2104        </para>
2105       </listitem>
2106      </varlistentry>
2107
2108      <varlistentry>
2109       <term><varname>CHECKPOINT_TIMEOUT</varname> (<type>integer</type>)</term>
2110       <listitem>
2111        <para>
2112         Maximum time between automatic WAL checkpoints, in seconds.
2113         This option can only be set at server start or in the
2114         <filename>postgresql.conf</filename> file.
2115        </para>
2116       </listitem>
2117      </varlistentry>
2118
2119      <varlistentry>
2120       <term><varname>CHECKPOINT_WARNING</varname> (<type>integer</type>)</term>
2121       <listitem>
2122        <para>
2123         Send a message to the server logs if checkpoints caused by the
2124         filling of checkpoint segment files happens more frequently than
2125         this number of seconds.  Zero turns off the warning.
2126        </para>
2127       </listitem>
2128      </varlistentry>
2129
2130      <varlistentry>
2131       <term><varname>COMMIT_DELAY</varname> (<type>integer</type>)</term>
2132       <listitem>
2133        <para>
2134         Time delay between writing a commit record to the WAL buffer and
2135         flushing the buffer out to disk, in microseconds. A nonzero
2136         delay allows multiple transactions to be committed with only one
2137         <function>fsync</function> system call, if system load is high
2138         enough additional transactions may become ready to commit within
2139         the given interval. But the delay is just wasted if no other
2140         transactions become ready to commit. Therefore, the delay is
2141         only performed if at least <varname>COMMIT_SIBLINGS</varname> other transactions
2142         are active at the instant that a backend process has written its commit
2143         record.
2144        </para>
2145       </listitem>
2146      </varlistentry>
2147
2148      <varlistentry>
2149       <term><varname>COMMIT_SIBLINGS</varname> (<type>integer</type>)</term>
2150       <listitem>
2151        <para>
2152         Minimum number of concurrent open transactions to require before
2153         performing the <varname>COMMIT_DELAY</> delay. A larger value
2154         makes it more probable that at least one other transaction will
2155         become ready to commit during the delay interval.
2156        </para>
2157       </listitem>
2158      </varlistentry>
2159
2160      <varlistentry>
2161       <term><varname>WAL_BUFFERS</varname> (<type>integer</type>)</term>
2162       <listitem>
2163        <para>
2164         Number of disk-page buffers in shared memory for WAL logging.
2165         This option can only be set at server start.
2166        </para>
2167       </listitem>
2168      </varlistentry>
2169
2170      <varlistentry>
2171       <term><varname>WAL_DEBUG</varname> (<type>integer</type>)</term>
2172       <listitem>
2173        <para>
2174         If nonzero, turn on WAL-related debugging output on standard
2175         error.
2176        </para>
2177       </listitem>
2178      </varlistentry>
2179
2180      <varlistentry>
2181       <term><varname>WAL_SYNC_METHOD</varname> (<type>string</type>)</term>
2182       <listitem>
2183        <para>
2184         Method used for forcing WAL updates out to disk.  Possible
2185         values are
2186         <literal>FSYNC</> (call <function>fsync()</> at each commit),
2187         <literal>FDATASYNC</> (call <function>fdatasync()</> at each commit),
2188         <literal>OPEN_SYNC</> (write WAL files with <function>open()</> option <symbol>O_SYNC</>), or
2189         <literal>OPEN_DATASYNC</> (write WAL files with <function>open()</> option <symbol>O_DSYNC</>).
2190         Not all of these choices are available on all platforms.
2191         This option can only be set at server start or in the
2192         <filename>postgresql.conf</filename> file.
2193        </para>
2194       </listitem>
2195      </varlistentry>
2196     </variablelist>
2197     </para>
2198    </sect2>
2199
2200
2201   <sect2 id="runtime-config-short">
2202    <title>Short Options</title>
2203
2204    <para>
2205     For convenience there are also single letter option switches
2206     available for many parameters. They are described in <xref
2207     linkend="runtime-config-short-table">.
2208    </para>
2209
2210     <table id="runtime-config-short-table">
2211      <title>Short option key</title>
2212      <tgroup cols="2">
2213       <thead>
2214        <row>
2215         <entry>Short option</entry>
2216         <entry>Equivalent</entry>
2217        </row>
2218       </thead>
2219
2220       <tbody>
2221        <row>
2222         <entry><option>-B <replaceable>x</replaceable></option></entry>
2223         <entry><literal>shared_buffers = <replaceable>x</replaceable></></entry>
2224        </row>
2225        <row>
2226         <entry><option>-d <replaceable>x</replaceable></option></entry>
2227         <entry><literal>log_min_messages = DEBUG<replaceable>x</replaceable></></entry>
2228        </row>
2229        <row>
2230         <entry><option>-F</option></entry>
2231         <entry><literal>fsync = off</></entry>
2232        </row>
2233        <row>
2234         <entry><option>-h <replaceable>x</replaceable></option></entry>
2235         <entry><literal>virtual_host = <replaceable>x</replaceable></></entry>
2236        </row>
2237        <row>
2238         <entry><option>-i</option></entry>
2239         <entry><literal>tcpip_socket = on</></entry>
2240        </row>
2241        <row>
2242         <entry><option>-k <replaceable>x</replaceable></option></entry>
2243         <entry><literal>unix_socket_directory = <replaceable>x</replaceable></></entry>
2244        </row>
2245        <row>
2246         <entry><option>-l</option></entry>
2247         <entry><literal>ssl = on</></entry>
2248        </row>
2249        <row>
2250         <entry><option>-N <replaceable>x</replaceable></option></entry>
2251         <entry><literal>max_connections = <replaceable>x</replaceable></></entry>
2252        </row>
2253        <row>
2254         <entry><option>-p <replaceable>x</replaceable></option></entry>
2255         <entry><literal>port = <replaceable>x</replaceable></></entry>
2256        </row>
2257
2258        <row>
2259         <entry>
2260           <option>-fi</option>, <option>-fh</option>,
2261           <option>-fm</option>, <option>-fn</option>,
2262           <option>-fs</option>, <option>-ft</option><footnote
2263           id="fn.runtime-config-short">
2264            <para>
2265             For historical reasons, these options must be passed to
2266             the individual backend process via the <option>-o</option>
2267             postmaster option, for example,
2268 <screen>
2269 $ <userinput>postmaster -o '-S 1024 -s'</userinput>
2270 </screen>
2271             or via <envar>PGOPTIONS</envar> from the client side, as
2272             explained above.
2273            </para>
2274           </footnote>
2275          </entry>
2276          <entry>
2277           <literal>enable_indexscan=off</>,
2278           <literal>enable_hashjoin=off</>,
2279           <literal>enable_mergejoin=off</>,
2280           <literal>enable_nestloop=off</>,
2281           <literal>enable_seqscan=off</>,
2282           <literal>enable_tidscan=off</>
2283          </entry>
2284        </row>
2285
2286        <row>
2287         <entry><option>-s</option><footnoteref linkend="fn.runtime-config-short"></entry>
2288         <entry><literal>show_statement_stats = on</></entry>
2289        </row>
2290
2291        <row>
2292         <entry><option>-S <replaceable>x</replaceable></option><footnoteref linkend="fn.runtime-config-short">
2293         </entry>
2294         <entry><literal>sort_mem = <replaceable>x</replaceable></></entry>
2295        </row>
2296
2297        <row>
2298         <entry><option>-tpa</option>, <option>-tpl</option>, <option>-te</option><footnoteref linkend="fn.runtime-config-short"></entry>
2299         <entry><literal>log_parser_stats=on</>,
2300         <literal>log_planner_stats=on</>, 
2301         <literal>log_executor_stats=on</></entry>
2302        </row>
2303       </tbody>
2304      </tgroup>
2305     </table>
2306
2307   </sect2>
2308  </sect1>
2309
2310
2311  <sect1 id="kernel-resources">
2312   <title>Managing Kernel Resources</title>
2313
2314   <para>
2315    A large <productname>PostgreSQL</> installation can quickly exhaust
2316    various operating system resource limits. (On some systems, the
2317    factory defaults are so low that you don't even need a really
2318    <quote>large</> installation.) If you have encountered this kind of
2319    problem, keep reading.
2320   </para>
2321
2322   <sect2 id="sysvipc">
2323    <title>Shared Memory and Semaphores</title>
2324
2325    <indexterm zone="sysvipc">
2326     <primary>shared memory</primary>
2327    </indexterm>
2328
2329    <indexterm zone="sysvipc">
2330     <primary>semaphores</primary>
2331    </indexterm>
2332
2333    <para>
2334     Shared memory and semaphores are collectively referred to as
2335     <quote><systemitem class="osname">System V</>
2336     <acronym>IPC</></quote> (together with message queues, which are not
2337     relevant for <productname>PostgreSQL</>). Almost all modern
2338     operating systems provide these features, but not all of them have
2339     them turned on or sufficiently sized by default, especially systems
2340     with BSD heritage. (For the <systemitem class="osname">QNX</> and
2341     <systemitem class="osname">BeOS</> ports, <productname>PostgreSQL</>
2342     provides its own replacement implementation of these facilities.)
2343    </para>
2344
2345    <para>
2346     The complete lack of these facilities is usually manifested by an
2347     <errorname>Illegal system call</> error upon postmaster start. In
2348     that case there's nothing left to do but to reconfigure your
2349     kernel -- <productname>PostgreSQL</> won't work without them.
2350    </para>
2351
2352    <para>
2353     When <productname>PostgreSQL</> exceeds one of the various hard
2354     <acronym>IPC</> limits, the postmaster will refuse to start and
2355     should leave an instructive error message describing the problem
2356     encountered and what to do about it. (See also <xref
2357     linkend="postmaster-start-failures">.) The relevant kernel
2358     parameters are named consistently across different systems; <xref
2359     linkend="sysvipc-parameters"> gives an overview. The methods to set
2360     them, however, vary. Suggestions for some platforms are given below.
2361     Be warned that it is often necessary to reboot your machine, and
2362     possibly even recompile the kernel, to change these settings.
2363    </para>
2364
2365
2366    <table id="sysvipc-parameters">
2367     <title><systemitem class="osname">System V</> <acronym>IPC</> parameters</>
2368
2369     <tgroup cols="3">
2370      <thead>
2371       <row>
2372        <entry>Name</>
2373        <entry>Description</>
2374        <entry>Reasonable values</>
2375       </row>
2376      </thead>
2377
2378      <tbody>
2379       <row>
2380        <entry><varname>SHMMAX</></>
2381        <entry>Maximum size of shared memory segment (bytes)</>
2382        <entry>250kB + 8.2 kB * <varname>shared_buffers</> + 14.2 kB * <varname>max_connections</> or infinity</entry>
2383       </row>
2384
2385       <row>
2386        <entry><varname>SHMMIN</></>
2387        <entry>Minimum size of shared memory segment (bytes)</>
2388        <entry>1</>
2389       </row>
2390
2391       <row>
2392        <entry><varname>SHMALL</></>
2393        <entry>Total amount of shared memory available (bytes or pages)</>
2394        <entry>if bytes, same as <varname>SHMMAX</varname>; if pages, <literal>ceil(SHMMAX/PAGE_SIZE)</literal></>
2395       </row>
2396
2397       <row>
2398        <entry><varname>SHMSEG</></>
2399        <entry>Maximum number of shared memory segments per process</>
2400        <entry>only 1 segment is needed, but the default is much higher</>
2401       </row>
2402
2403        <row>
2404         <entry><varname>SHMMNI</></>
2405         <entry>Maximum number of shared memory segments system-wide</>
2406         <entry>like <varname>SHMSEG</> plus room for other applications</>
2407        </row>
2408
2409        <row>
2410         <entry><varname>SEMMNI</></>
2411         <entry>Maximum number of semaphore identifiers (i.e., sets)</>
2412         <entry><literal>&gt;= ceil(max_connections / 16)</literal></>
2413        </row>
2414
2415        <row>
2416         <entry><varname>SEMMNS</></>
2417         <entry>Maximum number of semaphores system-wide</>
2418         <entry><literal>ceil(max_connections / 16) * 17</literal> + room for other applications</>
2419        </row>
2420
2421        <row>
2422         <entry><varname>SEMMSL</></>
2423         <entry>Maximum number of semaphores per set</>
2424         <entry>&gt;= 17</>
2425        </row>
2426
2427        <row>
2428         <entry><varname>SEMMAP</></>
2429         <entry>Number of entries in semaphore map</>
2430         <entry>see text</>
2431        </row>
2432
2433        <row>
2434         <entry><varname>SEMVMX</></>
2435         <entry>Maximum value of semaphore</>
2436         <entry>&gt;= 255  (The default is often 32767, don't change unless asked to.)</>
2437        </row>
2438
2439      </tbody>
2440     </tgroup>
2441    </table>
2442
2443
2444    <para>
2445     <indexterm><primary>SHMMAX</primary></indexterm> The most important
2446     shared memory parameter is <varname>SHMMAX</>, the maximum size, in
2447     bytes, of a shared memory segment. If you get an error message from
2448     <function>shmget</> like <errorname>Invalid argument</>, it is
2449     possible that this limit has been exceeded. The size of the required
2450     shared memory segment varies both with the number of requested
2451     buffers (<option>-B</> option) and the number of allowed connections
2452     (<option>-N</> option), although the former is the most significant.
2453     (You can, as a temporary solution, lower these settings to eliminate
2454     the failure.) As a rough approximation, you can estimate the
2455     required segment size by multiplying the number of buffers and the
2456     block size (8 kB by default) plus ample overhead (at least half a
2457     megabyte). Any error message you might get will contain the size of
2458     the failed allocation request.
2459    </para>
2460
2461    <para>
2462     Less likely to cause problems is the minimum size for shared
2463     memory segments (<varname>SHMMIN</>), which should be at most
2464     approximately 256 kB for <productname>PostgreSQL</> (it is
2465     usually just 1). The maximum number of segments system-wide
2466     (<varname>SHMMNI</>) or per-process (<varname>SHMSEG</>) should
2467     not cause a problem unless your system has them set to zero. Some
2468     systems also have a limit on the total amount of shared memory in
2469     the system; see the platform-specific instructions below.
2470    </para>
2471
2472    <para>
2473     <productname>PostgreSQL</> uses one semaphore per allowed connection
2474     (<option>-N</> option), in sets of 16.  Each such set will also
2475     contain a 17th semaphore which contains a <quote>magic
2476     number</quote>, to detect collision with semaphore sets used by
2477     other applications. The maximum number of semaphores in the system
2478     is set by <varname>SEMMNS</>, which consequently must be at least
2479     as high as the connection setting plus one extra for each 16
2480     allowed connections (see the formula in <xref
2481     linkend="sysvipc-parameters">).  The parameter <varname>SEMMNI</>
2482     determines the limit on the number of semaphore sets that can
2483     exist on the system at one time.  Hence this parameter must be at
2484     least <literal>ceil(max_connections / 16)</>. Lowering the number
2485     of allowed connections is a temporary workaround for failures,
2486     which are usually confusingly worded <quote><errorname>No space
2487     left on device</></>, from the function <function>semget()</>.
2488    </para>
2489
2490    <para>
2491     In some cases it might also be necessary to increase
2492     <varname>SEMMAP</> to be at least on the order of
2493     <varname>SEMMNS</>. This parameter defines the size of the semaphore
2494     resource map, in which each contiguous block of available semaphores
2495     needs an entry. When a semaphore set is freed it is either added to
2496     an existing entry that is adjacent to the freed block or it is
2497     registered under a new map entry. If the map is full, the freed
2498     semaphores get lost (until reboot). Fragmentation of the semaphore
2499     space could over time lead to fewer available semaphores than there
2500     should be.
2501    </para>
2502
2503    <para>
2504     The <varname>SEMMSL</> parameter, which determines how many
2505     semaphores can be in a set, must be at least 17 for
2506     <productname>PostgreSQL</>.
2507    </para>
2508
2509    <para>
2510     Various other settings related to <quote>semaphore undo</>, such as
2511     <varname>SEMMNU</> and <varname>SEMUME</>, are not of concern
2512     for <productname>PostgreSQL</>.
2513    </para>
2514
2515
2516    <para>
2517     <variablelist>
2518
2519      <varlistentry>
2520       <term><systemitem class="osname">BSD/OS</></term>
2521       <indexterm><primary>BSD/OS</></>
2522       <listitem>
2523        <formalpara>
2524         <title>Shared Memory</>
2525         <para>
2526          By default, only 4 MB of shared memory is supported. Keep in
2527          mind that shared memory is not pageable; it is locked in RAM.
2528          To increase the number of shared buffers supported by the
2529          postmaster, add the following to your kernel configuration
2530          file. A <varname>SHMALL</> value of 1024 represents 4 MB of
2531          shared memory. The following increases the maximum shared
2532          memory area to 32 MB:
2533 <programlisting>
2534 options "SHMALL=8192"
2535 options "SHMMAX=\(SHMALL*PAGE_SIZE\)"
2536 </programlisting>
2537         </para>
2538        </formalpara>
2539
2540        <para>
2541         For those running 4.1 or later, just make the above changes,
2542         recompile the kernel, and reboot. For those running earlier
2543         releases, use <command>bpatch</> to find the
2544         <varname>sysptsize</> value in the current kernel. This is
2545         computed dynamically at boot time.
2546 <screen>
2547 $ <userinput>bpatch -r sysptsize</>
2548 <computeroutput>0x9 = 9</>
2549 </screen>
2550         Next, add <varname>SYSPTSIZE</> as a hard-coded value in the
2551         kernel configuration file. Increase the value you found using
2552         <application>bpatch</>. Add 1 for every additional 4 MB of
2553         shared memory you desire.
2554 <programlisting>
2555 options "SYSPTSIZE=16"
2556 </programlisting>
2557         <varname>sysptsize</> cannot be changed by <command>sysctl</command>.
2558        </para>
2559
2560        <formalpara>
2561         <title>Semaphores</>
2562         <para>
2563          You may need to increase the number of semaphores. By default,
2564          <productname>PostgreSQL</> allocates 34 semaphores, which is
2565          over half the default system total of 60.
2566         </para>
2567        </formalpara>
2568
2569         <para>
2570         Set the values you want in your kernel configuration file, e.g.:
2571 <programlisting>
2572 options "SEMMNI=40"
2573 options "SEMMNS=240"
2574 options "SEMUME=40"
2575 options "SEMMNU=120"
2576 </programlisting>
2577        </para>
2578       </listitem>
2579      </varlistentry>
2580
2581
2582      <varlistentry>
2583       <term><systemitem class="osname">FreeBSD</></term>
2584       <term><systemitem class="osname">NetBSD</></term>
2585       <term><systemitem class="osname">OpenBSD</></term>
2586       <indexterm><primary>FreeBSD</></>
2587       <indexterm><primary>NetBSD</></>
2588       <indexterm><primary>OpenBSD</></>
2589       <listitem>
2590        <para>
2591         The options <varname>SYSVSHM</> and <varname>SYSVSEM</> need
2592         to be enabled when the kernel is compiled. (They are by
2593         default.) The maximum size of shared memory is determined by
2594         the option <varname>SHMMAXPGS</> (in pages). The following
2595         shows an example of how to set the various parameters:
2596 <programlisting>
2597 options         SYSVSHM
2598 options         SHMMAXPGS=4096
2599 options         SHMSEG=256
2600
2601 options         SYSVSEM
2602 options         SEMMNI=256
2603 options         SEMMNS=512
2604 options         SEMMNU=256
2605 options         SEMMAP=256
2606 </programlisting>
2607         (On <systemitem class="osname">NetBSD</> and <systemitem
2608         class="osname">OpenBSD</> the key word is actually
2609         <literal>option</literal> singular.)
2610        </para>
2611        <para>
2612         You might also want to use the <application>sysctl</> setting to
2613         lock shared memory into RAM and prevent it from being paged out
2614         to swap, e.g. <literal>kern.ipc.shm_use_phys</>.
2615        </para>
2616       </listitem>
2617      </varlistentry>
2618
2619
2620      <varlistentry>
2621       <term><systemitem class="osname">HP-UX</></term>
2622       <indexterm><primary>HP-UX</></>
2623       <listitem>
2624        <para>
2625         The default settings tend to suffice for normal installations.
2626         On <productname>HP-UX</> 10, the factory default for
2627         <varname>SEMMNS</> is 128, which might be too low for larger
2628         database sites.
2629        </para>
2630        <para>
2631         <acronym>IPC</> parameters can be set in the <application>System
2632         Administration Manager</> (<acronym>SAM</>) under
2633         <menuchoice><guimenu>Kernel
2634         Configuration</><guimenuitem>Configurable Parameters</></>. Hit
2635         <guibutton>Create A New Kernel</> when you're done.
2636        </para>
2637       </listitem>
2638      </varlistentry>
2639
2640
2641      <varlistentry>
2642       <term><systemitem class="osname">Linux</></term>
2643       <indexterm><primary>Linux</></>
2644       <listitem>
2645        <para>
2646         The default shared memory limit (both
2647         <varname>SHMMAX</varname> and <varname>SHMALL</varname>) is 32
2648         MB in 2.2 kernels, but it can be changed in the
2649         <filename>proc</filename> file system (without reboot).  For
2650         example, to allow 128 MB:
2651 <screen>
2652 <prompt>$</prompt> <userinput>echo 134217728 >/proc/sys/kernel/shmall</userinput>
2653 <prompt>$</prompt> <userinput>echo 134217728 >/proc/sys/kernel/shmmax</userinput>
2654 </screen>
2655         You could put these commands into a script run at boot-time.
2656        </para>
2657
2658        <para>
2659         Alternatively, you can use
2660         <citerefentry><refentrytitle>sysctl</refentrytitle>
2661         <manvolnum>8</manvolnum></citerefentry>, if available, to
2662         control these parameters.  Look for a file called
2663         <filename>/etc/sysctl.conf</filename> and add lines like the
2664         following to it:
2665 <programlisting>
2666 kernel.shmall = 134217728
2667 kernel.shmmax = 134217728
2668 </programlisting>
2669         This file is usually processed at boot time, but
2670         <application>sysctl</application> can also be called
2671         explicitly later.
2672        </para>
2673
2674        <para>
2675         Other parameters are sufficiently sized for any application. If
2676         you want to see for yourself look in
2677         <filename>/usr/src/linux/include/asm-<replaceable>xxx</>/shmpara
2678         m.h</> and <filename>/usr/src/linux/include/linux/sem.h</>.
2679        </para>
2680       </listitem>
2681      </varlistentry>
2682
2683
2684      <varlistentry>
2685       <term><systemitem class="osname">MacOS X</></term>
2686       <indexterm><primary>MacOS X</></>
2687       <listitem>
2688        <para>
2689         Edit the file
2690         <filename>/System/Library/StartupItems/SystemTuning/SystemTuning
2691         </> and change the following values:
2692 <programlisting>
2693 sysctl -w kern.sysv.shmmax
2694 sysctl -w kern.sysv.shmmin
2695 sysctl -w kern.sysv.shmmni
2696 sysctl -w kern.sysv.shmseg
2697 sysctl -w kern.sysv.shmall
2698 </programlisting>
2699         These values have the same meanings on <productname>MacOS</> X
2700         as those listed for previous operating systems.
2701        </para>
2702       </listitem>
2703      </varlistentry>
2704
2705
2706      <varlistentry>
2707       <term><systemitem class="osname">SCO OpenServer</></term>
2708       <indexterm><primary>SCO OpenServer</></>
2709       <listitem>
2710        <para>
2711         In the default configuration, only 512 kB of shared memory per
2712         segment is allowed, which is about enough for <option>-B 24 -N
2713         12</>. To increase the setting, first change directory to
2714         <filename>/etc/conf/cf.d</>. To display the current value of
2715         <varname>SHMMAX</>, in bytes, run
2716 <programlisting>
2717 ./configure -y SHMMAX
2718 </programlisting>
2719         To set a new value for <varname>SHMMAX</>, run:
2720 <programlisting>
2721 ./configure SHMMAX=<replaceable>value</>
2722 </programlisting>
2723         where <replaceable>value</> is the new value you want to use
2724         (in bytes). After setting <varname>SHMMAX</>, rebuild the kernel
2725 <programlisting>
2726 ./link_unix
2727 </programlisting>
2728         and reboot.
2729        </para>
2730       </listitem>
2731      </varlistentry>
2732
2733
2734      <varlistentry>
2735       <term><systemitem class="osname">Solaris</></term>
2736       <indexterm><primary>Solaris</></>
2737       <listitem>
2738        <para>
2739         At least in version 2.6, the default maximum size of a shared
2740         memory segments is too low for <productname>PostgreSQL</>. The
2741         relevant settings can be changed in <filename>/etc/system</>,
2742         for example:
2743 <programlisting>
2744 set shmsys:shminfo_shmmax=0x2000000
2745 set shmsys:shminfo_shmmin=1
2746 set shmsys:shminfo_shmmni=256
2747 set shmsys:shminfo_shmseg=256
2748
2749 set semsys:seminfo_semmap=256
2750 set semsys:seminfo_semmni=512
2751 set semsys:seminfo_semmns=512
2752 set semsys:seminfo_semmsl=32
2753 </programlisting>
2754         You need to reboot for the changes to take effect.
2755        </para>
2756
2757        <para>
2758         See also <ulink
2759         url="http://www.sunworld.com/swol-09-1997/swol-09-insidesolaris.html"></>
2760         for information on shared memory under
2761         <productname>Solaris</>.
2762        </para>
2763       </listitem>
2764      </varlistentry>
2765
2766
2767      <varlistentry>
2768       <term><systemitem class="osname">UnixWare</></term>
2769       <indexterm><primary>UnixWare</></>
2770       <listitem>
2771        <para>
2772         On <productname>UnixWare</> 7, the maximum size for shared
2773         memory segments is 512 kB in the default configuration. This
2774         is enough for about <option>-B 24 -N 12</>. To display the
2775         current value of <varname>SHMMAX</>, run
2776 <programlisting>
2777 /etc/conf/bin/idtune -g SHMMAX
2778 </programlisting>
2779         which displays the current, default, minimum, and maximum
2780         values, in bytes. To set a new value for <varname>SHMMAX</>,
2781         run:
2782 <programlisting>
2783 /etc/conf/bin/idtune SHMMAX <replaceable>value</>
2784 </programlisting>
2785         where <replaceable>value</> is the new value you want to use
2786         (in bytes). After setting <varname>SHMMAX</>, rebuild the
2787         kernel
2788 <programlisting>
2789 /etc/conf/bin/idbuild -B
2790 </programlisting>
2791         and reboot.
2792        </para>
2793       </listitem>
2794      </varlistentry>
2795
2796     </variablelist>
2797
2798    </para>
2799   </sect2>
2800
2801
2802   <sect2>
2803    <title>Resource Limits</title>
2804
2805    <para>
2806     Unix-like operating systems enforce various kinds of resource limits
2807     that might interfere with the operation of your
2808     <productname>PostgreSQL</productname> server. Of particular
2809     importance are limits on the number of processes per user, the
2810     number of open files per process, and the amount of memory available
2811     to each process. Each of these have a <quote>hard</quote> and a
2812     <quote>soft</quote> limit. The soft limit is what actually counts
2813     but it can be changed by the user up to the hard limit. The hard
2814     limit can only be changed by the root user. The system call
2815     <function>setrlimit</function> is responsible for setting these
2816     parameters. The shell's built-in command <command>ulimit</command>
2817     (Bourne shells) or <command>limit</command> (<application>csh</>) is
2818     used to control the resource limits from the command line. On
2819     BSD-derived systems the file <filename>/etc/login.conf</filename>
2820     controls the various resource limits set during login. See
2821     <citerefentry><refentrytitle>login.conf</refentrytitle>
2822     <manvolnum>5</manvolnum></citerefentry> for details. The relevant
2823     parameters are <varname>maxproc</varname>,
2824     <varname>openfiles</varname>, and <varname>datasize</varname>. For
2825     example:
2826 <programlisting>
2827 default:\
2828 ...
2829         :datasize-cur=256M:\
2830         :maxproc-cur=256:\
2831         :openfiles-cur=256:\
2832 ...
2833 </programlisting>
2834     (<literal>-cur</literal> is the soft limit.  Append
2835     <literal>-max</literal> to set the hard limit.)
2836    </para>
2837
2838    <para>
2839     Kernels can also have system-wide limits on some resources.
2840     <itemizedlist>
2841      <listitem>
2842       <para>
2843       On <productname>Linux</productname>
2844       <filename>/proc/sys/fs/file-max</filename> determines the
2845       maximum number of open files that the kernel will support.  It can
2846       be changed by writing a different number into the file or by
2847       adding an assignment in <filename>/etc/sysctl.conf</filename>.
2848       The maximum limit of files per process is fixed at the time the
2849       kernel is compiled; see
2850       <filename>/usr/src/linux/Documentation/proc.txt</filename> for
2851       more information.
2852       </para>
2853      </listitem>
2854     </itemizedlist>
2855    </para>
2856
2857    <para>
2858     The <productname>PostgreSQL</productname> server uses one process
2859     per connection so you should provide for at least as many processes
2860     as allowed connections, in addition to what you need for the rest
2861     of your system.  This is usually not a problem but if you run
2862     several servers on one machine things might get tight.
2863    </para>
2864
2865    <para>
2866     The factory default limit on open files is often set to
2867     <quote>socially friendly</quote> values that allow many users to
2868     coexist on a machine without using an inappropriate fraction of
2869     the system resources.  If you run many servers on a machine this
2870     is perhaps what you want, but on dedicated servers you may want to
2871     raise this limit.
2872    </para>
2873
2874    <para>
2875     On the other side of the coin, some systems allow individual
2876     processes to open large numbers of files; if more than a few
2877     processes do so then the system-wide limit can easily be exceeded.
2878     If you find this happening, and don't want to alter the system-wide
2879     limit, you can set <productname>PostgreSQL</productname>'s
2880     <varname>max_files_per_process</varname> configuration parameter to
2881     limit the consumption of open files.
2882    </para>
2883   </sect2>
2884
2885  </sect1>
2886
2887
2888  <sect1 id="postmaster-shutdown">
2889   <title>Shutting Down the Server</title>
2890
2891   <para>
2892    There are several ways to shut down the database server. You control
2893    the type of shutdown by sending different signals to the server
2894    process.
2895    <variablelist>
2896     <varlistentry>
2897      <term><systemitem>SIGTERM</systemitem></term>
2898      <listitem>
2899       <para>
2900        After receiving <systemitem>SIGTERM</systemitem>, the postmaster
2901        disallows new connections, but lets existing backends end their
2902        work normally. It shuts down only after all of the backends
2903        terminate normally. This is <firstterm>Smart
2904        Shutdown</firstterm>.
2905       </para>
2906      </listitem>
2907     </varlistentry>
2908
2909     <varlistentry>
2910      <term><systemitem>SIGINT</systemitem></term>
2911      <listitem>
2912       <para>
2913        The postmaster disallows new connections and sends all existing
2914        backends <systemitem>SIGTERM</systemitem>, which will cause them
2915        to abort their current transactions and exit promptly. It then
2916        waits for the backends to exit and finally shuts down. This is
2917        <firstterm>Fast Shutdown</firstterm>.
2918       </para>
2919      </listitem>
2920     </varlistentry>
2921
2922     <varlistentry>
2923      <term><systemitem>SIGQUIT</systemitem></term>
2924      <listitem>
2925       <para> This is <firstterm>Immediate Shutdown</firstterm>, which
2926       will cause the postmaster to send a
2927       <systemitem>SIGQUIT</systemitem> to all backends and exit
2928       immediately (without properly shutting itself down). The backends
2929       likewise exit immediately upon receiving
2930       <systemitem>SIGQUIT</systemitem>. This will lead to recovery (by
2931       replaying the WAL log) upon next start-up. This is recommended
2932       only in emergencies.
2933       </para>
2934      </listitem>
2935     </varlistentry>
2936    </variablelist>
2937
2938    <important>
2939     <para>
2940      It is best not to use <systemitem>SIGKILL</systemitem> to shut down
2941      the postmaster. This will prevent the postmaster from releasing
2942      shared memory and semaphores, which may then have to be done by
2943      manually.
2944     </para>
2945    </important>
2946
2947    The <acronym>PID</> of the postmaster process can be found using the
2948    <application>ps</application> program, or from the file
2949    <filename>postmaster.pid</filename> in the data directory. So for
2950    example, to do a fast shutdown:
2951 <screen>
2952 $ <userinput>kill -INT `head -1 /usr/local/pgsql/data/postmaster.pid`</userinput>
2953 </screen>
2954   </para>
2955   <para>
2956    The program <application>pg_ctl</application> is a shell script
2957    that provides a more convenient interface for shutting down the
2958    postmaster.
2959   </para>
2960  </sect1>
2961
2962  <sect1 id="ssl-tcp">
2963   <title>Secure TCP/IP Connections with SSL</title>
2964
2965   <indexterm zone="ssl-tcp">
2966    <primary>SSL</primary>
2967   </indexterm>
2968
2969   <para>
2970    <productname>PostgreSQL</> has native support for using
2971    <acronym>SSL</> connections to encrypt client/server communications
2972    for increased security. This requires
2973    <productname>OpenSSL</productname> be installed on both client and
2974    server systems and support enabled at build time (see <xref
2975    linkend="installation">).
2976   </para>
2977
2978   <para>
2979    With <acronym>SSL</> support compiled in, the
2980    <productname>PostgreSQL</> server can be started with
2981    <acronym>SSL</> support by setting the parameter
2982    <varname>ssl</varname> to on in <filename>postgresql.conf</>. When
2983    starting in <acronym>SSL</> mode, the server will look for the
2984    files <filename>server.key</> and <filename>server.crt</> in the
2985    data directory.  These files should contain the server private key
2986    and certificate respectively. These files must be set up correctly
2987    before an <acronym>SSL</>-enabled server can start. If the private key is
2988    protected with a passphrase, the server will prompt for the
2989    passphrase and will not start until it has been entered.
2990   </para>
2991
2992   <para>
2993    The server will listen for both standard and <acronym>SSL</>
2994    connections on the same TCP/IP port, and will negotiate with any
2995    connecting client on whether to use <acronym>SSL</>. See <xref
2996    linkend="client-authentication"> about how to force the server to
2997    require use of <acronym>SSL</> for certain connections.
2998   </para>
2999
3000   <para>
3001    For details on how to create your server private key and certificate,
3002    refer to the <productname>OpenSSL</> documentation. A simple
3003    self-signed certificate can be used to get started for testing, but a
3004    certificate signed by a certificate authority (<acronym>CA</>) (either one of the global
3005    <acronym>CAs</> or a local one) should be used in production so the
3006    client can verify the server's identity. To create a quick
3007    self-signed certificate, use the following
3008    <productname>OpenSSL</productname> command:
3009 <programlisting>
3010 openssl req -new -text -out server.req
3011 </programlisting>
3012    Fill out the information that <command>openssl</> asks for. Make sure
3013    that you enter the local host name as Common Name; the challenge
3014    password can be left blank. The script will generate a key that is
3015    passphrase protected; it will not accept a passphrase that is less
3016    than four characters long. To remove the passphrase (as you must if
3017    you want automatic start-up of the server), run the commands
3018 <programlisting>
3019 openssl rsa -in privkey.pem -out server.key
3020 rm privkey.pem
3021 </programlisting>
3022    Enter the old passphrase to unlock the existing key. Now do
3023 <programlisting>
3024 openssl req -x509 -in server.req -text -key server.key -out server.crt
3025 chmod og-rwx server.key
3026 </programlisting>
3027    to turn the certificate into a self-signed certificate and to copy the
3028    key and certificate to where the server will look for them.
3029   </para>
3030  </sect1>
3031
3032  <sect1 id="ssh-tunnels">
3033   <title>Secure TCP/IP Connections with <application>SSH</application> Tunnels</title>
3034
3035   <indexterm zone="ssh-tunnels">
3036    <primary>ssh</primary>
3037   </indexterm>
3038
3039   <note>
3040    <title>Acknowledgement</title>
3041    <para>
3042     Idea taken from an email by Gene Selkov, Jr.
3043     (<email>selkovjr@mcs.anl.gov</>) written on 1999-09-08 in response
3044     to a question from Eric Marsden.
3045    </para>
3046   </note>
3047
3048   <para>
3049    One can use <application>SSH</application> to encrypt the network
3050    connection between clients and a
3051    <productname>PostgreSQL</productname> server. Done properly, this
3052    provides an adequately secure network connection.
3053   </para>
3054
3055   <para>
3056    First make sure that an <application>SSH</application> server is
3057    running properly on the same machine as
3058    <productname>PostgreSQL</productname> and that you can log in using
3059    <command>ssh</command> as some user. Then you can establish a secure
3060    tunnel with a command like this from the client machine:
3061 <programlisting>
3062 ssh -L 3333:foo.com:5432 joe@foo.com
3063 </programlisting>
3064    The first number in the <option>-L</option> argument, 3333, is the
3065    port number of your end of the tunnel; it can be chosen freely. The
3066    second number, 5432, is the remote end of the tunnel -- the port
3067    number your server is using. The name or the address in between
3068    the port numbers is the host with the database server you are going
3069    to connect to. In order to connect to the database server using
3070    this tunnel, you connect to port 3333 on the local machine:
3071 <programlisting>
3072 psql -h localhost -p 3333 template1
3073 </programlisting>
3074    To the database server it will then look as though you are really
3075    user <literal>joe@foo.com</literal> and it will use whatever
3076    authentication procedure was set up for this user. In order for the
3077    tunnel setup to succeed you must be allowed to connect via
3078    <command>ssh</command> as <systemitem>joe@foo.com</systemitem>, just
3079    as if you had attempted to use <command>ssh</command> to set up a
3080    terminal session.
3081   </para>
3082
3083   <tip>
3084    <para>
3085     Several other applications exist that can provide secure tunnels using
3086     a procedure similar in concept to the one just described.
3087    </para>
3088   </tip>
3089
3090  </sect1>
3091
3092 </Chapter>
3093
3094 <!-- Keep this comment at the end of the file
3095 Local variables:
3096 mode:sgml
3097 sgml-omittag:nil
3098 sgml-shorttag:t
3099 sgml-minimize-attributes:nil
3100 sgml-always-quote-attributes:t
3101 sgml-indent-step:1
3102 sgml-indent-data:t
3103 sgml-parent-document:nil
3104 sgml-default-dtd-file:"./reference.ced"
3105 sgml-exposed-tags:nil
3106 sgml-local-catalogs:("/usr/lib/sgml/catalog")
3107 sgml-local-ecat-files:nil
3108 End:
3109 -->