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

# 9.28.4. 復原控制函式

## 9.28.4. 復原控制函式 [#](#functions-recovery-control) <a href="#functions-recovery-control" id="functions-recovery-control"></a>

[表 9.98](#functions-recovery-info-table) 所列的函式提供備用伺服器目前狀態的相關資訊。這些函式在復原期間與正常執行時都可以執行。

### 表 9.98. 復原資訊函式 [#](#functions-recovery-info-table) <a href="#functions-recovery-info-table" id="functions-recovery-info-table"></a>

| <p>函式</p><p>說明</p>                                                                                                                                                                                                                                                                                                                                  |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>pg\_is\_in\_recovery</code> () → <code>boolean</code></p><p>如果復原仍在進行中，就回傳 true。</p>                                                                                                                                                                                                                                                        |
| <p><code>pg\_last\_wal\_receive\_lsn</code> () → <code>pg\_lsn</code></p><p>回傳串流複寫已接收並同步到磁碟的最後一個預寫式日誌位置。在串流複寫進行期間，這個值會單調遞增。如果復原已經完成，這個值會停留在復原期間最後接收並同步到磁碟之 WAL 紀錄的位置。如果停用了串流複寫，或串流複寫尚未開始，函式會回傳 <code>NULL</code>。</p>                                                                                                                               |
| <p><code>pg\_last\_wal\_replay\_lsn</code> () → <code>pg\_lsn</code></p><p>回傳復原期間已重播的最後一個預寫式日誌位置。如果復原仍在進行中，這個值會單調遞增。如果復原已經完成，這個值會停留在復原期間最後套用之 WAL 紀錄的位置。如果伺服器是在沒有復原的情況下正常啟動，函式會回傳 <code>NULL</code>。</p>                                                                                                                                            |
| <p><code>pg\_last\_xact\_replay\_timestamp</code> () → <code>timestamp with time zone</code></p><p>回傳復原期間最後重播之交易的時間戳記。這是該交易的提交或中止 WAL 紀錄在主要伺服器上產生的時間。如果復原期間沒有重播任何交易，函式會回傳 <code>NULL</code>。否則，如果復原仍在進行中，這個值會單調遞增。如果復原已經完成，這個值會停留在復原期間最後套用之交易的時間。如果伺服器是在沒有復原的情況下正常啟動，函式會回傳 <code>NULL</code>。</p>                                                   |
| <p><code>pg\_get\_wal\_resource\_managers</code> () → <code>setof record</code> ( <em><code>rm\_id</code></em> <code>integer</code>, <em><code>rm\_name</code></em> <code>text</code>, <em><code>rm\_builtin</code></em> <code>boolean</code> )</p><p>回傳系統中目前已載入的 WAL 資源管理器。<em><code>rm\_builtin</code></em> 欄位表示它是內建的資源管理器，還是由擴充套件載入的自訂資源管理器。</p> |

<br>

[表 9.99](#functions-recovery-control-table) 所列的函式用於控制復原的進度。這些函式只能在復原期間執行。

### 表 9.99. 復原控制函式 [#](#functions-recovery-control-table) <a href="#functions-recovery-control-table" id="functions-recovery-control-table"></a>

| <p>函式</p><p>說明</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><code>pg\_is\_wal\_replay\_paused</code> () → <code>boolean</code></p><p>如果已請求暫停復原，就回傳 true。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| <p><code>pg\_get\_wal\_replay\_pause\_state</code> () → <code>text</code></p><p>回傳復原暫停的狀態。回傳值為：未請求暫停時為 <code>not paused</code>；已請求暫停但復原尚未暫停時為 <code>pause requested</code>；復原實際已暫停時為 <code>paused</code>。</p>                                                                                                                                                                                                                                                                                                                                                                                                                |
| <p><code>pg\_promote</code> ( <em><code>wait</code></em> <code>boolean</code> <code>DEFAULT</code> <code>true</code>, <em><code>wait\_seconds</code></em> <code>integer</code> <code>DEFAULT</code> <code>60</code> ) → <code>boolean</code></p><p>將備用伺服器提升為主要伺服器。當 <em><code>wait</code></em> 設為 <code>true</code>（預設值）時，函式會等到提升完成或經過 <em><code>wait\_seconds</code></em> 秒為止，提升成功時回傳 <code>true</code>，否則回傳 <code>false</code>。如果 <em><code>wait</code></em> 設為 <code>false</code>，函式會回傳 <code>true</code>，而且是在向 postmaster 傳送 <code>SIGUSR1</code> 訊號以觸發提升之後立即回傳。</p><p>這個函式預設只限超級使用者使用，但可以將 EXECUTE 權限授予其他使用者來執行此函式。</p> |
| <p><code>pg\_wal\_replay\_pause</code> () → <code>void</code></p><p>請求暫停復原。提出請求並不代表復原會立即停止。如果你想確保復原確實已暫停，就需要檢查 <code>pg\_get\_wal\_replay\_pause\_state()</code> 所回傳的復原暫停狀態。請注意，<code>pg\_is\_wal\_replay\_paused()</code> 回傳的是是否已提出請求。在復原暫停期間，不會再套用任何資料庫變更。如果熱備用（hot standby）處於作用中，所有新的查詢都會看到相同且一致的資料庫快照，而且在復原恢復之前不會再產生任何查詢衝突。</p><p>這個函式預設只限超級使用者使用，但可以將 EXECUTE 權限授予其他使用者來執行此函式。</p>                                                                                                                                                                                                                                      |
| <p><code>pg\_wal\_replay\_resume</code> () → <code>void</code></p><p>如果復原已暫停，就重新開始復原。</p><p>這個函式預設只限超級使用者使用，但可以將 EXECUTE 權限授予其他使用者來執行此函式。</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

<br>

在提升（promotion）進行中時，不能執行 `pg_wal_replay_pause` 與 `pg_wal_replay_resume`。如果在復原暫停時觸發了提升，暫停狀態就會結束，並繼續進行提升。

如果停用了串流複寫，暫停狀態可以無限期持續而不會有問題。如果正在進行串流複寫，就會持續接收 WAL 紀錄，最終會填滿可用的磁碟空間，這取決於暫停的時間長短、WAL 的產生速率以及可用的磁碟空間。

[返回 9.28. 系統管理函式](https://docs.postgresql.tw/19/the-sql-language/functions/functions-admin.md#functions-admin)

***

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


---

# 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/the-sql-language/functions/functions-admin/functions-recovery-control.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.
