DB Internals AtlasPostgreSQL 18.6 Home About

Parameter · Reporting and Logging / Where to Log

log_truncate_on_rotation

Truncate existing log files of same name during log rotation.

  • Default: off
  • Type: bool
  • Applies: Reload

In plain words

With a repeating file name such as postgresql-%a.log (weekday), next Monday's rotation reuses last Monday's file. With this setting on, the old content is thrown away and the file starts empty, so you keep exactly one week of logs without any cleanup job.

For DBAs and operators

Applies only to time-based rotation (log_rotation_age) when the new name already exists. It never truncates on server start, on pg_rotate_logfile(), or on size-based rotation; in those cases output is appended. This protects against losing the file you were just writing.

Classic self-cleaning recipes:

logging_collector = on
log_filename = 'postgresql-%a.log'   # 7 files
log_rotation_age = 1d
log_truncate_on_rotation = on

log_filename = 'postgresql-%H.log'   # 24 files
log_rotation_age = 1h
log_truncate_on_rotation = on

Support pitfall: when a customer reports "the log for last Tuesday is missing" on such a setup, it was simply overwritten. Ask for logs promptly, or have them copy the file before it cycles. Requires logging_collector.

How to change it

Change in postgresql.conf or ALTER SYSTEM, then run SELECT pg_reload_conf().

See it in context

Logger (logging collector)

Related parameters

log_filename log_rotation_age log_rotation_size logging_collector

All Reporting and Logging parameters