{"Entry":{"collection":"guc","key":"log_min_duration_statement","name":"log_min_duration_statement","aliases":[],"metadata":{"baseline":true,"boot_human":"Not specified","boot_val":null,"category":"Reporting and Logging / When to Log","category_zh":"","changed_in":["9.1","13","18"],"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":false,"fields":{"max_val":{"from":"2147483","to":"2147483647"}},"from":"9.0","status":"changed","to":"9.1"},{"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":{"short_desc":{"from":"Sets the minimum execution time above which statements will be logged.","to":"Sets the minimum execution time above which all statements will be logged."}},"from":"12","status":"changed","to":"13"},{"documentation_changed":true,"fields":{},"from":"14","status":"changed","to":"15"},{"documentation_changed":false,"fields":{"extra_desc":{"from":"Zero prints all queries. -1 turns this feature off.","to":"-1 disables logging statement durations. 0 means log all statement durations."}},"from":"17","status":"changed","to":"18"}],"content_hash":"3b10427d81cedbbe135d2e2270fd3a52bf83d7d726f698daebbec93dd5156681","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"-1 ms"}],"editorial":{"advice":{"olap":"Use a higher threshold so normal long analytical work does not flood logs. Pair logs with query identifiers and workload labels so repeated reports remain actionable.","oltp":"Choose a threshold from the application's latency objective and expected log volume. At high QPS, combine a meaningful hard threshold with sampled logging for the faster population.","small":"A low threshold can be useful while tuning, but watch disk use and rotation. Raise it or switch to sampling when logging becomes a measurable part of the workload."},"mechanism":["The value is a duration in milliseconds when no unit is written. A value of -1 disables duration-based statement logging, zero logs every completed statement, and a positive value logs statements at or above the threshold.","Statements selected by this setting are always logged rather than sampled, so it takes priority over log_min_duration_sample. Under the extended query protocol, Parse, Bind, and Execute durations can appear separately.","This parameter observes and records completed work; it does not stop slow statements. statement_timeout is the separate execution-cancellation control."],"pitfalls":["Low thresholds on high-throughput systems can create extreme log volume and I/O.","SQL text can contain sensitive literals and must be protected like application data.","It logs slow statements but does not cancel them; use statement_timeout for that goal.","Extended-protocol phases may be logged separately and need session or PID correlation.","Interactions with log_statement, sampling, and log_line_prefix can confuse duplicate or fragmented entries."],"references":[{"title":"PostgreSQL 19 Beta 4: log_min_duration_statement","url":"https://www.postgresql.org/docs/19/runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["log_min_duration_sample","log_statement_sample_rate","log_statement","log_duration","log_line_prefix","statement_timeout"],"summary":"Logs every completed statement whose duration reaches a threshold. It is a deterministic slow-query capture control, distinct from sampling and from statement cancellation."},"enumvals":[],"first_version":"7.4","group":"Reporting and Logging","group_slug":"logging","imported_at":"2026-09-30T00:40:57.372895+08:00","intro_commit":{},"key":"log_min_duration_statement","last_version":"20","max_val":"","min_val":"","name":"log_min_duration_statement","position":234,"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 each completed statement to be logged if the statement ran for at least the specified amount of time.","short_desc_zh":"","source_rev":"english-manuals:fdebca34be71f61151c222ec85c85943c9d2c616b0719bcdb6847bf394fdddcc","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"log_min_duration_statement","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"log_min_duration_statement","SourceRevision":"english-manuals:fdebca34be71f61151c222ec85c85943c9d2c616b0719bcdb6847bf394fdddcc","Facts":{"boot_val":"-1","category":"Reporting and Logging / When to Log","context":"superuser","description":"Causes the duration of each completed statement to be logged if the statement ran for at least the specified amount of time. For example, if you set it to 250ms then all SQL statements that run 250ms or longer will be logged. Enabling this parameter can be helpful in tracking down unoptimized queries in your applications. If this value is specified without units, it is taken as milliseconds. Setting this to zero prints all statement durations. -1 (the default) disables logging statement durations. Only superusers and users with the appropriate SET privilege can change this setting. This overrides log_min_duration_sample, meaning that queries with duration exceeding this setting are not subject to sampling and are always logged. For clients using extended query protocol, durations of the Parse, Bind, and Execute steps are logged independently. Note When using this option together with log_statement, the text of statements that are logged because of log_statement will not be repeated in the duration log message. If you are not using syslog, it is recommended that you log the PID or session ID using log_line_prefix so that you can link the statement message to the later duration message using the process ID or session ID.","doc":{"anchor":"GUC-LOG-MIN-DURATION-STATEMENT","file":"runtime-config-logging.html","lang":"en","sha256":"93c48c522a72fca19705c4c91a71e951eae653662008eee2e4a9a74a11127fde","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"-1 disables logging statement durations. 0 means log all statement durations.","lang":"en","max_val":"2147483647","metadata_version":"18","min_val":"-1","name":"log_min_duration_statement","short_desc":"Sets the minimum execution time above which all statements will be logged.","source":"pg-settings-source-snapshot","unit":"ms","vartype":"integer"},"ManualEvidence":{"doc":{"anchor":"GUC-LOG-MIN-DURATION-STATEMENT","file":"runtime-config-logging.html","lang":"en","sha256":"93c48c522a72fca19705c4c91a71e951eae653662008eee2e4a9a74a11127fde","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"log_min_duration_statement","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"log_min_duration_statement","Summary":"","BodyHTML":"\u003cp\u003e记录每个已完成语句的持续时间，如果语句运行时间至少达到指定时间。例如，如果将其设置为\u003ccode\u003e250ms\u003c/code\u003e，那么所有运行时间为250ms或更长的SQL语句将被记录。启用此参数可帮助跟踪应用程序中的未优化查询。如果未指定单位，则将其视为毫秒。将此值设置为零将打印所有语句持续时间。\u003ccode\u003e-1\u003c/code\u003e（默认值）禁用记录语句持续时间。只有超级用户和具有适当\u003ccode\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e\u003cp\u003e这会覆盖\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-MIN-DURATION-SAMPLE\" rel=\"nofollow\"\u003elog_min_duration_sample\u003c/a\u003e，意味着持续时间超过此设置的查询不进行抽样，并且始终被记录。\u003c/p\u003e\u003cp\u003e对于使用扩展查询协议的客户端，Parse、Bind 和 Execute 步骤的持续时间将被独立记录。\u003c/p\u003e\u003cdiv\u003e\n注意\u003cp\u003e当把这个选项和\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-STATEMENT\" rel=\"nofollow\"\u003elog_statement\u003c/a\u003e一起使用时，已经被\u003ccode\u003elog_statement\u003c/code\u003e记录的语句文本不会在持续时间日志消息中重复。如果你没有使用\u003cspan\u003esyslog\u003c/span\u003e，我们推荐你使用\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\" rel=\"nofollow\"\u003elog_line_prefix\u003c/a\u003e记录 PID 或会话 ID，这样你可以使用进程 ID 或会话 ID 把语句消息链接到后来的持续时间消息。\u003c/p\u003e\u003c/div\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"e087e0416f5849987299797aca4a495e75c231c2de8cf2b5f6f74d45ec024625","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e记录每个已完成语句的持续时间，如果语句运行时间至少达到指定时间。例如，如果将其设置为\u003ccode class=\"literal\"\u003e250ms\u003c/code\u003e，那么所有运行时间为250ms或更长的SQL语句将被记录。启用此参数可帮助跟踪应用程序中的未优化查询。如果未指定单位，则将其视为毫秒。将此值设置为零将打印所有语句持续时间。\u003ccode class=\"literal\"\u003e-1\u003c/code\u003e（默认值）禁用记录语句持续时间。只有超级用户和具有适当\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e\u003cp\u003e这会覆盖\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-MIN-DURATION-SAMPLE\"\u003elog_min_duration_sample\u003c/a\u003e，意味着持续时间超过此设置的查询不进行抽样，并且始终被记录。\u003c/p\u003e\u003cp\u003e对于使用扩展查询协议的客户端，Parse、Bind 和 Execute 步骤的持续时间将被独立记录。\u003c/p\u003e\u003cdiv class=\"note\"\u003e\n注意\u003cp\u003e当把这个选项和\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-STATEMENT\"\u003elog_statement\u003c/a\u003e一起使用时，已经被\u003ccode class=\"varname\"\u003elog_statement\u003c/code\u003e记录的语句文本不会在持续时间日志消息中重复。如果你没有使用\u003cspan class=\"application\"\u003esyslog\u003c/span\u003e，我们推荐你使用\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-LINE-PREFIX\"\u003elog_line_prefix\u003c/a\u003e记录 PID 或会话 ID，这样你可以使用进程 ID 或会话 ID 把语句消息链接到后来的持续时间消息。\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}
