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

# COMMIT

### COMMIT

COMMIT — 提交目前的交易

### 語法

```

COMMIT [ WORK | TRANSACTION ] [ AND [ NO ] CHAIN ]
```

### 說明

`COMMIT` 會提交目前的交易。該交易所做的所有變更都會變得對其他人可見，並保證在發生當機時仍能持久保存。

### 參數

`WORK`\
`TRANSACTION` [#](#SQL-COMMIT-TRANSACTION) : 可省略的關鍵字，沒有任何效果。

`AND CHAIN` [#](#SQL-COMMIT-CHAIN) : 若指定了 `AND CHAIN`，會立即啟動一個新交易，其交易特性（請參閱 [SET TRANSACTION](https://docs.postgresql.tw/19/reference/sql-commands/sql-set-transaction.md)）與剛結束的交易相同。否則，不會啟動新交易。

### 注意事項

使用 [ROLLBACK](https://docs.postgresql.tw/19/reference/sql-commands/sql-rollback.md) 來中止交易。

在交易外發出 `COMMIT` 不會造成損害，但會引發一則警告訊息。在交易外執行 `COMMIT AND CHAIN` 則是錯誤。

### 範例

要提交目前的交易，並使所有變更永久生效：

```

COMMIT;
```

### 相容性

`COMMIT` 命令符合 SQL 標準。`COMMIT TRANSACTION` 這種形式是 PostgreSQL 的擴充語法。

### 另請參閱

[BEGIN](https://docs.postgresql.tw/19/reference/sql-commands/sql-begin.md), [ROLLBACK](https://docs.postgresql.tw/19/reference/sql-commands/sql-rollback.md)

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/sql-commit.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.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.
