Wiki / Configuration Parameters
log_truncate_on_rotation
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. 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 server_log.%H%M, log_truncate_on_rotation to on, log_rotation_age to 60, and log_rotation_size to 1000000. Including %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.
English manual coverage begins with PostgreSQL 7.4. Source history and runtime observations have their own recorded version boundaries.
Reading PG 18·Select a recorded version
- boot val
- off
- category
- Reporting and Logging / Where to Log
- context
- sighup
- doc same as
- Unknown
- documented
- true
- enumvals
- Unknown
- extra desc
- Unknown
- lang
- en
- max val
- Unknown
- metadata version
- 18
- min val
- Unknown
- name
- log_truncate_on_rotation
- short desc
- Truncate existing log files of same name during log rotation.
- source
- pg-settings-source-snapshot
- unit
- Unknown
- vartype
- bool
Definition PG 18
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.
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 server_log.%H%M,
log_truncate_on_rotation to on,
log_rotation_age to 60, and
log_rotation_size to 1000000.
Including %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.
Compare versions
Complete source facts
doc html
<p>
When <code class="varname">logging_collector</code> is enabled,
this parameter will cause <span class="productname">PostgreSQL</span> 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 <code class="varname">log_filename</code> like <code class="literal">postgresql-%H.log</code>
would result in generating twenty-four hourly log files and then
cyclically overwriting them.
This parameter can only be set in the <code class="filename">postgresql.conf</code>
file or on the server command line.
</p><p>
Example: To keep 7 days of logs, one log file per day named
<code class="literal">server_log.Mon</code>, <code class="literal">server_log.Tue</code>,
etc., and automatically overwrite last week's log with this week's log,
set <code class="varname">log_filename</code> to <code class="literal">server_log.%a</code>,
<code class="varname">log_truncate_on_rotation</code> to <code class="literal">on</code>, and
<code class="varname">log_rotation_age</code> to <code class="literal">1440</code>.
</p><p>
Example: To keep 24 hours of logs, one log file per hour, but
also rotate sooner if the log file size exceeds 1GB, set
<code class="varname">log_filename</code> to <code class="literal">server_log.%H%M</code>,
<code class="varname">log_truncate_on_rotation</code> to <code class="literal">on</code>,
<code class="varname">log_rotation_age</code> to <code class="literal">60</code>, and
<code class="varname">log_rotation_size</code> to <code class="literal">1000000</code>.
Including <code class="literal">%M</code> in <code class="varname">log_filename</code> allows
any size-driven rotations that might occur to select a file name
different from the hour's initial file name.
</p>documentation revision
{"inputs":[{"file":"runtime-config-logging.html","kind":"same-version-reviewed-manual","locale":"en","sha256":"278d913b9c0f735c5cd7b35fd7205826bbd9c449805370d2dbe54105c0ed1d88","version":"18.7"},{"file":"runtime-config-logging.html","kind":"same-version-reviewed-manual","locale":"zh-Hans","sha256":"68c010254e1859ec0b76f06a563babd51a6c38997f1242e35e4c6b649724b1cb","version":"18.7"}],"release":"18.7","runtime_remeasured":false,"source_revision":"pgdoc:b9f0e7232f60f380d642ac9b99226606c254b552"}Source references
Full definition and evidence JSON
Definition sources
center · PostgreSQL 18 · wiki-repair-20261023:ba2ed9297627c0b3b3d638cc60d015596b3a7ada38de45dbab54b7169423cf33
Text language: en · wiki-repair-20261023:ba2ed9297627c0b3b3d638cc60d015596b3a7ada38de45dbab54b7169423cf33