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

# 9.28.5. 快照同步函式

## 9.28.5. 快照同步函式 [#](#functions-snapshot-synchronization) <a href="#functions-snapshot-synchronization" id="functions-snapshot-synchronization"></a>

PostgreSQL 允許資料庫工作階段同步它們的快照。*快照*決定了哪些資料對正在使用該快照的交易是可見的。當兩個以上的工作階段需要看到資料庫中完全相同的內容時，就需要同步快照。如果兩個工作階段只是各自獨立地開始交易，那麼總是有可能在兩個 `START TRANSACTION` 指令執行之間，有第三個交易提交，使得其中一個工作階段看得到該交易的效果，而另一個則看不到。

為了解決這個問題，PostgreSQL 允許交易*匯出*（export）它正在使用的快照。只要匯出快照的交易仍保持開啟，其他交易就可以*匯入*（import）它的快照，從而保證它們看到的資料庫狀態與第一個交易所看到的完全相同。但請注意，這些交易中任何一個所做的資料庫變更，對其他交易仍然是不可見的，這與未提交交易所做的變更一般情況相同。因此，這些交易對於既有的資料是同步的，但對於它們自己所做的變更則照常運作。

快照是以 `pg_export_snapshot` 函式匯出（如[表 9.100](#functions-snapshot-synchronization-table) 所示），並以 [SET TRANSACTION](https://docs.postgresql.tw/19/reference/sql-commands/sql-set-transaction.md) 指令匯入。

### 表 9.100. 快照同步函式 [#](#functions-snapshot-synchronization-table) <a href="#functions-snapshot-synchronization-table" id="functions-snapshot-synchronization-table"></a>

| <p>函式</p><p>說明</p>                                                                                                                                                                                                                                                                                                                                                                                                                               |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><code>pg\_export\_snapshot</code> () → <code>text</code></p><p>儲存交易目前的快照，並回傳一個識別該快照的 <code>text</code> 字串。這個字串必須（在資料庫之外）傳給想要匯入該快照的用戶端。這個快照只在匯出它的交易結束之前可供匯入。</p><p>如有需要，一個交易可以匯出多個快照。請注意，這樣做只在 <code>READ COMMITTED</code> 交易中才有用，因為在 <code>REPEATABLE READ</code> 及更高的隔離等級中，交易在其整個生命週期內都使用同一個快照。一旦交易匯出了任何快照，就不能再以 <a href="https://docs.postgresql.tw/19/reference/sql-commands/sql-prepare-transaction.md">PREPARE TRANSACTION</a> 進行準備。</p> |
| <p><code>pg\_log\_standby\_snapshot</code> () → <code>pg\_lsn</code></p><p>擷取執行中交易的快照並寫入 WAL，而不必等待 bgwriter 或 checkpointer 記錄一筆。這對於在備用伺服器上進行邏輯解碼很有用，因為建立邏輯複寫槽必須等到這樣的紀錄在備用伺服器上重播之後才能進行。</p>                                                                                                                                                                                                                                                       |

<br>

[返回 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-snapshot-synchronization.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.
