When logging_collector is 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 a log_filename like
postgresql-%H.log would 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 named
server_log.Tue, etc, and automatically overwrite last week's log with this week's log, set log_filename to
on, and log_rotation_age to
Example: To keep 24 hours of logs, one log file per hour, but also rotate sooner if the log file size exceeds 1GB, set log_filename to
on, log_rotation_age to
60, and log_rotation_size to
%M in log_filename allows any size-driven rotations that might occur to select a file name different from the hour's initial file name.