1
1
<!--
2
- $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.36 2004/07/24 19:51:22 tgl Exp $
2
+ $PostgreSQL: pgsql/doc/src/sgml/maintenance.sgml,v 1.37 2004/08/05 23:32:10 tgl Exp $
3
3
-->
4
4
5
5
<chapter id="maintenance">
@@ -445,22 +445,52 @@ VACUUM
445
445
</para>
446
446
447
447
<para>
448
- If you simply direct the <systemitem>stderr</> of the <command>postmaster</command> into a
449
- file, the only way to truncate the log file is to stop and restart
448
+ If you simply direct the <systemitem>stderr</> of the
449
+ <command>postmaster</command> into a
450
+ file, you will have log output, but
451
+ the only way to truncate the log file is to stop and restart
450
452
the <command>postmaster</command>. This may be OK if you are using
451
453
<productname>PostgreSQL</productname> in a development environment,
452
454
but few production servers would find this behavior acceptable.
453
455
</para>
454
456
455
457
<para>
456
- The simplest production-grade approach to managing log output is to
458
+ A better approach is to send the <command>postmaster</>'s
459
+ <systemitem>stderr</> output to some type of log rotation program.
460
+ There is a built-in log rotation program, which you can use by
461
+ setting the configuration parameter <literal>redirect_stderr</> to
462
+ <literal>true</> in <filename>postgresql.conf</>. The control
463
+ parameters for this program are described in <xref
464
+ linkend="runtime-config-logging-where">.
465
+ </para>
466
+
467
+ <para>
468
+ Alternatively, you might prefer to use an external log rotation
469
+ program, if you have one that you are already using with other
470
+ server software. For example, the <application>rotatelogs</application>
471
+ tool included in the <productname>Apache</productname> distribution
472
+ can be used with <productname>PostgreSQL</productname>. To do this,
473
+ just pipe the <command>postmaster</>'s
474
+ <systemitem>stderr</> output to the desired program.
475
+ If you start the server with
476
+ <command>pg_ctl</>, then <systemitem>stderr</>
477
+ is already redirected to <systemitem>stdout</>, so you just need a
478
+ pipe command:
479
+
480
+ <programlisting>
481
+ pg_ctl start | rotatelogs /var/log/pgsql_log 86400
482
+ </programlisting>
483
+ </para>
484
+
485
+ <para>
486
+ Another production-grade approach to managing log output is to
457
487
send it all to <application>syslog</> and let
458
488
<application>syslog</> deal with file rotation. To do this, set the
459
- configuration parameter <literal>log_destination</> to ' syslog' (to log to
460
- <application>syslog</> only) in <filename>postgresql.conf</>. Then
461
- you can send a <literal>SIGHUP</literal> signal to the
462
- <application>syslog</> daemon whenever you want to force it to
463
- start writing a new log file. If you want to automate log
489
+ configuration parameter <literal>log_destination</> to <literal> syslog</>
490
+ (to log to <application>syslog</> only) in
491
+ <filename>postgresql.conf</>. Then you can send a <literal>SIGHUP</literal>
492
+ signal to the <application>syslog</> daemon whenever you want to force it
493
+ to start writing a new log file. If you want to automate log
464
494
rotation, the <application>logrotate</application> program can be
465
495
configured to work with log files from
466
496
<application>syslog</application>.
@@ -471,27 +501,15 @@ VACUUM
471
501
particularly with large log messages; it may truncate or drop messages
472
502
just when you need them the most. Also, on <productname>linux</>,
473
503
<application>syslog</> will sync each message to disk, yielding poor
474
- performance. Use a <literal>-</> at the start of the file name
475
- in the <application>syslog</> config file to disable this behavior.
504
+ performance. (You can use a <literal>-</> at the start of the file name
505
+ in the <application>syslog</> config file to disable this behavior.)
476
506
</para>
477
507
478
508
<para>
479
- You may find it more useful to pipe the
480
- <systemitem>stderr</> of the <command>postmaster</> to some type of
481
- log rotation program. If you start the server with
482
- <command>pg_ctl</>, then the <systemitem>stderr</> of the <command>postmaster</command>
483
- is already redirected to <systemitem>stdout</>, so you just need a
484
- pipe command:
485
-
486
- <programlisting>
487
- pg_ctl start | rotatelogs /var/log/pgsql_log 86400
488
- </programlisting>
489
-
490
- The <productname>PostgreSQL</> distribution doesn't include a
491
- suitable log rotation program, but there are many available on the
492
- Internet. For example, the <application>rotatelogs</application>
493
- tool included in the <productname>Apache</productname> distribution
494
- can be used with <productname>PostgreSQL</productname>.
509
+ Note that all the solutions described above take care of starting new
510
+ log files at configurable intervals, but they do not handle deletion
511
+ of old, no-longer-interesting log files. You will also want to set
512
+ up a batch job to periodically delete old log files.
495
513
</para>
496
514
</sect1>
497
515
</chapter>
0 commit comments