{"Entry":{"collection":"guc","key":"log_duration","name":"log_duration","aliases":[],"metadata":{"baseline":true,"boot_human":"Not specified","boot_val":null,"category":"Reporting and Logging / What to Log","category_zh":"","changed_in":[],"changes":[{"documentation_changed":true,"fields":{},"from":"7.4","status":"changed","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":"9.6","status":"changed","to":"10"},{"documentation_changed":true,"fields":{},"from":"11","status":"changed","to":"12"},{"documentation_changed":true,"fields":{},"from":"14","status":"changed","to":"15"}],"content_hash":"be9cdd79ef4903cb38c076dd8a8c5303c7d014fc84ee023ff6663ecefb6891ba","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"off"}],"editorial":{"advice":{"olap":"Analytical jobs can justify richer log_duration telemetry, but account for long statements, large bind values, and bursty completion patterns in the log pipeline.","oltp":"Tune log_duration against an explicit observability question and a measured log-volume budget. Prefer selective thresholds, sampling, or role-level overrides over indiscriminate capture.","small":"Keep log_duration useful but bounded: verify disk, collector, retention, and redaction capacity before increasing detail or frequency."},"mechanism":["log_duration logs the duration of each completed SQL statement. It emits a duration for every completed statement but does not itself emit statement text; log_statement or a duration threshold supplies text when required.","log_duration is a SUPERUSER-context setting. Superuser or a role granted the appropriate SET privilege can change it for a session, while ALTER ROLE or ALTER DATABASE can establish a default for future sessions.","It changes emitted diagnostic data rather than query semantics, but volume, sensitive content, log_line_prefix, destinations, collector throughput, and retention determine operational cost and usefulness."],"pitfalls":["Changing log_duration in one session and assuming role defaults, database defaults, or other pooled sessions changed with it.","Enabling richer logging without budgeting collector throughput, storage, retention, and downstream query cost.","Writing SQL text, bind values, identities, or host data without a redaction and access-control policy.","Expecting duration records to contain SQL text when no statement-logging setting emits that text."],"references":[{"title":"PostgreSQL 19 Beta 4: log_duration","url":"https://www.postgresql.org/docs/19/runtime-config-logging.html#GUC-LOG-DURATION"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["log_statement","log_connections","log_disconnections","log_parameter_max_length","log_parameter_max_length_on_error"],"summary":"log_duration is the PostgreSQL setting that controls whether PostgreSQL logs the duration of each completed SQL statement."},"enumvals":[],"first_version":"7.4","group":"Reporting and Logging","group_slug":"logging","imported_at":"2026-09-30T00:40:57.315129+08:00","intro_commit":{},"key":"log_duration","last_version":"20","max_val":"","min_val":"","name":"log_duration","position":224,"present_in":["7.4","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"],"short_desc":"Causes the duration of every completed statement to be logged.","short_desc_zh":"","source_rev":"english-manuals:22e0f88412ecb4e9705d9d059ada00c183b8b57c6e7a884b207936a5e0b73014","unit":"","vartype":"bool"}},"Definition":{"Collection":"guc","Key":"log_duration","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"log_duration","SourceRevision":"english-manuals:22e0f88412ecb4e9705d9d059ada00c183b8b57c6e7a884b207936a5e0b73014","Facts":{"boot_val":"off","category":"Reporting and Logging / What to Log","context":"superuser","description":"Causes the duration of every completed statement to be logged. The default is off. Only superusers and users with the appropriate SET privilege can change this setting. For clients using extended query protocol, durations of the Parse, Bind, and Execute steps are logged independently. Note The difference between enabling log_duration and setting log_min_duration_statement to zero is that exceeding log_min_duration_statement forces the text of the query to be logged, but this option doesn't. Thus, if log_duration is on and log_min_duration_statement has a positive value, all durations are logged but the query text is included only for statements exceeding the threshold. This behavior can be useful for gathering statistics in high-load installations.","doc":{"anchor":"GUC-LOG-DURATION","file":"runtime-config-logging.html","lang":"en","sha256":"93c48c522a72fca19705c4c91a71e951eae653662008eee2e4a9a74a11127fde","slug":"18"},"documented":true,"enumvals":null,"extra_desc":null,"lang":"en","max_val":null,"metadata_version":"18","min_val":null,"name":"log_duration","short_desc":"Logs the duration of each completed SQL statement.","source":"pg-settings-source-snapshot","unit":null,"vartype":"bool"},"ManualEvidence":{"doc":{"anchor":"GUC-LOG-DURATION","file":"runtime-config-logging.html","lang":"en","sha256":"93c48c522a72fca19705c4c91a71e951eae653662008eee2e4a9a74a11127fde","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"log_duration","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"log_duration","Summary":"","BodyHTML":"\u003cp\u003e记录每个已完成语句的持续时间。默认值为\u003ccode\u003eoff\u003c/code\u003e。只有超级用户和具有适当\u003ccode\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e\u003cp\u003e对于使用扩展查询协议的客户端，Parse、Bind 和 Execute 步骤的持续时间将被独立记录。\u003c/p\u003e\u003cdiv\u003e\n注意\u003cp\u003e启用\u003ccode\u003elog_duration\u003c/code\u003e和设置\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT\" rel=\"nofollow\"\u003elog_min_duration_statement\u003c/a\u003e为零之间的区别是，超过\u003ccode\u003elog_min_duration_statement\u003c/code\u003e指定的时长会强制记录查询文本，而这个选项不会。因此，如果\u003ccode\u003elog_duration\u003c/code\u003e为\u003ccode\u003eon\u003c/code\u003e并且\u003ccode\u003elog_min_duration_statement\u003c/code\u003e为正值，所有持续时间都将被记录，但是只有超过阈值的语句才会被记录查询文本。这种行为有助于在高负载安装中收集统计信息。\u003c/p\u003e\u003c/div\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"043cb25310bb378777758c29a8f448f5dc1836550ac74c3bdd56e9e1cfed62a0","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e记录每个已完成语句的持续时间。默认值为\u003ccode class=\"literal\"\u003eoff\u003c/code\u003e。只有超级用户和具有适当\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e\u003cp\u003e对于使用扩展查询协议的客户端，Parse、Bind 和 Execute 步骤的持续时间将被独立记录。\u003c/p\u003e\u003cdiv class=\"note\"\u003e\n注意\u003cp\u003e启用\u003ccode class=\"varname\"\u003elog_duration\u003c/code\u003e和设置\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT\"\u003elog_min_duration_statement\u003c/a\u003e为零之间的区别是，超过\u003ccode class=\"varname\"\u003elog_min_duration_statement\u003c/code\u003e指定的时长会强制记录查询文本，而这个选项不会。因此，如果\u003ccode class=\"varname\"\u003elog_duration\u003c/code\u003e为\u003ccode class=\"literal\"\u003eon\u003c/code\u003e并且\u003ccode class=\"varname\"\u003elog_min_duration_statement\u003c/code\u003e为正值，所有持续时间都将被记录，但是只有超过阈值的语句才会被记录查询文本。这种行为有助于在高负载安装中收集统计信息。\u003c/p\u003e\u003c/div\u003e","doc_same_as":""}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","7.4","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}
