{"Entry":{"collection":"guc","key":"log_min_duration_sample","name":"log_min_duration_sample","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Reporting and Logging / When to Log","category_zh":"","changed_in":["18"],"changes":[{"documentation_changed":false,"fields":{},"from":"12","status":"added","to":"13"},{"documentation_changed":true,"fields":{},"from":"14","status":"changed","to":"15"},{"documentation_changed":false,"fields":{"extra_desc":{"from":"Zero logs a sample of all queries. -1 turns this feature off.","to":"-1 disables sampling. 0 means sample all statements."},"short_desc":{"from":"Sets the minimum execution time above which a sample of statements will be logged. Sampling is determined by log_statement_sample_rate.","to":"Sets the minimum execution time above which a sample of statements will be logged. Sampling is determined by \"log_statement_sample_rate\"."}},"from":"17","status":"changed","to":"18"}],"content_hash":"7d242f4b8ec289beab5ed59ebedb265fc363cf055c56b4505303a5afaa7ddf2d","context":"","default_changed_in":[],"default_history":[{"from":"13","to":"19","value":"-1 ms"}],"editorial":{"advice":{"olap":"Long analytical queries often exceed the always-log threshold, so sampling may provide no reduction for them. Choose thresholds from the duration distribution rather than copying OLTP values.","oltp":"Set an always-log threshold first with log_min_duration_statement, then use a lower sample threshold and measured rate for the high-volume middle band. Verify actual sample counts and sensitive-data handling under peak OLTP traffic.","small":"Use a conservative rate and bounded statement text. A small node should avoid zero with rate 1 unless it intentionally wants every statement-duration entry."},"mechanism":["log_min_duration_sample admits completed statements at or above its duration threshold into stochastic logging controlled by log_statement_sample_rate. -1 disables this path, zero admits every completed statement, and the sample rate then decides which admitted statements are emitted.","log_min_duration_statement has higher priority. A statement that reaches its threshold is always logged and is not sampled, even if it also exceeds log_min_duration_sample. Under the extended query protocol, Parse, Bind, and Execute durations are logged separately.","It is a SUPERUSER-context session setting. Sampled entries have the same statement-text, Bind-value, correlation, overhead, and security considerations as log_min_duration_statement, so log_line_prefix and log_parameter_max_length still determine usefulness and exposure."],"pitfalls":["Expecting sampling to affect statements already captured by the higher-priority log_min_duration_statement threshold.","Forgetting that Parse, Bind, and Execute are timed and logged separately with the extended query protocol.","Setting zero with log_statement_sample_rate = 1 and unintentionally logging every completed statement duration.","Sampling SQL and Bind values without correlation identifiers, redaction, access control, and a measured volume budget."],"references":[{"title":"PostgreSQL 19 Beta 4: log_min_duration_sample","url":"https://www.postgresql.org/docs/19/runtime-config-logging.html#GUC-LOG-MIN-DURATION-SAMPLE"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["log_min_messages","log_min_error_statement","log_min_duration_statement","log_statement_sample_rate","log_transaction_sample_rate"],"summary":"log_min_duration_sample is the PostgreSQL setting that defines the minimum execution time above which a sample of statements will be logged. Sampling is determined by \"log_statement_sample_rate\"."},"enumvals":[],"first_version":"13","group":"Reporting and Logging","group_slug":"logging","imported_at":"2026-09-30T00:40:57.368965+08:00","intro_commit":{"authored_at":"2019-11-04T01:57:45+01:00","discussion":["https://postgr.es/m/bbe0a1a8-a8f7-3be2-155a-888e661cc06c@anayrat.info"],"hash":"6e3e6cc0e884a6091e1094dff29db430af08fb93","subject":"Allow sampling of statements depending on duration","url":"https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=6e3e6cc0e884a6091e1094dff29db430af08fb93"},"key":"log_min_duration_sample","last_version":"20","max_val":"","min_val":"","name":"log_min_duration_sample","position":233,"present_in":["13","14","15","16","17","18","19","20"],"short_desc":"Allows sampling the duration of completed statements that ran for at least the specified amount of time.","short_desc_zh":"","source_rev":"english-manuals:1e9abfb3e8292988a372b32947a3f39733a34f3847d0b4383d0b3648374c1b5e","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"log_min_duration_sample","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"log_min_duration_sample","SourceRevision":"english-manuals:1e9abfb3e8292988a372b32947a3f39733a34f3847d0b4383d0b3648374c1b5e","Facts":{"boot_val":"-1","category":"Reporting and Logging / When to Log","context":"superuser","description":"Allows sampling the duration of completed statements that ran for at least the specified amount of time. This produces the same kind of log entries as log_min_duration_statement, but only for a subset of the executed statements, with sample rate controlled by log_statement_sample_rate. For example, if you set it to 100ms then all SQL statements that run 100ms or longer will be considered for sampling. Enabling this parameter can be helpful when the traffic is too high to log all queries. If this value is specified without units, it is taken as milliseconds. Setting this to zero samples all statement durations. -1 (the default) disables sampling statement durations. Only superusers and users with the appropriate SET privilege can change this setting. This setting has lower priority than log_min_duration_statement, meaning that statements with durations exceeding log_min_duration_statement are not subject to sampling and are always logged. Other notes for log_min_duration_statement apply also to this setting.","doc":{"anchor":"GUC-LOG-MIN-DURATION-SAMPLE","file":"runtime-config-logging.html","lang":"en","sha256":"93c48c522a72fca19705c4c91a71e951eae653662008eee2e4a9a74a11127fde","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"-1 disables sampling. 0 means sample all statements.","lang":"en","max_val":"2147483647","metadata_version":"18","min_val":"-1","name":"log_min_duration_sample","short_desc":"Sets the minimum execution time above which a sample of statements will be logged. Sampling is determined by \"log_statement_sample_rate\".","source":"pg-settings-source-snapshot","unit":"ms","vartype":"integer"},"ManualEvidence":{"doc":{"anchor":"GUC-LOG-MIN-DURATION-SAMPLE","file":"runtime-config-logging.html","lang":"en","sha256":"93c48c522a72fca19705c4c91a71e951eae653662008eee2e4a9a74a11127fde","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"log_min_duration_sample","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"log_min_duration_sample","Summary":"","BodyHTML":"\u003cp\u003e允许对运行时间至少达到指定时间的已完成语句进行采样。这会产生与\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT\" rel=\"nofollow\"\u003elog_min_duration_statement\u003c/a\u003e相同类型的日志条目，但仅针对已执行语句的子集，采样率由\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-STATEMENT-SAMPLE-RATE\" rel=\"nofollow\"\u003elog_statement_sample_rate\u003c/a\u003e控制。例如，如果将其设置为\u003ccode\u003e100ms\u003c/code\u003e，那么运行时间达到100ms或更长的所有 SQL语句都将被考虑进行采样。启用此参数在流量过高无法记录所有查询时很有帮助。如果未指定单位，则将其视为毫秒。将其设置为零会对所有语句持续时间进行采样。\u003ccode\u003e-1\u003c/code\u003e（默认值）禁用语句持续时间的采样。只有超级用户和具有适当\u003ccode\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e\u003cp\u003e此设置的优先级低于 \u003ccode\u003elog_min_duration_statement\u003c/code\u003e，意味着持续时间超过 \u003ccode\u003elog_min_duration_statement\u003c/code\u003e 的语句不被采样，并且始终被记录。\u003c/p\u003e\u003cp\u003e\u003ccode\u003elog_min_duration_statement\u003c/code\u003e的其他说明也适用于此设置。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"d132cee8cc8590cb7d0de6fa4b6225fac6b1d1566477dc3d70db30ccdd1eaa2f","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e允许对运行时间至少达到指定时间的已完成语句进行采样。这会产生与\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-MIN-DURATION-STATEMENT\"\u003elog_min_duration_statement\u003c/a\u003e相同类型的日志条目，但仅针对已执行语句的子集，采样率由\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-STATEMENT-SAMPLE-RATE\"\u003elog_statement_sample_rate\u003c/a\u003e控制。例如，如果将其设置为\u003ccode class=\"literal\"\u003e100ms\u003c/code\u003e，那么运行时间达到100ms或更长的所有 SQL语句都将被考虑进行采样。启用此参数在流量过高无法记录所有查询时很有帮助。如果未指定单位，则将其视为毫秒。将其设置为零会对所有语句持续时间进行采样。\u003ccode class=\"literal\"\u003e-1\u003c/code\u003e（默认值）禁用语句持续时间的采样。只有超级用户和具有适当\u003ccode class=\"literal\"\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e\u003cp\u003e此设置的优先级低于 \u003ccode class=\"varname\"\u003elog_min_duration_statement\u003c/code\u003e，意味着持续时间超过 \u003ccode class=\"varname\"\u003elog_min_duration_statement\u003c/code\u003e 的语句不被采样，并且始终被记录。\u003c/p\u003e\u003cp\u003e\u003ccode class=\"varname\"\u003elog_min_duration_statement\u003c/code\u003e的其他说明也适用于此设置。\u003c/p\u003e","doc_same_as":""}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["13","14","15","16","17","18","19","20"],"Locales":["en","zh-Hans"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
