Configuration parameter

log_truncate_on_rotation — PostgreSQL configuration parameter

Category Error Reporting and Logging Change scope Sighup

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.

At a glance

Property Value
Parameter log_truncate_on_rotation
Category Error Reporting and Logging
Default (see documentation)
Value type boolean (on/off)
Change scope Reload (postgresql.conf, SIGHUP)
Available in PostgreSQL 12, 13, 14, 15, 16, 17, 18, 19 (added in 12)

What it does

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.Mon, server_log.Tue, etc., and automatically overwrite last week’s log with this week’s log, set log_filename to server_log.%a, log_truncate_on_rotation to on, and log_rotation_age to 1440.

(Description quoted from the official PostgreSQL documentation.)

How to apply a change

Set it in postgresql.conf (or with ALTER SYSTEM) and reload with SELECT pg_reload_conf(); or pg_ctl reload — no restart needed.

Inspect the current value and source with SHOW log_truncate_on_rotation; or SELECT name, setting, unit, context, source FROM pg_settings WHERE name = 'log_truncate_on_rotation';.

Tuning guidance

Tune this for observability versus log volume, not for raw performance. More verbose logging helps diagnose problems but costs disk and I/O; quieter logging saves space but hides detail. Pick a level your log pipeline can store and search, and raise verbosity temporarily when investigating an incident.

Reference

PostgreSQL documentation — log_truncate_on_rotation.

Keep going

Related & next steps

Was this helpful?

← All configuration parameters