{"Entry":{"collection":"guc","key":"max_prepared_transactions","name":"max_prepared_transactions","aliases":[],"metadata":{"baseline":false,"boot_human":"Not specified","boot_val":null,"category":"Resource Usage / Memory","category_zh":"","changed_in":["9.1","9.6"],"changes":[{"documentation_changed":false,"fields":{},"from":"8.0","status":"added","to":"8.1"},{"documentation_changed":true,"fields":{},"from":"8.1","status":"changed","to":"8.2"},{"documentation_changed":true,"fields":{},"from":"8.2","status":"changed","to":"8.3"},{"documentation_changed":true,"fields":{},"from":"8.3","status":"changed","to":"8.4"},{"documentation_changed":true,"fields":{},"from":"8.4","status":"changed","to":"9.0"},{"documentation_changed":false,"fields":{"max_val":{"from":"536870911","to":"8388607"}},"from":"9.0","status":"changed","to":"9.1"},{"documentation_changed":true,"fields":{},"from":"9.2","status":"changed","to":"9.3"},{"documentation_changed":false,"fields":{"max_val":{"from":"8388607","to":"262143"}},"from":"9.5","status":"changed","to":"9.6"},{"documentation_changed":true,"fields":{},"from":"9.6","status":"changed","to":"10"},{"documentation_changed":true,"fields":{},"from":"13","status":"changed","to":"14"},{"documentation_changed":true,"fields":{},"from":"19","status":"changed","to":"20"}],"content_hash":"c84968c2e34d8b545b878fc6230d08111990122ef29ec739d2c0dd9ce5a0548f","context":"","default_changed_in":[],"default_history":[{"from":"9.0","to":"19","value":"0"}],"editorial":{"advice":{"olap":"Analytical workload does not justify max_prepared_transactions. Enable only for an application protocol that requires durable prepared transactions, not for SQL prepared statements.","oltp":"Keep max_prepared_transactions=0 unless a real two-phase-commit coordinator monitors and resolves every prepared transaction. If enabled, size primary and standbys consistently and alert on transaction age.","small":"Leave max_prepared_transactions=0 on a small deployment unless two-phase commit is mandatory and operational recovery is documented; stranded prepared transactions can block the cluster."},"mechanism":["max_prepared_transactions reserves capacity for two-phase transactions left in the prepared state by PREPARE TRANSACTION. Zero disables creating prepared transactions.","Prepared transactions retain locks and transaction state across client disconnects and crashes until COMMIT PREPARED or ROLLBACK PREPARED. Capacity requires shared memory and durable state.","A standby must configure at least the primary's value or read queries can be refused. This is unrelated to SQL prepared statements and should remain zero unless a two-phase commit coordinator is operationally managed. Its postmaster context fixes the value at server start; changing it requires a restart."],"pitfalls":["Changing max_prepared_transactions without applying its documented unit and configuration context.","Optimizing an isolated benchmark while ignoring concurrent aggregate resource use.","Assuming a configured value guarantees operating-system or storage behavior.","Failing to retest startup, failover, and workload latency after the change."],"references":[{"title":"PostgreSQL 19 Beta 4: max_prepared_transactions","url":"https://www.postgresql.org/docs/19/runtime-config-resource.html#GUC-MAX-PREPARED-TRANSACTIONS"},{"title":"PostgreSQL 19 release notes","url":"https://www.postgresql.org/docs/19/release-19.html"}],"related":["max_connections","max_locks_per_transaction","wal_level","max_wal_senders"],"summary":"max_prepared_transactions — Sets the maximum number of simultaneously prepared transactions. Observed in PG9.0–19 Beta 4; its last measured boot default is 0 in PG19 Beta 4, with postmaster context. This is a beta-snapshot fact and can change before PostgreSQL 19 GA."},"enumvals":[],"first_version":"8.1","group":"Resource Usage","group_slug":"resource","imported_at":"2026-09-27T17:57:31.730976+08:00","intro_commit":{},"key":"max_prepared_transactions","last_version":"20","max_val":"","min_val":"","name":"max_prepared_transactions","position":280,"present_in":["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":"Sets the maximum number of transactions that can be in the “prepared” state simultaneously (see PREPARE TRANSACTION).","short_desc_zh":"","source_rev":"english-manuals:24792d8170a2e32d40c3a9ed128b0b697fdd5b79b1fd123374b1e75bb0e89eae","unit":"","vartype":"integer"}},"Definition":{"Collection":"guc","Key":"max_prepared_transactions","SourceDatabase":"center","Version":"18","SourceTable":"guc","SourceKey":"max_prepared_transactions","SourceRevision":"english-manuals:24792d8170a2e32d40c3a9ed128b0b697fdd5b79b1fd123374b1e75bb0e89eae","Facts":{"boot_val":"0","category":"Resource Usage / Memory","context":"postmaster","description":"Sets the maximum number of transactions that can be in the “prepared” state simultaneously (see PREPARE TRANSACTION). Setting this parameter to zero (which is the default) disables the prepared-transaction feature. This parameter can only be set at server start. If you are not planning to use prepared transactions, this parameter should be set to zero to prevent accidental creation of prepared transactions. If you are using prepared transactions, you will probably want max_prepared_transactions to be at least as large as max_connections, so that every session can have a prepared transaction pending. When running a standby server, you must set this parameter to the same or higher value than on the primary server. Otherwise, queries will not be allowed in the standby server.","doc":{"anchor":"GUC-MAX-PREPARED-TRANSACTIONS","file":"runtime-config-resource.html","lang":"en","sha256":"2e207c599f0884dfbe594558c478a2c7c132578981071e980e2015f31dfce28c","slug":"18"},"documented":true,"enumvals":null,"extra_desc":null,"lang":"en","max_val":"262143","metadata_version":"18","min_val":"0","name":"max_prepared_transactions","short_desc":"Sets the maximum number of simultaneously prepared transactions.","source":"pg-settings-source-snapshot","unit":null,"vartype":"integer"},"ManualEvidence":{"doc":{"anchor":"GUC-MAX-PREPARED-TRANSACTIONS","file":"runtime-config-resource.html","lang":"en","sha256":"2e207c599f0884dfbe594558c478a2c7c132578981071e980e2015f31dfce28c","slug":"18"}},"MeasuredEvidence":{"metadata_version":"18"}},"Text":{"Collection":"guc","Key":"max_prepared_transactions","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"max_prepared_transactions","Summary":"","BodyHTML":"\u003cp\u003e设置可同时处于\u003cspan\u003e“\u003cspan\u003e预备\u003c/span\u003e”\u003c/span\u003e状态的事务的最大数量（见\u003ca href=\"/docs/18/sql-prepare-transaction.html\" title=\"PREPARE TRANSACTION\" rel=\"nofollow\"\u003e\u003cspan\u003ePREPARE TRANSACTION\u003c/span\u003e\u003c/a\u003e）。将此参数设为零（默认值）会禁用预备事务功能。此参数只能在服务器启动时设置。\u003c/p\u003e\u003cp\u003e如果不打算使用预备事务，应将此参数设为零，以防意外创建预备事务。如果使用预备事务，通常应将 \u003ccode\u003emax_prepared_transactions\u003c/code\u003e 设为不小于\u003ca href=\"/docs/18/runtime-config-connection.html#GUC-MAX-CONNECTIONS\" rel=\"nofollow\"\u003emax_connections\u003c/a\u003e的值，以便每个会话都能有一个待处理的预备事务。\u003c/p\u003e\u003cp\u003e运行备库时，必须将此参数设为与主库相同或更大的值。否则，备库上将不允许执行查询。\u003c/p\u003e","SourceRevision":"2026-09-11@29c86d9","ContentHash":"c62b3065ea11bb5754fad0a954ff64461e7e0c8604c61e272928cbcc241f4c00","Payload":{"carried_from":"","carry_reason":"","doc_html":"\u003cp\u003e设置可同时处于\u003cspan class=\"quote\"\u003e“\u003cspan class=\"quote\"\u003e预备\u003c/span\u003e”\u003c/span\u003e状态的事务的最大数量（见\u003ca href=\"/docs/18/sql-prepare-transaction.html\" title=\"PREPARE TRANSACTION\"\u003e\u003cspan class=\"refentrytitle\"\u003ePREPARE TRANSACTION\u003c/span\u003e\u003c/a\u003e）。将此参数设为零（默认值）会禁用预备事务功能。此参数只能在服务器启动时设置。\u003c/p\u003e\u003cp\u003e如果不打算使用预备事务，应将此参数设为零，以防意外创建预备事务。如果使用预备事务，通常应将 \u003ccode class=\"varname\"\u003emax_prepared_transactions\u003c/code\u003e 设为不小于\u003ca href=\"/docs/18/runtime-config-connection.html#GUC-MAX-CONNECTIONS\"\u003emax_connections\u003c/a\u003e的值，以便每个会话都能有一个待处理的预备事务。\u003c/p\u003e\u003cp\u003e运行备库时，必须将此参数设为与主库相同或更大的值。否则，备库上将不允许执行查询。\u003c/p\u003e","doc_same_as":""}},"RequestedLocale":"zh-Hans","Fallback":false,"Versions":["10","11","12","13","14","15","16","17","18","19","20","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}
