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

# 53.20. pg\_replication\_slots \#

### 53.20. `pg_replication_slots` [#](#view-pg-replication-slots) <a href="#view-pg-replication-slots" id="view-pg-replication-slots"></a>

檢視表 `pg_replication_slots` 列出資料庫叢集中目前存在的所有複寫插槽，以及它們目前的狀態。

關於複寫插槽的更多資訊，請參閱[第 26.2.6 節](https://docs.postgresql.tw/19/server-administration/high-availability/warm-standby.md#streaming-replication-slots)與[第 47 章](https://docs.postgresql.tw/19/server-programming/logicaldecoding.md)。

#### 表 53.20. `pg_replication_slots` 欄位 [#](#view-pg-replication-slots-columns) <a href="#view-pg-replication-slots-columns" id="view-pg-replication-slots-columns"></a>

| <p>欄位類型</p><p>說明</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><code>slot\_name</code> <code>name</code></p><p>此複寫插槽在整個叢集中唯一的識別名稱</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>plugin</code> <code>name</code></p><p>此邏輯插槽所使用之輸出外掛所在的共享物件的基本名稱；實體插槽則為 null。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>slot\_type</code> <code>text</code></p><p>插槽類型：<code>physical</code> 或 <code>logical</code></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>datoid</code> <code>oid</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-database.md"><code>pg\_database</code></a>.<code>oid</code>）</p><p>此插槽所關聯之資料庫的 OID，或為 null。只有邏輯插槽才有關聯的資料庫。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| <p><code>database</code> <code>name</code> （參照 <a href="https://docs.postgresql.tw/19/internals/catalogs/catalog-pg-database.md"><code>pg\_database</code></a>.<code>datname</code>）</p><p>此插槽所關聯之資料庫的名稱，或為 null。只有邏輯插槽才有關聯的資料庫。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| <p><code>temporary</code> <code>bool</code></p><p>若這是暫時複寫插槽則為 true。暫時插槽不會儲存到磁碟，並會在發生錯誤時或工作階段結束時自動移除。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>active</code> <code>bool</code></p><p>若此插槽目前正在進行串流則為 true</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| <p><code>active\_pid</code> <code>int4</code></p><p>為此插槽串流資料之工作階段的程序 ID。非使用中時為 <code>NULL</code>。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| <p><code>xmin</code> <code>xid</code></p><p>此插槽需要資料庫保留的最舊交易。<code>VACUUM</code> 無法移除由任何較晚的交易所刪除的資料列。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| <p><code>catalog\_xmin</code> <code>xid</code></p><p>此插槽需要資料庫保留、且會影響系統目錄的最舊交易。<code>VACUUM</code> 無法移除由任何較晚的交易所刪除的系統目錄資料列。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| <p><code>restart\_lsn</code> <code>pg\_lsn</code></p><p>此插槽的取用端可能仍需要的最舊 WAL 的位址（<code>LSN</code>），因此這些 WAL 在檢查點期間不會被自動移除，除非此 LSN 落後目前的 LSN 超過 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-replication.md#GUC-MAX-SLOT-WAL-KEEP-SIZE">max\_slot\_wal\_keep\_size</a>。以下情況為 <code>NULL</code>：此插槽的 <code>LSN</code> 從未被保留。</p>                                                                                                                                                                                                                                                                                                                                        |
| <p><code>confirmed\_flush\_lsn</code> <code>pg\_lsn</code></p><p>邏輯插槽的取用端已確認收到資料所到達的位址（<code>LSN</code>）。在此 <code>LSN</code> 之前已提交之交易所對應的資料已不再可用。實體插槽則為 <code>NULL</code>。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| <p><code>wal\_status</code> <code>text</code></p><p>此插槽所要求保留之 WAL 檔案的可用狀態。可能的值有：</p><ul><li><code>reserved</code> 表示所要求保留的檔案仍在 <code>max\_wal\_size</code> 的範圍內。</li><li><code>extended</code> 表示已超過 <code>max\_wal\_size</code>，但這些檔案仍由複寫插槽或 <code>wal\_keep\_size</code> 保留著。</li><li><code>unreserved</code> 表示此插槽已不再保留所需的 WAL 檔案，其中部分檔案將在下一次檢查點時被移除。這通常發生在 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-replication.md#GUC-MAX-SLOT-WAL-KEEP-SIZE">max\_slot\_wal\_keep\_size</a> 設為非負值時。此狀態可以回到 <code>reserved</code> 或 <code>extended</code>。</li><li><code>lost</code> 表示此插槽已無法再使用。</li></ul>                                                                 |
| <p><code>safe\_wal\_size</code> <code>int8</code></p><p>在不使此插槽陷入「lost」狀態之危險的前提下，仍可寫入 WAL 的位元組數。對於處於 lost 狀態的插槽，以及 <code>max\_slot\_wal\_keep\_size</code> 為 <code>-1</code> 時，此值為 NULL。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>two\_phase</code> <code>bool</code></p><p>若此插槽已啟用已準備交易的解碼則為 true。實體插槽一律為 false。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| <p><code>two\_phase\_at</code> <code>pg\_lsn</code></p><p>開始啟用已準備交易解碼的位址（<code>LSN</code>）。以下情況為 <code>NULL</code>：<code>two\_phase</code> 為 false 的邏輯插槽，以及實體插槽。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| <p><code>inactive\_since</code> <code>timestamptz</code></p><p>插槽變為非使用中的時間。若插槽目前正在串流，則為 <code>NULL</code>。若插槽變為無效，此值將永遠不會再更新。對於正從主要伺服器同步過來的待命伺服器插槽（其 <code>synced</code> 欄位為 <code>true</code>），<code>inactive\_since</code> 表示插槽同步（請參閱 <a href="https://docs.postgresql.tw/19/server-programming/logicaldecoding/logicaldecoding-explanation.md#logicaldecoding-replication-slots-synchronization">第 47.2.3 節</a>）最近一次停止的時間。若插槽一直保持同步，則為 <code>NULL</code>。這有助於待命伺服器插槽追蹤同步是在何時中斷的。</p>                                                                                                                                                                                                                            |
| <p><code>conflicting</code> <code>bool</code></p><p>若此邏輯插槽與復原發生衝突（因而現已失效）則為 true。此欄位為 true 時，請查看 <code>invalidation\_reason</code> 欄位以了解衝突原因。實體插槽一律為 <code>NULL</code>。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| <p><code>invalidation\_reason</code> <code>text</code></p><p>插槽失效的原因。邏輯插槽與實體插槽都會設定此欄位。若插槽未失效，則為 <code>NULL</code>。可能的值有：</p><ul><li><code>wal\_removed</code> 表示所需的 WAL 已被移除。</li><li><code>rows\_removed</code> 表示所需的資料列已被移除。只有邏輯插槽會設定此值。</li><li><code>wal\_level\_insufficient</code> 表示主要伺服器的 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-wal.md#GUC-WAL-LEVEL">wal\_level</a> 不足以執行邏輯解碼。只有邏輯插槽會設定此值。</li><li><code>idle\_timeout</code> 表示插槽維持非使用中的時間已超過所設定的 <a href="https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-replication.md#GUC-IDLE-REPLICATION-SLOT-TIMEOUT">idle\_replication\_slot\_timeout</a> 時間長度。</li></ul> |
| <p><code>failover</code> <code>bool</code></p><p>若這是已啟用同步至待命伺服器的邏輯插槽則為 true，如此在容錯移轉後，邏輯複寫便可從新的主要伺服器繼續進行。實體插槽一律為 false。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| <p><code>synced</code> <code>bool</code></p><p>若這是從主要伺服器同步而來的邏輯插槽則為 true。在熱備援伺服器上，synced 欄位標記為 true 的插槽既不能用於邏輯解碼，也不能手動移除。此欄位的值在主要伺服器上沒有意義；主要伺服器上所有插槽的此欄位值預設為 false，但也可能為 true（若該插槽是從已提升為主要伺服器的待命伺服器遺留下來的）。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |

<br>

***

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


---

# 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/internals/views/view-pg-replication-slots.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.
