Skip to content

Commit bb2ff5f

Browse files
committed
Expand discussion of logfile management a little bit.
1 parent 7107c3d commit bb2ff5f

File tree

2 files changed

+63
-8
lines changed

2 files changed

+63
-8
lines changed

doc/src/sgml/maintenance.sgml

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/maintenance.sgml,v 1.7 2001/11/18 22:17:30 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/maintenance.sgml,v 1.8 2001/11/20 04:27:49 tgl Exp $
33
-->
44

55
<chapter id="maintenance">
@@ -34,10 +34,8 @@ $Header: /cvsroot/pgsql/doc/src/sgml/maintenance.sgml,v 1.7 2001/11/18 22:17:30
3434
</para>
3535

3636
<para>
37-
It is also necessary to rotate the database server log file that is specified
38-
when the <application>postmaster</application> is started. If you are using
39-
<application>syslog</application>, you can send a <literal>SIGHUP</literal>
40-
signal to the syslog daemon to force it to start writing a new log file.
37+
Something else that might need periodic attention is log file management.
38+
This is discussed in <xref linkend="logfile-maintenance">.
4139
</para>
4240

4341
<para>
@@ -367,6 +365,61 @@ VACUUM
367365

368366
</sect2>
369367
</sect1>
368+
369+
<sect1 id="logfile-maintenance">
370+
<title>Log File Maintenance</title>
371+
372+
<indexterm zone="logfile-maintenance">
373+
<primary>log files</primary>
374+
</indexterm>
375+
376+
<para>
377+
It's a good idea to save the database server's log output somewhere,
378+
rather than just routing it to <filename>/dev/null</>. The log output
379+
is invaluable when it comes time to diagnose problems. However, the
380+
log output tends to be voluminuous (especially at higher debug levels)
381+
and you won't want to save it indefinitely. You need to <quote>rotate</>
382+
the log files so that new log files are started and old ones thrown
383+
away every so often.
384+
</para>
385+
386+
<para>
387+
If you simply direct the postmaster's stderr into a file, the only way
388+
to truncate the log file is to stop and restart the postmaster. This
389+
may be okay for development setups but you won't want to run a production
390+
server that way.
391+
</para>
392+
393+
<para>
394+
The simplest production-grade approach to managing log output is to send it
395+
all to <application>syslog</> and let <application>syslog</> deal with file
396+
rotation. To do this, make sure <productname>Postgres</> was built with
397+
the <option>--enable-syslog</> configure option, and set
398+
<literal>syslog</> to 2
399+
(log to syslog only) in <filename>postgresql.conf</>.
400+
Then you can send a <literal>SIGHUP</literal> signal to the
401+
<application>syslog</> daemon whenever you want to force it to start
402+
writing a new log file.
403+
</para>
404+
405+
<para>
406+
On many systems, however, syslog is not very reliable, particularly
407+
with large log messages; it may truncate or drop messages just when
408+
you need them the most. You may find it more useful to pipe the
409+
<application>postmaster</>'s stderr to some type of log rotation script.
410+
If you start the postmaster with <application>pg_ctl</>, then the
411+
postmaster's stderr is already redirected to stdout, so you just need a
412+
pipe command:
413+
414+
<screen>
415+
<userinput>pg_ctl start | logrotate</userinput>
416+
</screen>
417+
418+
The <productname>Postgres</> distribution doesn't include a suitable
419+
log rotation program, but there are many available on the net;
420+
one is included in the Apache distribution, for example.
421+
</para>
422+
</sect1>
370423
</chapter>
371424

372425
<!-- Keep this comment at the end of the file

doc/src/sgml/runtime.sgml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.95 2001/11/19 03:58:24 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.96 2001/11/20 04:27:49 tgl Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -171,9 +171,11 @@ NOTICE: Initializing database with en_US collation order.
171171
<screen>
172172
&gt; <userinput>postmaster -D /usr/local/pgsql/data &gt; logfile 2&gt;&amp;1 &amp;</userinput>
173173
</screen>
174-
It is an extremely good idea to keep the server output around
175-
somewhere, as indicated here. It will help both for auditing
174+
It is an extremely good idea to keep the server's stdout and stderr
175+
output around somewhere, as suggested here. It will help both for auditing
176176
purposes and to diagnose problems.
177+
(See <xref linkend="logfile-maintenance"> for a more thorough discussion
178+
of logfile handling.)
177179
</para>
178180

179181
<para>

0 commit comments

Comments
 (0)