> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/reference/sql-commands/sql-rollback-prepared.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# ROLLBACK PREPARED

### ROLLBACK PREPARED

ROLLBACK PREPARED — 取消一個先前已為兩階段提交而準備的交易

### 語法

```

ROLLBACK PREPARED transaction_id
```

### 說明

`ROLLBACK PREPARED` 會回復一個處於已準備狀態的交易。

### 參數

*`transaction_id`* : 要被回復之交易的交易識別碼。

### 注意

若要回復一個已準備的交易，你必須是最初執行該交易的同一位使用者，或是超級使用者。但你不必身處執行該交易的同一個工作階段中。

此指令不能在交易區塊內執行。已準備的交易會被立即回復。

所有目前可用的已準備交易，都列在 [`pg_prepared_xacts`](https://docs.postgresql.tw/19/internals/views/view-pg-prepared-xacts.md) 系統檢視表中。

### 範例

回復以交易識別碼 `foobar` 所識別的交易：

```

ROLLBACK PREPARED 'foobar';
```

### 相容性

`ROLLBACK PREPARED` 是 PostgreSQL 的擴充功能，適用於外部交易管理系統。有些這類系統受標準（例如 X/Open XA）涵蓋，但這些系統的 SQL 端並未標準化。

### 另請參閱

[PREPARE TRANSACTION](https://docs.postgresql.tw/19/reference/sql-commands/sql-prepare-transaction.md), [COMMIT PREPARED](https://docs.postgresql.tw/19/reference/sql-commands/sql-commit-prepared.md)

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/sql-rollback-prepared.html)（原文版本：18.6；核對日期：2026-09-28）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/reference/sql-commands/sql-rollback-prepared.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
