{"Entry":{"collection":"sql","key":"rollback-prepared","name":"ROLLBACK PREPARED","aliases":["rollback-prepared"],"metadata":{"aliases":["rollback-prepared"],"changed_in":[],"changes":[{"from":"8.0","purpose_changed":false,"renamed":null,"sections":{"added":[],"changed":[],"removed":[]},"status":"added","synopsis":null,"to":"8.1"},{"from":"9.1","purpose_changed":false,"renamed":null,"sections":{"added":["compatibility"],"changed":[],"removed":[]},"status":"changed","synopsis":null,"to":"9.2"}],"content_hash":"0c108378048047d209cdbe32a9b208cd80aa53c9d0dd4425780038c57db56b90","editorial":{},"first_version":"8.1","group":"transaction","imported_at":"2026-09-30T17:43:39.365243+08:00","last_version":"20","name":"ROLLBACK PREPARED","object":"PREPARED","position":13009,"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"],"purpose":"cancel a transaction that was earlier prepared for two-phase commit","purpose_zh":"","related":["prepare-transaction","commit-prepared"],"slug":"rollback-prepared","source_rev":"a709ab85","synopsis":"ROLLBACK PREPARED transaction_id","verb":"ROLLBACK"}},"Definition":{"Collection":"sql","Key":"rollback-prepared","SourceDatabase":"center","Version":"18","SourceTable":"sqlcmd","SourceKey":"rollback-prepared","SourceRevision":"a709ab85","Facts":{"anchor":"SQL-ROLLBACK-PREPARED","file":"sql-rollback-prepared.html","lang":"en","name":"ROLLBACK PREPARED","purpose":"cancel a transaction that was earlier prepared for two-phase commit","purpose_zh":"","related":["prepare-transaction","commit-prepared"],"sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eROLLBACK PREPARED\u003c/code\u003e rolls back a transaction that is in prepared state.\u003c/p\u003e","key":"description","title":"Description"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_id\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003eThe transaction identifier of the transaction that is to be rolled back.\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"Parameters"},{"html":"\u003cp\u003eTo roll back a prepared transaction, you must be either the same user that executed the transaction originally, or a superuser. But you do not have to be in the same session that executed the transaction.\u003c/p\u003e\u003cp\u003eThis command cannot be executed inside a transaction block. The prepared transaction is rolled back immediately.\u003c/p\u003e\u003cp\u003eAll currently available prepared transactions are listed in the \u003ca href=\"/docs/18/view-pg-prepared-xacts.html\" title=\"53.17. pg_prepared_xacts\"\u003e\u003ccode class=\"structname\"\u003epg_prepared_xacts\u003c/code\u003e\u003c/a\u003e system view.\u003c/p\u003e","key":"notes","title":"Notes"},{"html":"\u003cp\u003eRoll back the transaction identified by the transaction identifier \u003ccode class=\"literal\"\u003efoobar\u003c/code\u003e:\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eROLLBACK PREPARED 'foobar';\n\u003c/pre\u003e","key":"examples","title":"Examples"},{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eROLLBACK PREPARED\u003c/code\u003e is a \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e extension. It is intended for use by external transaction management systems, some of which are covered by standards (such as X/Open XA), but the SQL side of those systems is not standardized.\u003c/p\u003e","key":"compatibility","title":"Compatibility"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/prepare-transaction/?v=18\" title=\"PREPARE TRANSACTION\"\u003e\u003cspan class=\"refentrytitle\"\u003ePREPARE TRANSACTION\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/commit-prepared/?v=18\" title=\"COMMIT PREPARED\"\u003e\u003cspan class=\"refentrytitle\"\u003eCOMMIT PREPARED\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"See Also"}],"sections_same_as":"","slug":"18","synopsis_html":"ROLLBACK PREPARED \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_id\u003c/code\u003e\u003c/em\u003e","synopsis_text":"ROLLBACK PREPARED transaction_id"},"ManualEvidence":{},"MeasuredEvidence":{}},"Text":{"Collection":"sql","Key":"rollback-prepared","SourceDatabase":"pgweb","Version":"18","Locale":"zh-Hans","Title":"ROLLBACK PREPARED","Summary":"回滚一个先前为两阶段提交而预备的事务","BodyHTML":"\u003cpre\u003eROLLBACK PREPARED transaction_id\u003c/pre\u003e\u003csection\u003e\u003ch2\u003e描述\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eROLLBACK PREPARED\u003c/code\u003e回滚一个处于预备状态的事务。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e参数\u003c/h2\u003e\u003cdiv\u003e\u003cdl\u003e\u003cdt\u003e\u003cspan\u003e\u003cem\u003e\u003ccode\u003etransaction_id\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e要回滚的事务的事务标识符。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e注解\u003c/h2\u003e\u003cp\u003e要回滚预备事务，执行者必须是最初执行该事务的同一用户，或者是超级用户；但不必处在执行该事务的同一会话中。\u003c/p\u003e\u003cp\u003e这个命令不能在事务块内执行。该预备事务会被立即回滚。\u003c/p\u003e\u003cp\u003e当前所有处于预备状态的事务都列在 \u003ca href=\"/docs/18/view-pg-prepared-xacts.html\" rel=\"nofollow\"\u003e\u003ccode\u003epg_prepared_xacts\u003c/code\u003e\u003c/a\u003e 系统视图中。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e示例\u003c/h2\u003e\u003cp\u003e回滚事务标识符为\u003ccode\u003efoobar\u003c/code\u003e的事务：\u003c/p\u003e\u003cpre\u003eROLLBACK PREPARED \u0026#39;foobar\u0026#39;;\n\u003c/pre\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e兼容性\u003c/h2\u003e\u003cp\u003e\u003ccode\u003eROLLBACK PREPARED\u003c/code\u003e是 \u003cspan\u003ePostgreSQL\u003c/span\u003e扩展。它旨在供外部事务管理系统使用，其中有些系统已被标准覆盖（例如 X/Open XA），但这些系统的 SQL 侧并未标准化。\u003c/p\u003e\u003c/section\u003e\u003csection\u003e\u003ch2\u003e另见\u003c/h2\u003e\u003cspan\u003e\u003ca href=\"/wiki/sql/prepare-transaction/?v=18\" title=\"PREPARE TRANSACTION\" rel=\"nofollow\"\u003e\u003cspan\u003ePREPARE TRANSACTION\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/commit-prepared/?v=18\" title=\"COMMIT PREPARED\" rel=\"nofollow\"\u003e\u003cspan\u003eCOMMIT PREPARED\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e\u003c/section\u003e","SourceRevision":"1b5ca64c","ContentHash":"3a763787e161fb3ba079e9a346e5a2a1617038b7a17753fe86b852430f682a98","Payload":{"purpose_zh":"回滚一个先前为两阶段提交而预备的事务","sections":[{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eROLLBACK PREPARED\u003c/code\u003e回滚一个处于预备状态的事务。\u003c/p\u003e","key":"description","title":"描述"},{"html":"\u003cdiv class=\"variablelist\"\u003e\u003cdl class=\"variablelist\"\u003e\u003cdt\u003e\u003cspan class=\"term\"\u003e\u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_id\u003c/code\u003e\u003c/em\u003e\u003c/span\u003e\u003c/dt\u003e\u003cdd\u003e\u003cp\u003e要回滚的事务的事务标识符。\u003c/p\u003e\u003c/dd\u003e\u003c/dl\u003e\u003c/div\u003e","key":"parameters","title":"参数"},{"html":"\u003cp\u003e要回滚预备事务，执行者必须是最初执行该事务的同一用户，或者是超级用户；但不必处在执行该事务的同一会话中。\u003c/p\u003e\u003cp\u003e这个命令不能在事务块内执行。该预备事务会被立即回滚。\u003c/p\u003e\u003cp\u003e当前所有处于预备状态的事务都列在 \u003ca href=\"/docs/18/view-pg-prepared-xacts.html\" title=\"53.17. pg_prepared_xacts\"\u003e\u003ccode class=\"structname\"\u003epg_prepared_xacts\u003c/code\u003e\u003c/a\u003e 系统视图中。\u003c/p\u003e","key":"notes","title":"注解"},{"html":"\u003cp\u003e回滚事务标识符为\u003ccode class=\"literal\"\u003efoobar\u003c/code\u003e的事务：\u003c/p\u003e\u003cpre class=\"programlisting\"\u003eROLLBACK PREPARED 'foobar';\n\u003c/pre\u003e","key":"examples","title":"示例"},{"html":"\u003cp\u003e\u003ccode class=\"command\"\u003eROLLBACK PREPARED\u003c/code\u003e是 \u003cspan class=\"productname\"\u003ePostgreSQL\u003c/span\u003e扩展。它旨在供外部事务管理系统使用，其中有些系统已被标准覆盖（例如 X/Open XA），但这些系统的 SQL 侧并未标准化。\u003c/p\u003e","key":"compatibility","title":"兼容性"},{"html":"\u003cspan class=\"simplelist\"\u003e\u003ca href=\"/wiki/sql/prepare-transaction/?v=18\" title=\"PREPARE TRANSACTION\"\u003e\u003cspan class=\"refentrytitle\"\u003ePREPARE TRANSACTION\u003c/span\u003e\u003c/a\u003e, \u003ca href=\"/wiki/sql/commit-prepared/?v=18\" title=\"COMMIT PREPARED\"\u003e\u003cspan class=\"refentrytitle\"\u003eCOMMIT PREPARED\u003c/span\u003e\u003c/a\u003e\u003c/span\u003e","key":"see_also","title":"另见"}],"sections_same_as":"","synopsis_html":"ROLLBACK PREPARED \u003cem class=\"replaceable\"\u003e\u003ccode\u003etransaction_id\u003c/code\u003e\u003c/em\u003e","synopsis_text":"ROLLBACK PREPARED transaction_id"}},"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}
