{"Entry":{"collection":"guc","key":"log_truncate_on_rotation","name":"log_truncate_on_rotation","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Reporting and Logging / Where to Log","category_zh":"","changed_in":[],"changes":[{"documentation_changed":false,"fields":{},"from":"7.4","status":"added","to":"8.0"},{"documentation_changed":true,"fields":{},"from":"8.0","status":"changed","to":"8.1"},{"documentation_changed":true,"fields":{},"from":"8.1","status":"changed","to":"8.2"},{"documentation_changed":true,"fields":{},"from":"8.2","status":"changed","to":"8.3"},{"documentation_changed":true,"fields":{},"from":"14","status":"changed","to":"15"}],"content_hash":"94e92f6da40d30489f7ab83dbcfd234433323b46a022c0cbeefb486ecce5180a","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"off"}],"derived_content_hash":"dd8f8fe5ab3eac9de6666abf7f6a4b8b7b662d82a8c353afb417c387b088f419","documentation_refresh":{"batch":"20261113","original_source_rev":"wiki-repair-20261023:ba2ed9297627c0b3b3d638cc60d015596b3a7ada38de45dbab54b7169423cf33","versions":{"14":"14.25","15":"15.20","16":"16.16","17":"17.12","18":"18.7","19":"19rc2"}},"editorial":{"advice":{"olap":"For analytical logs, confirm that long-running ingestion has finished before a repeating name is truncated; use unique names when completion cannot be guaranteed.","oltp":"Enable log_truncate_on_rotation only when time-based rotation intentionally reuses a filename and the previous file has been durably shipped or is meant to be replaced. Leave it off for unique timestamped names.","small":"A short repeating cycle can bound disk use, but truncation is not retention management. Monitor shipping and backups so the next time rotation cannot erase the only copy."},"mechanism":["log_truncate_on_rotation truncates existing log files of same name during log rotation. Truncation occurs when time-based rotation reuses an existing filename; size rotation and other causes do not apply the same overwrite rule.","log_truncate_on_rotation is a SIGHUP-context setting: a configuration reload activates the new server value without a restart; subsequent operations that consult it use the refreshed value.","The active path is composed from log_destination, logging_collector or syslog/eventlog, file naming and permissions, rotation triggers, and external shipping or retention."],"pitfalls":["Editing log_truncate_on_rotation without reloading configuration and verifying the effective value and subsequent behavior.","Combining incompatible destination, collector, filename, and rotation assumptions and then losing or overwriting logs.","Failing to monitor a full or unwritable log target, which can block logging or database activity depending on the path.","Expecting truncation on every rotation path; it is tied to time-based reuse of an existing filename."],"references":[{"title":"PostgreSQL 19 Beta 4: log_truncate_on_rotation","url":"https://www.postgresql.org/docs/19/runtime-config-logging.html#GUC-LOG-TRUNCATE-ON-ROTATION"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["logging_collector","log_destination","log_directory","log_filename","log_rotation_age","log_rotation_size"],"summary":"log_truncate_on_rotation is the PostgreSQL setting that controls whether PostgreSQL truncates existing log files of same name during log rotation."},"enumvals":[],"first_version":"8.0","group":"Reporting and Logging","group_slug":"logging","imported_at":"2026-09-30T00:40:57.453548+08:00","intro_commit":{},"key":"log_truncate_on_rotation","last_version":"20","max_val":"","min_val":"","name":"log_truncate_on_rotation","position":256,"present_in":["8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6","10","11","12","13","14","15","16","17","18","19","20"],"repair_provenance":{"original_source_revision":"english-manuals:1f3eb48cf140ce5a9d9d91850e83a2bf6037b23e3a15cf249178e97f1a9871ad","receipt_sha256":"ab319a6ae52a3d1ee2b136f41108c36d7e9f4ea2f348acaf76325fdf2a7e82e6","repair":"wiki-repair-20261023"},"short_desc":"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.","short_desc_zh":"","source_rev":"wiki-repair-20261023:ba2ed9297627c0b3b3d638cc60d015596b3a7ada38de45dbab54b7169423cf33","unit":"","vartype":"bool"}},"Definition":{"Collection":"guc","Key":"log_truncate_on_rotation","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"log_truncate_on_rotation","SourceRevision":"wiki-repair-20261023:ba2ed9297627c0b3b3d638cc60d015596b3a7ada38de45dbab54b7169423cf33","Facts":{"boot_val":"off","category":"Reporting and Logging / Where to Log","context":"sighup","description":"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.","description_zh":"当 logging_collector 被启用时，这个参数将导致 PostgreSQL 截断（覆盖而不是追加）任何已有的同名日志文件。不过，截断只在一个新文件由于基于时间的轮转被打开时发生，在服务器启动或基于尺寸的轮转时不会发生。如果被关闭，在所有情况下以前存在的文件将被追加。例如，使用这个设置和一个类似 postgresql-%H.log 的 log_filename 将导致产生 24 个每小时的日志文件，并且循环地覆盖它们。这个参数只能在 postgresql.conf 文件中或在服务器命令行上设置。 示例：保留 7 天的日志，每天一个日志文件，命名为 server_log.Mon，server_log.Tue，等等，并自动用本周的日志覆盖上周的日志，将 log_filename 设置为 server_log.%a，将 log_truncate_on_rotation 设置为 on，将 log_rotation_age 设置为 1440。 示例：要保留 24 小时的日志，每个小时一个日志文件，如果日志文件尺寸超过 1GB，也会提前轮转。可以这样做：将 log_filename 设置为 server_log.%H%M、将 log_truncate_on_rotation 设置为 on、将 log_rotation_age 设置为 60 并且将 log_rotation_size 设置为 1000000。在 log_filename 中包含 %M，可让按文件大小触发的轮转选用与整点初始文件名不同的新文件名。","description_zh_html":"\u003cp\u003e\n        当 \u003ccode class=\"varname\"\u003elogging_collector\u003c/code\u003e 被启用时，这个参数将导致 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e 截断（覆盖而不是追加）任何已有的同名日志文件。不过，截断只在一个新文件由于基于时间的轮转被打开时发生，在服务器启动或基于尺寸的轮转时不会发生。如果被关闭，在所有情况下以前存在的文件将被追加。例如，使用这个设置和一个类似 \u003ccode class=\"literal\"\u003epostgresql-%H.log\u003c/code\u003e 的 \u003ccode class=\"varname\"\u003elog_filename\u003c/code\u003e 将导致产生 24 个每小时的日志文件，并且循环地覆盖它们。这个参数只能在 \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e 文件中或在服务器命令行上设置。\n       \u003c/p\u003e\u003cp\u003e\n        示例：保留 7 天的日志，每天一个日志文件，命名为 \u003ccode class=\"literal\"\u003eserver_log.Mon\u003c/code\u003e，\u003ccode class=\"literal\"\u003eserver_log.Tue\u003c/code\u003e，等等，并自动用本周的日志覆盖上周的日志，将 \u003ccode class=\"varname\"\u003elog_filename\u003c/code\u003e 设置为 \u003ccode class=\"literal\"\u003eserver_log.%a\u003c/code\u003e，将 \u003ccode class=\"varname\"\u003elog_truncate_on_rotation\u003c/code\u003e 设置为 \u003ccode class=\"literal\"\u003eon\u003c/code\u003e，将 \u003ccode class=\"varname\"\u003elog_rotation_age\u003c/code\u003e 设置为 \u003ccode class=\"literal\"\u003e1440\u003c/code\u003e。\n       \u003c/p\u003e\u003cp\u003e\n        示例：要保留 24 小时的日志，每个小时一个日志文件，如果日志文件尺寸超过 1GB，也会提前轮转。可以这样做：将 \u003ccode class=\"varname\"\u003elog_filename\u003c/code\u003e 设置为 \u003ccode class=\"literal\"\u003eserver_log.%H%M\u003c/code\u003e、将 \u003ccode class=\"varname\"\u003elog_truncate_on_rotation\u003c/code\u003e 设置为 \u003ccode class=\"literal\"\u003eon\u003c/code\u003e、将 \u003ccode class=\"varname\"\u003elog_rotation_age\u003c/code\u003e 设置为 \u003ccode class=\"literal\"\u003e60\u003c/code\u003e 并且将 \u003ccode class=\"varname\"\u003elog_rotation_size\u003c/code\u003e 设置为 \u003ccode class=\"literal\"\u003e1000000\u003c/code\u003e。在 \u003ccode class=\"varname\"\u003elog_filename\u003c/code\u003e 中包含 \u003ccode class=\"literal\"\u003e%M\u003c/code\u003e，可让按文件大小触发的轮转选用与整点初始文件名不同的新文件名。\n       \u003c/p\u003e","doc":{"anchor":"GUC-LOG-TRUNCATE-ON-ROTATION","file":"runtime-config-logging.html","lang":"en","sha256":"278d913b9c0f735c5cd7b35fd7205826bbd9c449805370d2dbe54105c0ed1d88","slug":"18"},"doc_html":"\u003cp\u003e\n        When \u003ccode class=\"varname\"\u003elogging_collector\u003c/code\u003e is enabled,\n        this parameter will cause \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e to truncate (overwrite),\n        rather than append to, any existing log file of the same name.\n        However, truncation will occur only when a new file is being opened\n        due to time-based rotation, not during server startup or size-based\n        rotation.  When off, pre-existing files will be appended to in\n        all cases.  For example, using this setting in combination with\n        a \u003ccode class=\"varname\"\u003elog_filename\u003c/code\u003e like \u003ccode class=\"literal\"\u003epostgresql-%H.log\u003c/code\u003e\n        would result in generating twenty-four hourly log files and then\n        cyclically overwriting them.\n        This parameter can only be set in the \u003ccode class=\"filename\"\u003epostgresql.conf\u003c/code\u003e\n        file or on the server command line.\n       \u003c/p\u003e\u003cp\u003e\n        Example:  To keep 7 days of logs, one log file per day named\n        \u003ccode class=\"literal\"\u003eserver_log.Mon\u003c/code\u003e, \u003ccode class=\"literal\"\u003eserver_log.Tue\u003c/code\u003e,\n        etc., and automatically overwrite last week's log with this week's log,\n        set \u003ccode class=\"varname\"\u003elog_filename\u003c/code\u003e to \u003ccode class=\"literal\"\u003eserver_log.%a\u003c/code\u003e,\n        \u003ccode class=\"varname\"\u003elog_truncate_on_rotation\u003c/code\u003e to \u003ccode class=\"literal\"\u003eon\u003c/code\u003e, and\n        \u003ccode class=\"varname\"\u003elog_rotation_age\u003c/code\u003e to \u003ccode class=\"literal\"\u003e1440\u003c/code\u003e.\n       \u003c/p\u003e\u003cp\u003e\n        Example: To keep 24 hours of logs, one log file per hour, but\n        also rotate sooner if the log file size exceeds 1GB, set\n        \u003ccode class=\"varname\"\u003elog_filename\u003c/code\u003e to \u003ccode class=\"literal\"\u003eserver_log.%H%M\u003c/code\u003e,\n        \u003ccode class=\"varname\"\u003elog_truncate_on_rotation\u003c/code\u003e to \u003ccode class=\"literal\"\u003eon\u003c/code\u003e,\n        \u003ccode class=\"varname\"\u003elog_rotation_age\u003c/code\u003e to \u003ccode class=\"literal\"\u003e60\u003c/code\u003e, and\n        \u003ccode class=\"varname\"\u003elog_rotation_size\u003c/code\u003e to \u003ccode class=\"literal\"\u003e1000000\u003c/code\u003e.\n        Including \u003ccode class=\"literal\"\u003e%M\u003c/code\u003e in \u003ccode class=\"varname\"\u003elog_filename\u003c/code\u003e allows\n        any size-driven rotations that might occur to select a file name\n        different from the hour's initial file name.\n       \u003c/p\u003e","doc_same_as":"","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"},"documented":true,"enumvals":null,"extra_desc":null,"lang":"en","max_val":null,"metadata_version":"18","min_val":null,"name":"log_truncate_on_rotation","short_desc":"Truncate existing log files of same name during log rotation.","source":"pg-settings-source-snapshot","translation_provenance":{"inputs":[{"kind":"current-pgdoc-translation","path":"/Users/vonng/pgsty/pgdoc/zh/18/html/runtime-config-logging.html","sha256":"a322f5293f10e348b5fc5dca98fdb6af52462723a215b8701c3b9d933e2933b4"}],"kind":"same-version-pgdoc","locale":"zh-Hans","source_revision":"b1b500221dbe5437cfca004d6b04d3f6e422765d","version":"18"},"unit":null,"vartype":"bool","zh_from":"same-version-manual"},"ManualEvidence":{"doc":{"anchor":"GUC-LOG-TRUNCATE-ON-ROTATION","file":"runtime-config-logging.html","lang":"en","sha256":"278d913b9c0f735c5cd7b35fd7205826bbd9c449805370d2dbe54105c0ed1d88","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"log_truncate_on_rotation","SourceDatabase":"center","Version":"18","Locale":"en","Title":"log_truncate_on_rotation","Summary":"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.","BodyHTML":"\u003cp\u003e\n        When \u003ccode\u003elogging_collector\u003c/code\u003e is enabled,\n        this parameter will cause \u003cspan\u003ePostgreSQL\u003c/span\u003e to truncate (overwrite),\n        rather than append to, any existing log file of the same name.\n        However, truncation will occur only when a new file is being opened\n        due to time-based rotation, not during server startup or size-based\n        rotation.  When off, pre-existing files will be appended to in\n        all cases.  For example, using this setting in combination with\n        a \u003ccode\u003elog_filename\u003c/code\u003e like \u003ccode\u003epostgresql-%H.log\u003c/code\u003e\n        would result in generating twenty-four hourly log files and then\n        cyclically overwriting them.\n        This parameter can only be set in the \u003ccode\u003epostgresql.conf\u003c/code\u003e\n        file or on the server command line.\n       \u003c/p\u003e\u003cp\u003e\n        Example:  To keep 7 days of logs, one log file per day named\n        \u003ccode\u003eserver_log.Mon\u003c/code\u003e, \u003ccode\u003eserver_log.Tue\u003c/code\u003e,\n        etc., and automatically overwrite last week\u0026#39;s log with this week\u0026#39;s log,\n        set \u003ccode\u003elog_filename\u003c/code\u003e to \u003ccode\u003eserver_log.%a\u003c/code\u003e,\n        \u003ccode\u003elog_truncate_on_rotation\u003c/code\u003e to \u003ccode\u003eon\u003c/code\u003e, and\n        \u003ccode\u003elog_rotation_age\u003c/code\u003e to \u003ccode\u003e1440\u003c/code\u003e.\n       \u003c/p\u003e\u003cp\u003e\n        Example: To keep 24 hours of logs, one log file per hour, but\n        also rotate sooner if the log file size exceeds 1GB, set\n        \u003ccode\u003elog_filename\u003c/code\u003e to \u003ccode\u003eserver_log.%H%M\u003c/code\u003e,\n        \u003ccode\u003elog_truncate_on_rotation\u003c/code\u003e to \u003ccode\u003eon\u003c/code\u003e,\n        \u003ccode\u003elog_rotation_age\u003c/code\u003e to \u003ccode\u003e60\u003c/code\u003e, and\n        \u003ccode\u003elog_rotation_size\u003c/code\u003e to \u003ccode\u003e1000000\u003c/code\u003e.\n        Including \u003ccode\u003e%M\u003c/code\u003e in \u003ccode\u003elog_filename\u003c/code\u003e allows\n        any size-driven rotations that might occur to select a file name\n        different from the hour\u0026#39;s initial file name.\n       \u003c/p\u003e","SourceRevision":"wiki-repair-20261023:ba2ed9297627c0b3b3d638cc60d015596b3a7ada38de45dbab54b7169423cf33","ContentHash":"669fca81d127849acd85d63a55b4f1ec7df740bc906e7e4f2eebfdd958980e46","Payload":{"description":"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."}},"RequestedLocale":"en","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","8.0","8.1","8.2","8.3","8.4","9.0","9.1","9.2","9.3","9.4","9.5","9.6"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
