> 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/server-programming/archive-modules.md).

# Chapter 49. Archive Modules

**Table of Contents**

[49.1. Initialization Functions](/server-programming/archive-modules/archive-module-init.md)

[49.2. Archive Module Callbacks](/server-programming/archive-modules/archive-module-callbacks.md) : [49.2.1. Startup Callback](/server-programming/archive-modules/archive-module-callbacks.md#ARCHIVE-MODULE-STARTUP)

```
[49.2.2. Check Callback](archive-module-callbacks.md#ARCHIVE-MODULE-CHECK)

[49.2.3. Archive Callback](archive-module-callbacks.md#ARCHIVE-MODULE-ARCHIVE)

[49.2.4. Shutdown Callback](archive-module-callbacks.md#ARCHIVE-MODULE-SHUTDOWN)
```

PostgreSQL provides infrastructure to create custom modules for continuous archiving (see [Section 25.3](/server-administration/backup/continuous-archiving.md)). While archiving via a shell command (i.e., [archive\_command](/server-administration/runtime-config/runtime-config-wal.md#GUC-ARCHIVE-COMMAND)) is much simpler, a custom archive module will often be considerably more robust and performant.

When a custom [archive\_library](/server-administration/runtime-config/runtime-config-wal.md#GUC-ARCHIVE-LIBRARY) is configured, PostgreSQL will submit completed WAL files to the module, and the server will avoid recycling or removing these WAL files until the module indicates that the files were successfully archived. It is ultimately up to the module to decide what to do with each WAL file, but many recommendations are listed at [Section 25.3.1](/server-administration/backup/continuous-archiving.md#BACKUP-ARCHIVING-WAL).

Archiving modules must at least consist of an initialization function (see [Section 49.1](/server-programming/archive-modules/archive-module-init.md)) and the required callbacks (see [Section 49.2](/server-programming/archive-modules/archive-module-callbacks.md)). However, archive modules are also permitted to do much more (e.g., declare GUCs and register background workers).

The `contrib/basic_archive` module contains a working example, which demonstrates some useful techniques.

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/archive-modules.html)（英文原文，待翻譯）


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.postgresql.tw/server-programming/archive-modules.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
