{"Entry":{"collection":"guc","key":"log_statement","name":"log_statement","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":"8.4","status":"changed","to":"9.0"},{"documentation_changed":true,"fields":{},"from":"9.6","status":"changed","to":"10"},{"documentation_changed":true,"fields":{},"from":"14","status":"changed","to":"15"}],"content_hash":"8873b7cb722a99ac95420306f6ca5387d9d0c746fbceaebd98365105fc0a8ed6","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"none"}],"derived_content_hash":"a4ee95cb939ef7f15c2644bc4393fd2b01ff339b146b9d21d1abfd463a3fd2f8","documentation_refresh":{"batch":"20261113","original_source_rev":"wiki-repair-20261023:e3c328d21138ffe93c38fba42e7e784d70f7c559489cd0d3da24af4cf1731222","versions":{"14":"14.25","15":"15.20","16":"16.16","17":"17.12","18":"18.7","19":"19rc2"}},"editorial":{"advice":{"olap":"Use a role- or session-scoped window for analytical troubleshooting rather than all cluster-wide. Long generated SQL and large Bind values can dominate logs and expose source data.","oltp":"Keep none or ddl as the routine OLTP baseline and use duration thresholds or sampling for query performance. Before enabling mod/all, test volume and a concrete redaction/access policy for SQL text and Bind values.","small":"Prefer ddl or targeted thresholds; all can overwhelm disk and reveal secrets even on a quiet node. Keep log_min_error_statement configured for syntax/parse failures that log_statement misses."},"mechanism":["log_statement selects none, ddl, mod, or all. ddl logs data-definition commands; mod adds data-changing commands; all logs every statement that reaches the logging point. PREPARE, EXECUTE, and EXPLAIN ANALYZE follow the contained command's class.","With the extended query protocol, logging occurs when Execute is received and includes Bind parameter values. Even all does not log a simple statement that fails basic parsing, nor an extended-protocol statement that fails before Execute during parse analysis or planning; log_min_error_statement is required for those error paths.","It is a SUPERUSER-context session setting. Statement text and Bind values can expose personal data, tokens, and even plaintext passwords, so selection, access, redaction, transport, and retention must be treated as a security control as well as an observability choice."],"pitfalls":["Assuming all captures syntax errors or extended-protocol failures before Execute; use log_min_error_statement for those paths.","Forgetting that extended-protocol Execute logging includes Bind parameter values.","Logging SQL that contains plaintext passwords, bearer tokens, personal data, or application secrets without redaction and strict access controls.","Enabling mod or all cluster-wide without bounding log throughput, disk, shipping, and retention."],"references":[{"title":"PostgreSQL 19 Beta 4: log_statement","url":"https://www.postgresql.org/docs/19/runtime-config-logging.html#GUC-LOG-STATEMENT"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["log_duration","log_connections","log_disconnections","log_parameter_max_length","log_parameter_max_length_on_error"],"summary":"log_statement is the PostgreSQL setting that defines the type of statements logged."},"enumvals":[],"first_version":"7.4","group":"Reporting and Logging","group_slug":"logging","imported_at":"2026-09-30T00:40:57.424283+08:00","intro_commit":{},"key":"log_statement","last_version":"20","max_val":"","min_val":"","name":"log_statement","position":248,"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"],"repair_provenance":{"original_source_revision":"english-manuals:e508595a6e8a9fa5632925c1b0f3fba27530ba318837253996624a821c6b5d09","receipt_sha256":"9733d3da4b5479921791bc49b5e2859280442c3dc24fd512829261b1dc278e39","repair":"wiki-repair-20261023"},"short_desc":"Controls which SQL statements are logged.","short_desc_zh":"","source_rev":"wiki-repair-20261023:e3c328d21138ffe93c38fba42e7e784d70f7c559489cd0d3da24af4cf1731222","unit":"","vartype":"enum"}},"Definition":{"Collection":"guc","Key":"log_statement","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"log_statement","SourceRevision":"wiki-repair-20261023:e3c328d21138ffe93c38fba42e7e784d70f7c559489cd0d3da24af4cf1731222","Facts":{"boot_val":"none","category":"Reporting and Logging / What to Log","context":"superuser","description":"Controls which SQL statements are logged. Valid values are none (off), ddl, mod, and all (all statements). ddl logs all data definition statements, such as CREATE, ALTER, and DROP statements. mod logs all ddl statements, plus data-modifying statements such as INSERT, UPDATE, DELETE, TRUNCATE, and COPY FROM. PREPARE, EXECUTE, and EXPLAIN ANALYZE statements are also logged if their contained command is of an appropriate type. For clients using extended query protocol, logging occurs when an Execute message is received, and values of the Bind parameters are included (with any embedded single-quote marks doubled). The default is none. Only superusers and users with the appropriate SET privilege can change this setting. Note Statements that contain simple syntax errors are not logged even by the log_statement = all setting, because the log message is emitted only after basic parsing has been done to determine the statement type. In the case of extended query protocol, this setting likewise does not log statements that fail before the Execute phase (i.e., during parse analysis or planning). Set log_min_error_statement to ERROR (or lower) to log such statements. Logged statements might reveal sensitive data and even contain plaintext passwords.","description_zh":"控制哪些 SQL 语句被记录。有效值是 none (off)、ddl、mod 和 all（所有语句）。ddl 记录所有数据定义语句，例如 CREATE、ALTER 和 DROP 语句。mod 记录所有 ddl 语句，外加 INSERT、UPDATE、DELETE、TRUNCATE 和 COPY FROM 等数据修改语句。如果 PREPARE、EXECUTE 和 EXPLAIN ANALYZE 包含合适类型的命令，它们也会被记录。对于使用扩展查询协议的客户端，当收到一个 Execute 消息时会产生日志并且会包括 Bind 参数的值（任何内嵌的单引号会被双写）。 默认值为 none。只有超级用户和具有适当 SET 权限的用户才能更改此设置。 注意 即使使用 log_statement = all 设置，包含简单语法错误的语句也不会被记录。这是因为只有在完成基本语法解析并确定了语句类型之后才会发出日志消息。在扩展查询协议的情况下，在 Execute 阶段之前（即在解析分析或规划期间）出错的语句也不会被记录。将 log_min_error_statement 设置为 ERROR（或更低）来记录这种语句。 记录的语句可能会透露敏感数据，甚至包含明文密码。","description_zh_html":"\u003cp\u003e\n        控制哪些 SQL 语句被记录。有效值是\n        \u003ccode class=\"literal\"\u003enone\u003c/code\u003e (off)、\u003ccode class=\"literal\"\u003eddl\u003c/code\u003e、\u003ccode class=\"literal\"\u003emod\u003c/code\u003e 和\n        \u003ccode class=\"literal\"\u003eall\u003c/code\u003e（所有语句）。\u003ccode class=\"literal\"\u003eddl\u003c/code\u003e 记录所有数据定义语句，例如 \u003ccode class=\"command\"\u003eCREATE\u003c/code\u003e、\u003ccode class=\"command\"\u003eALTER\u003c/code\u003e 和\n        \u003ccode class=\"command\"\u003eDROP\u003c/code\u003e 语句。\u003ccode class=\"literal\"\u003emod\u003c/code\u003e 记录所有 \u003ccode class=\"literal\"\u003eddl\u003c/code\u003e 语句，外加 \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e、\u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e、\u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e、\u003ccode class=\"command\"\u003eTRUNCATE\u003c/code\u003e 和 \u003ccode class=\"command\"\u003eCOPY FROM\u003c/code\u003e 等数据修改语句。如果 \u003ccode class=\"command\"\u003ePREPARE\u003c/code\u003e、\u003ccode class=\"command\"\u003eEXECUTE\u003c/code\u003e 和\n        \u003ccode class=\"command\"\u003eEXPLAIN ANALYZE\u003c/code\u003e 包含合适类型的命令，它们也会被记录。对于使用扩展查询协议的客户端，当收到一个 Execute 消息时会产生日志并且会包括 Bind 参数的值（任何内嵌的单引号会被双写）。\n       \u003c/p\u003e\u003cp\u003e\n        默认值为 \u003ccode class=\"literal\"\u003enone\u003c/code\u003e。只有超级用户和具有适当 \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e 权限的用户才能更改此设置。\n       \u003c/p\u003e\u003cdiv class=\"note\"\u003e\u003ch3 class=\"title\"\u003e注意\u003c/h3\u003e\u003cp\u003e\n         即使使用 \u003ccode class=\"varname\"\u003elog_statement\u003c/code\u003e = \u003ccode class=\"literal\"\u003eall\u003c/code\u003e 设置，包含简单语法错误的语句也不会被记录。这是因为只有在完成基本语法解析并确定了语句类型之后才会发出日志消息。在扩展查询协议的情况下，在 Execute 阶段之前（即在解析分析或规划期间）出错的语句也不会被记录。将 \u003ccode class=\"varname\"\u003elog_min_error_statement\u003c/code\u003e 设置为 \u003ccode class=\"literal\"\u003eERROR\u003c/code\u003e（或更低）来记录这种语句。\n        \u003c/p\u003e\u003cp\u003e\n         记录的语句可能会透露敏感数据，甚至包含明文密码。\n        \u003c/p\u003e\u003c/div\u003e","doc":{"anchor":"GUC-LOG-STATEMENT","file":"runtime-config-logging.html","lang":"en","sha256":"278d913b9c0f735c5cd7b35fd7205826bbd9c449805370d2dbe54105c0ed1d88","slug":"18"},"doc_html":"\u003cp\u003e\n        Controls which SQL statements are logged. Valid values are\n        \u003ccode class=\"literal\"\u003enone\u003c/code\u003e (off), \u003ccode class=\"literal\"\u003eddl\u003c/code\u003e, \u003ccode class=\"literal\"\u003emod\u003c/code\u003e, and\n        \u003ccode class=\"literal\"\u003eall\u003c/code\u003e (all statements). \u003ccode class=\"literal\"\u003eddl\u003c/code\u003e logs all data definition\n        statements, such as \u003ccode class=\"command\"\u003eCREATE\u003c/code\u003e, \u003ccode class=\"command\"\u003eALTER\u003c/code\u003e, and\n        \u003ccode class=\"command\"\u003eDROP\u003c/code\u003e statements. \u003ccode class=\"literal\"\u003emod\u003c/code\u003e logs all\n        \u003ccode class=\"literal\"\u003eddl\u003c/code\u003e statements, plus data-modifying statements\n        such as \u003ccode class=\"command\"\u003eINSERT\u003c/code\u003e,\n        \u003ccode class=\"command\"\u003eUPDATE\u003c/code\u003e, \u003ccode class=\"command\"\u003eDELETE\u003c/code\u003e, \u003ccode class=\"command\"\u003eTRUNCATE\u003c/code\u003e,\n        and \u003ccode class=\"command\"\u003eCOPY FROM\u003c/code\u003e.\n        \u003ccode class=\"command\"\u003ePREPARE\u003c/code\u003e, \u003ccode class=\"command\"\u003eEXECUTE\u003c/code\u003e, and\n        \u003ccode class=\"command\"\u003eEXPLAIN ANALYZE\u003c/code\u003e statements are also logged if their\n        contained command is of an appropriate type.  For clients using\n        extended query protocol, logging occurs when an Execute message\n        is received, and values of the Bind parameters are included\n        (with any embedded single-quote marks doubled).\n       \u003c/p\u003e\u003cp\u003e\n        The default is \u003ccode class=\"literal\"\u003enone\u003c/code\u003e.\n        Only superusers and users with the appropriate \u003ccode class=\"literal\"\u003eSET\u003c/code\u003e\n        privilege can change this setting.\n       \u003c/p\u003e\u003cdiv class=\"note\"\u003e\u003ch3 class=\"title\"\u003eNote\u003c/h3\u003e\u003cp\u003e\n         Statements that contain simple syntax errors are not logged\n         even by the \u003ccode class=\"varname\"\u003elog_statement\u003c/code\u003e = \u003ccode class=\"literal\"\u003eall\u003c/code\u003e setting,\n         because the log message is emitted only after basic parsing has\n         been done to determine the statement type.  In the case of extended\n         query protocol, this setting likewise does not log statements that\n         fail before the Execute phase (i.e., during parse analysis or\n         planning).  Set \u003ccode class=\"varname\"\u003elog_min_error_statement\u003c/code\u003e to\n         \u003ccode class=\"literal\"\u003eERROR\u003c/code\u003e (or lower) to log such statements.\n        \u003c/p\u003e\u003cp\u003e\n         Logged statements might reveal sensitive data and even contain\n         plaintext passwords.\n        \u003c/p\u003e\u003c/div\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":["none","ddl","mod","all"],"extra_desc":null,"lang":"en","max_val":null,"metadata_version":"18","min_val":null,"name":"log_statement","short_desc":"Sets the type of statements logged.","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":"enum","zh_from":"same-version-manual"},"ManualEvidence":{"doc":{"anchor":"GUC-LOG-STATEMENT","file":"runtime-config-logging.html","lang":"en","sha256":"278d913b9c0f735c5cd7b35fd7205826bbd9c449805370d2dbe54105c0ed1d88","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"log_statement","SourceDatabase":"center","Version":"18","Locale":"en","Title":"log_statement","Summary":"Controls which SQL statements are logged. Valid values are none (off), ddl, mod, and all (all statements). ddl logs all data definition statements, such as CREATE, ALTER, and DROP statements. mod logs all ddl statements, plus data-modifying statements such as INSERT, UPDATE, DELETE, TRUNCATE, and COPY FROM. PREPARE, EXECUTE, and EXPLAIN ANALYZE statements are also logged if their contained command is of an appropriate type. For clients using extended query protocol, logging occurs when an Execute message is received, and values of the Bind parameters are included (with any embedded single-quote marks doubled). The default is none. Only superusers and users with the appropriate SET privilege can change this setting. Note Statements that contain simple syntax errors are not logged even by the log_statement = all setting, because the log message is emitted only after basic parsing has been done to determine the statement type. In the case of extended query protocol, this setting likewise does not log statements that fail before the Execute phase (i.e., during parse analysis or planning). Set log_min_error_statement to ERROR (or lower) to log such statements. Logged statements might reveal sensitive data and even contain plaintext passwords.","BodyHTML":"\u003cp\u003e\n        Controls which SQL statements are logged. Valid values are\n        \u003ccode\u003enone\u003c/code\u003e (off), \u003ccode\u003eddl\u003c/code\u003e, \u003ccode\u003emod\u003c/code\u003e, and\n        \u003ccode\u003eall\u003c/code\u003e (all statements). \u003ccode\u003eddl\u003c/code\u003e logs all data definition\n        statements, such as \u003ccode\u003eCREATE\u003c/code\u003e, \u003ccode\u003eALTER\u003c/code\u003e, and\n        \u003ccode\u003eDROP\u003c/code\u003e statements. \u003ccode\u003emod\u003c/code\u003e logs all\n        \u003ccode\u003eddl\u003c/code\u003e statements, plus data-modifying statements\n        such as \u003ccode\u003eINSERT\u003c/code\u003e,\n        \u003ccode\u003eUPDATE\u003c/code\u003e, \u003ccode\u003eDELETE\u003c/code\u003e, \u003ccode\u003eTRUNCATE\u003c/code\u003e,\n        and \u003ccode\u003eCOPY FROM\u003c/code\u003e.\n        \u003ccode\u003ePREPARE\u003c/code\u003e, \u003ccode\u003eEXECUTE\u003c/code\u003e, and\n        \u003ccode\u003eEXPLAIN ANALYZE\u003c/code\u003e statements are also logged if their\n        contained command is of an appropriate type.  For clients using\n        extended query protocol, logging occurs when an Execute message\n        is received, and values of the Bind parameters are included\n        (with any embedded single-quote marks doubled).\n       \u003c/p\u003e\u003cp\u003e\n        The default is \u003ccode\u003enone\u003c/code\u003e.\n        Only superusers and users with the appropriate \u003ccode\u003eSET\u003c/code\u003e\n        privilege can change this setting.\n       \u003c/p\u003e\u003cdiv\u003e\u003ch3\u003eNote\u003c/h3\u003e\u003cp\u003e\n         Statements that contain simple syntax errors are not logged\n         even by the \u003ccode\u003elog_statement\u003c/code\u003e = \u003ccode\u003eall\u003c/code\u003e setting,\n         because the log message is emitted only after basic parsing has\n         been done to determine the statement type.  In the case of extended\n         query protocol, this setting likewise does not log statements that\n         fail before the Execute phase (i.e., during parse analysis or\n         planning).  Set \u003ccode\u003elog_min_error_statement\u003c/code\u003e to\n         \u003ccode\u003eERROR\u003c/code\u003e (or lower) to log such statements.\n        \u003c/p\u003e\u003cp\u003e\n         Logged statements might reveal sensitive data and even contain\n         plaintext passwords.\n        \u003c/p\u003e\u003c/div\u003e","SourceRevision":"wiki-repair-20261023:e3c328d21138ffe93c38fba42e7e784d70f7c559489cd0d3da24af4cf1731222","ContentHash":"52e41139d5a9ed1028ec633cdc5f8f3cd32b8b5be3d1a6eba59a818b661e40a6","Payload":{"description":"Controls which SQL statements are logged. Valid values are none (off), ddl, mod, and all (all statements). ddl logs all data definition statements, such as CREATE, ALTER, and DROP statements. mod logs all ddl statements, plus data-modifying statements such as INSERT, UPDATE, DELETE, TRUNCATE, and COPY FROM. PREPARE, EXECUTE, and EXPLAIN ANALYZE statements are also logged if their contained command is of an appropriate type. For clients using extended query protocol, logging occurs when an Execute message is received, and values of the Bind parameters are included (with any embedded single-quote marks doubled). The default is none. Only superusers and users with the appropriate SET privilege can change this setting. Note Statements that contain simple syntax errors are not logged even by the log_statement = all setting, because the log message is emitted only after basic parsing has been done to determine the statement type. In the case of extended query protocol, this setting likewise does not log statements that fail before the Execute phase (i.e., during parse analysis or planning). Set log_min_error_statement to ERROR (or lower) to log such statements. Logged statements might reveal sensitive data and even contain plaintext passwords."}},"RequestedLocale":"en","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}
