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

# 第 49 章 封存模組

### 第 49 章 封存模組

**目錄**

* [49.1. 初始化函式](https://docs.postgresql.tw/19/server-programming/archive-modules/archive-module-init.md)
* [49.2. 封存模組回呼](https://docs.postgresql.tw/19/server-programming/archive-modules/archive-module-callbacks.md)
  * [49.2.1. 啟動回呼](https://docs.postgresql.tw/19/server-programming/archive-modules/archive-module-callbacks.md#archive-module-startup)
  * [49.2.2. 檢查回呼](https://docs.postgresql.tw/19/server-programming/archive-modules/archive-module-callbacks.md#archive-module-check)
  * [49.2.3. 封存回呼](https://docs.postgresql.tw/19/server-programming/archive-modules/archive-module-callbacks.md#archive-module-archive)
  * [49.2.4. 關閉回呼](https://docs.postgresql.tw/19/server-programming/archive-modules/archive-module-callbacks.md#archive-module-shutdown)

PostgreSQL 提供了基礎架構，可用來建立自訂的連續封存模組 （見[25.3 節](https://docs.postgresql.tw/19/server-administration/backup/continuous-archiving.md)）。 雖然透過 shell 指令進行封存（也就是 [archive\_command](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-wal.md#GUC-ARCHIVE-COMMAND)） 簡單得多，但自訂封存模組通常會更加穩健且更具效能。

當設定了自訂的 [archive\_library](https://docs.postgresql.tw/19/server-administration/runtime-config/runtime-config-wal.md#GUC-ARCHIVE-LIBRARY) 之後，PostgreSQL 會將已完成的 WAL 檔案提交給該模組， 且伺服器在該模組指出這些檔案已成功封存之前， 都會避免回收或移除這些 WAL 檔案。至於每個 WAL 檔案該如何處理， 最終取決於該模組，但 [25.3.1 節](https://docs.postgresql.tw/19/server-administration/backup/continuous-archiving.md#backup-archiving-wal) 列出了許多建議做法。

封存模組至少必須包含一個初始化函式（見 [49.1 節](https://docs.postgresql.tw/19/server-programming/archive-modules/archive-module-init.md)）以及所需的回呼函式（見 [49.2 節](https://docs.postgresql.tw/19/server-programming/archive-modules/archive-module-callbacks.md)）。不過，封存模組 也允許做更多事情（例如宣告 GUC 或註冊背景工作程序）。

`contrib/basic_archive` 模組包含一個可運作的範例， 展示了一些實用的技巧。

***

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


---

# 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/archive-modules.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.
