log_rotation_age

A system parameter determining the lifetime of a log file

log_rotation_age is a configuration parameter determining the maximum lifetime of an individual log file.

log_rotation_age was added in PostgreSQL 8.0.

Default value

The default value for log_rotation_age is: 1d.

Usage

A new log file will be created when the amount of specified by log_rotation_age has elapsed since the creation of the previous log file.

logging_collector must be enabled for log_rotation_age to take effect.

Note that log_rotation_age is only effective if log_filename is formatted to the same or higher interval granularity as the specified value. For example, if log_filename is a fixed string, the log file will never be rotated.

A value of 0 disables log_rotation_age.

Change history

Examples

Usage example with log_rotation_age set to 1min:

postgres=# SHOW log_filename;
          log_filename          
--------------------------------
 postgresql-%Y-%m-%d_%H%M%S.log
(1 row)

postgres=# SELECT pg_current_logfile();
          pg_current_logfile           
---------------------------------------
 /tmp/postgresql-2022-07-29_040400.log
(1 row)

postgres=# SELECT pg_sleep(60);
 pg_sleep 
----------
 
(1 row)

postgres=# SELECT pg_current_logfile();
          pg_current_logfile           
---------------------------------------
 /tmp/postgresql-2022-07-29_040500.log
(1 row)

Categories

GUC configuration item, Logging

See also

log_rotation_size, logging_collector