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

# 第 47 章 邏輯解碼

### 第 47 章 邏輯解碼

**目錄**

* [47.1. 邏輯解碼範例](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-example.md)
* [47.2. 邏輯解碼的概念](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-explanation.md)
  * [47.2.1. 邏輯解碼](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-explanation.md#logicaldecoding-explanation-log-dec)
  * [47.2.2. 複寫插槽](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-explanation.md#logicaldecoding-replication-slots)
  * [47.2.3. 複寫插槽同步](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-explanation.md#logicaldecoding-replication-slots-synchronization)
  * [47.2.4. 輸出外掛程式](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-explanation.md#logicaldecoding-explanation-output-plugins)
  * [47.2.5. 匯出的快照](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-explanation.md#logicaldecoding-explanation-exported-snapshots)
* [47.3. 串流複寫協定介面](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-walsender.md)
* [47.4. 邏輯解碼 SQL 介面](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-sql.md)
* [47.5. 與邏輯解碼相關的系統目錄](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-catalogs.md)
* [47.6. 邏輯解碼輸出外掛程式](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-output-plugin.md)
  * [47.6.1. 初始化函式](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-output-plugin.md#logicaldecoding-output-init)
  * [47.6.2. 功能](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-output-plugin.md#logicaldecoding-capabilities)
  * [47.6.3. 輸出模式](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-output-plugin.md#logicaldecoding-output-mode)
  * [47.6.4. 輸出外掛程式回呼函式](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-output-plugin.md#logicaldecoding-output-plugin-callbacks)
  * [47.6.5. 用於產生輸出的函式](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-output-plugin.md#logicaldecoding-output-plugin-output)
* [47.7. 邏輯解碼輸出寫入器](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-writer.md)
* [47.8. 邏輯解碼的同步複寫支援](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-synchronous.md)
  * [47.8.1. 概觀](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-synchronous.md#logicaldecoding-synchronous-overview)
  * [47.8.2. 注意事項](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-synchronous.md#logicaldecoding-synchronous-caveats)
* [47.9. 邏輯解碼的大型交易串流](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-streaming.md)
* [47.10. 邏輯解碼的兩階段提交支援](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-two-phase-commits.md)

PostgreSQL 提供了一套基礎架構，可以把透過 SQL 所做的修改，以串流方式傳送給外部消費端。這項功能可用於各種用途，包括複寫解決方案與稽核。

變更會在由邏輯複寫插槽識別的串流中送出。

這些變更以何種格式串流傳送，是由所使用的輸出外掛程式決定的。PostgreSQL 發行版中提供了一個範例外掛程式。也可以在不修改任何核心程式碼的情況下，撰寫額外的外掛程式，以擴充可用的格式選項。每個輸出外掛程式，都能存取由 `INSERT` 所產生的每一筆新資料列，以及由 `UPDATE` 所建立的新版本資料列。至於 `UPDATE` 與 `DELETE` 的舊版本資料列是否可用，則取決於所設定的複本識別（見 [`REPLICA IDENTITY`](https://docs.postgresql.tw/19/reference/sql-commands/sql-altertable.md#SQL-ALTERTABLE-REPLICA-IDENTITY)）。

變更可以透過串流複寫協定來消費（見[第 54.4 節](https://docs.postgresql.tw/19/internals/protocol/protocol-replication.md)與[第 47.3 節](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-walsender.md)），也可以透過呼叫 SQL 函式來消費（見[第 47.4 節](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-sql.md)）。你也可以在不修改核心程式碼的情況下，撰寫額外的方法來消費複寫插槽的輸出（見[第 47.7 節](https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-writer.md)）。

***

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


---

# 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/server-programming/logicaldecoding.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.
