{"Entry":{"collection":"guc","key":"log_statement_sample_rate","name":"log_statement_sample_rate","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Reporting and Logging / When to Log","category_zh":"","changed_in":["17"],"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":{"short_desc":{"from":"Fraction of statements exceeding log_min_duration_sample to be logged.","to":"Fraction of statements exceeding \"log_min_duration_sample\" to be logged."}},"from":"16","status":"changed","to":"17"}],"content_hash":"bd889bb26374f9518641beee989278a99de041e18699f16947f05dd0be38fc7f","context":"","default_changed_in":[],"default_history":[{"from":"13","to":"19","value":"1"}],"editorial":{"advice":{"olap":"Analytical jobs can justify richer log_statement_sample_rate telemetry, but account for long statements, large bind values, and bursty completion patterns in the log pipeline.","oltp":"Tune log_statement_sample_rate 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_statement_sample_rate useful but bounded: verify disk, collector, retention, and redaction capacity before increasing detail or frequency."},"mechanism":["log_statement_sample_rate sets the fraction of statements exceeding \"log_min_duration_sample\" to be logged. Use a value between 0.0 (never log) and 1.0 (always log). This probability is evaluated only for statements admitted by log_min_duration_sample; it does not sample log_statement or log_min_duration_statement output.","log_statement_sample_rate 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_statement_sample_rate 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 it to sample all statement logging even though it only gates log_min_duration_sample."],"references":[{"title":"PostgreSQL 19 Beta 4: log_statement_sample_rate","url":"https://www.postgresql.org/docs/19/runtime-config-logging.html#GUC-LOG-STATEMENT-SAMPLE-RATE"},{"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_min_duration_sample","log_transaction_sample_rate"],"summary":"log_statement_sample_rate is the PostgreSQL setting that defines the fraction of statements exceeding \"log_min_duration_sample\" to be logged."},"enumvals":[],"first_version":"13","group":"Reporting and Logging","group_slug":"logging","imported_at":"2026-09-30T00:40:57.431624+08:00","intro_commit":{"authored_at":"2018-11-29T18:42:53-03:00","discussion":["https://postgr.es/m/c30ee535-ee1e-db9f-fa97-146b9f62caed@anayrat.info"],"hash":"88bdbd3f746049834ae3cc972e6e650586ec3c9d","subject":"Add log_statement_sample_rate parameter","url":"https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=88bdbd3f746049834ae3cc972e6e650586ec3c9d"},"key":"log_statement_sample_rate","last_version":"20","max_val":"","min_val":"","name":"log_statement_sample_rate","position":250,"present_in":["13","14","15","16","17","18","19","20"],"short_desc":"Determines the fraction of statements with duration exceeding log_min_duration_sample that will be logged.","short_desc_zh":"","source_rev":"english-manuals:866f9a8be7a13da592593031b07e854bbb245b052650a3125c0d17ba0d13dbec","unit":"","vartype":"real"}},"Definition":{"Collection":"guc","Key":"log_statement_sample_rate","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"log_statement_sample_rate","SourceRevision":"english-manuals:866f9a8be7a13da592593031b07e854bbb245b052650a3125c0d17ba0d13dbec","Facts":{"boot_val":"1","category":"Reporting and Logging / When to Log","context":"superuser","description":"Determines the fraction of statements with duration exceeding log_min_duration_sample that will be logged. Sampling is stochastic, for example 0.5 means there is statistically one chance in two that any given statement will be logged. The default is 1.0, meaning to log all sampled statements. Setting this to zero disables sampled statement-duration logging, the same as setting log_min_duration_sample to -1. Only superusers and users with the appropriate SET privilege can change this setting.","doc":{"anchor":"GUC-LOG-STATEMENT-SAMPLE-RATE","file":"runtime-config-logging.html","lang":"en","sha256":"93c48c522a72fca19705c4c91a71e951eae653662008eee2e4a9a74a11127fde","slug":"18"},"documented":true,"enumvals":null,"extra_desc":"Use a value between 0.0 (never log) and 1.0 (always log).","lang":"en","max_val":"1","metadata_version":"18","min_val":"0","name":"log_statement_sample_rate","short_desc":"Fraction of statements exceeding \"log_min_duration_sample\" to be logged.","source":"pg-settings-source-snapshot","unit":null,"vartype":"real"},"ManualEvidence":{"doc":{"anchor":"GUC-LOG-STATEMENT-SAMPLE-RATE","file":"runtime-config-logging.html","lang":"en","sha256":"93c48c522a72fca19705c4c91a71e951eae653662008eee2e4a9a74a11127fde","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"log_statement_sample_rate","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"log_statement_sample_rate","Summary":"","BodyHTML":"\u003cp\u003e确定持续时间超过\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-MIN-DURATION-SAMPLE\" rel=\"nofollow\"\u003elog_min_duration_sample\u003c/a\u003e的语句中，将被记录的语句比例。采样是随机的，例如\u003ccode\u003e0.5\u003c/code\u003e表示任意给定语句被记录的统计概率为二分之一。默认值为\u003ccode\u003e1.0\u003c/code\u003e，表示记录所有采样的语句。将此设置为零将禁用采样语句持续时间记录，与将\u003ccode\u003elog_min_duration_sample\u003c/code\u003e设置为\u003ccode\u003e-1\u003c/code\u003e相同。只有超级用户和具有适当\u003ccode\u003eSET\u003c/code\u003e权限的用户才能更改此设置。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"a44d78d721a3d4c5e7add4d7692dccfb05f0afe391f451259a0e51037f3baebc","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e确定持续时间超过\u003ca href=\"/docs/18/runtime-config-logging.html#GUC-LOG-MIN-DURATION-SAMPLE\"\u003elog_min_duration_sample\u003c/a\u003e的语句中，将被记录的语句比例。采样是随机的，例如\u003ccode class=\"literal\"\u003e0.5\u003c/code\u003e表示任意给定语句被记录的统计概率为二分之一。默认值为\u003ccode class=\"literal\"\u003e1.0\u003c/code\u003e，表示记录所有采样的语句。将此设置为零将禁用采样语句持续时间记录，与将\u003ccode class=\"varname\"\u003elog_min_duration_sample\u003c/code\u003e设置为\u003ccode class=\"literal\"\u003e-1\u003c/code\u003e相同。只有超级用户和具有适当\u003ccode class=\"literal\"\u003eSET\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}
