| The PostgreSQL 9.0 Reference Manual - Volume 3 - Server Administration Guide
by The PostgreSQL Global Development Group Paperback (6"x9"), 274 pages ISBN 9781906966072 RRP £9.95 ($14.95) Sales of this book support the PostgreSQL project! Get a printed copy>>> |
4.7.1 Where To Log
log_destination(string)-
PostgreSQL supports several methods
for logging server messages, including
stderr,csvlogandsyslog. On Windows,eventlogis also supported. Set this parameter to a list of desired log destinations separated by commas. The default is to log tostderronly. This parameter can only be set in the ‘postgresql.conf’ file or on the server command line. Ifcsvlogis included inlog_destination, log entries are output in “comma separated value” (CSV) format, which is convenient for loading logs into programs. See section 4.7.4 Using CSV-Format Log Output for details.logging_collectormust be enabled to generate CSV-format log output.Note: On most Unix systems, you will need to alter the configuration of your system's syslog daemon in order to make use of the
syslogoption forlog_destination. PostgreSQL can log to syslog facilitiesLOCAL0throughLOCAL7(seesyslog_facility), but the default syslog configuration on most platforms will discard all such messages. You will need to add something like:local0.* /var/log/postgresql
to the syslog daemon's configuration file to make it work.
logging_collector(boolean)-
This parameter captures plain and CSV-format log messages
sent to stderr and redirects them into log files.
This approach is often more useful than
logging to syslog, since some types of messages
might not appear in syslog output (a common example
is dynamic-linker failure messages).
This parameter can only be set at server start.
Note: The logging collector is designed to never lose messages. This means that in case of extremely high load, server processes could be blocked due to trying to send additional log messages when the collector has fallen behind. In contrast, syslog prefers to drop messages if it cannot write them, which means it's less reliable in those cases but it will not block the rest of the system.
log_directory(string)-
When
logging_collectoris enabled, this parameter determines the directory in which log files will be created. It can be specified as an absolute path, or relative to the cluster data directory. This parameter can only be set in the ‘postgresql.conf’ file or on the server command line. log_filename(string)-
When
logging_collectoris enabled, this parameter sets the file names of the created log files. The value is treated as astrftimepattern, so%-escapes can be used to specify time-varying file names. (Note that if there are any time-zone-dependent%-escapes, the computation is done in the zone specified bylog_timezone.) Note that the system'sstrftimeis not used directly, so platform-specific (nonstandard) extensions do not work. If you specify a file name without escapes, you should plan to use a log rotation utility to avoid eventually filling the entire disk. In releases prior to 8.4, if no%escapes were present, PostgreSQL would append the epoch of the new log file's creation time, but this is no longer the case. If CSV-format output is enabled inlog_destination,.csvwill be appended to the timestamped log file name to create the file name for CSV-format output. (Iflog_filenameends in.log, the suffix is replaced instead.) In the case of the example above, the CSV file name will beserver_log.1093827753.csv. This parameter can only be set in the ‘postgresql.conf’ file or on the server command line. log_rotation_age(integer)-
When
logging_collectoris enabled, this parameter determines the maximum lifetime of an individual log file. After this many minutes have elapsed, a new log file will be created. Set to zero to disable time-based creation of new log files. This parameter can only be set in the ‘postgresql.conf’ file or on the server command line. log_rotation_size(integer)-
When
logging_collectoris enabled, this parameter determines the maximum size of an individual log file. After this many kilobytes have been emitted into a log file, a new log file will be created. Set to zero to disable size-based creation of new log files. This parameter can only be set in the ‘postgresql.conf’ file or on the server command line. log_truncate_on_rotation(boolean)-
When
logging_collectoris enabled, this parameter will cause PostgreSQL to truncate (overwrite), rather than append to, any existing log file of the same name. However, truncation will occur only when a new file is being opened due to time-based rotation, not during server startup or size-based rotation. When off, pre-existing files will be appended to in all cases. For example, using this setting in combination with alog_filenamelikepostgresql-%H.logwould result in generating twenty-four hourly log files and then cyclically overwriting them. This parameter can only be set in the ‘postgresql.conf’ file or on the server command line. Example: To keep 7 days of logs, one log file per day namedserver_log.Mon,server_log.Tue, etc, and automatically overwrite last week's log with this week's log, setlog_filenametoserver_log.%a,log_truncate_on_rotationtoon, andlog_rotation_ageto1440. Example: To keep 24 hours of logs, one log file per hour, but also rotate sooner if the log file size exceeds 1GB, setlog_filenametoserver_log.%H%M,log_truncate_on_rotationtoon,log_rotation_ageto60, andlog_rotation_sizeto1000000. Including%Minlog_filenameallows any size-driven rotations that might occur to select a file name different from the hour's initial file name. syslog_facility(enum)-
When logging to syslog is enabled, this parameter
determines the syslog
“facility” to be used. You can choose
from
LOCAL0,LOCAL1,LOCAL2,LOCAL3,LOCAL4,LOCAL5,LOCAL6,LOCAL7; the default isLOCAL0. See also the documentation of your system's syslog daemon. This parameter can only be set in the ‘postgresql.conf’ file or on the server command line. syslog_ident(string)-
When logging to syslog is enabled, this parameter
determines the program name used to identify
PostgreSQL messages in
syslog logs. The default is
postgres. This parameter can only be set in the ‘postgresql.conf’ file or on the server command line. silent_mode(boolean)-
Runs the server silently. If this parameter is set, the server
will automatically run in background and disassociate from the
controlling terminal.
This parameter can only be set at server start.
Caution: When this parameter is set, the server's standard output and standard error are redirected to the file ‘postmaster.log’ within the data directory. There is no provision for rotating this file, so it will grow indefinitely unless server log output is redirected elsewhere by other settings. It is recommended that
log_destinationbe set tosyslogor thatlogging_collectorbe enabled when using this option. Even with those measures, errors reported early during startup may appear in ‘postmaster.log’ rather than the normal log destination.
| ISBN 9781906966072 | The PostgreSQL 9.0 Reference Manual - Volume 3 - Server Administration Guide | See the print edition |