> 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-commit-prepared.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# COMMIT PREPARED

### COMMIT PREPARED

COMMIT PREPARED — 提交先前已為兩階段提交而準備的交易

### 語法

```

COMMIT PREPARED transaction_id
```

### 說明

`COMMIT PREPARED` 會提交處於已準備狀態的交易。

### 參數

*`transaction_id`* : 要提交之交易的交易識別碼。

### 注意事項

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

此命令不能在交易區塊內執行。已準備的交易會立即提交。

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

### 範例

提交以交易識別碼 `foobar` 識別的交易：

```

COMMIT PREPARED 'foobar';
```

### 相容性

`COMMIT PREPARED` 是 PostgreSQL 的擴充語法。它是供外部交易管理系統使用的，其中有些系統受標準（例如 X/Open XA）涵蓋，但這些系統的 SQL 端並未標準化。

### 另請參閱

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

***

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


---

# 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-commit-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.
