Postgresql 中文操作指南
51.2. Archive Module Callbacks #
归档回调定义了模块的实际归档行为。服务器将根据需要调用它们来处理每个单独的 WAL 文件。
The archive callbacks define the actual archiving behavior of the module. The server will call them as required to process each individual WAL file.
51.2.1. Startup Callback #
模块加载后不久便会调用 startup_cb 回调。此回调用于执行所需的任何其他初始化。如果存档模块具有任何状态,它可以使用 state→private_data 来存储它。
The startup_cb callback is called shortly after the module is loaded. This callback can be used to perform any additional initialization required. If the archive module has any state, it can use state→private_data to store it.
typedef void (*ArchiveStartupCB) (ArchiveModuleState *state);
51.2.2. Check Callback #
调用 check_configured_cb 回调来确定模块是否已完全配置并准备接受 WAL 文件(例如,其配置参数已设置为有效值)。如果未定义 check_configured_cb ,服务器始终假设该模块已配置。
The check_configured_cb callback is called to determine whether the module is fully configured and ready to accept WAL files (e.g., its configuration parameters are set to valid values). If no check_configured_cb is defined, the server always assumes the module is configured.
typedef bool (*ArchiveCheckConfiguredCB) (ArchiveModuleState *state);
如果返回 true ,服务器将通过调用 archive_file_cb 回调继续对文件进行存档。如果返回 false ,存档将不会继续,并且存档程序将向服务器日志发出以下消息:
If true is returned, the server will proceed with archiving the file by calling the archive_file_cb callback. If false is returned, archiving will not proceed, and the archiver will emit the following message to the server log:
WARNING: archive_mode enabled, yet archiving is not configured
在后一种情况下,服务器将定期调用此函数,并且只有在函数返回 true 时存档才会继续。
In the latter case, the server will periodically call this function, and archiving will proceed only when it returns true.
51.2.3. Archive Callback #
调用 archive_file_cb 回调来存档单个 WAL 文件。
The archive_file_cb callback is called to archive a single WAL file.
typedef bool (*ArchiveFileCB) (ArchiveModuleState *state, const char *file, const char *path);
如果返回 true ,服务器将继续操作,就好像该文件已成功存档一样,其中可能包括回收或删除原始 WAL 文件。如果返回 false ,服务器将保留原始 WAL 文件并稍后再尝试存档。file 将仅包含要存档的 WAL 文件的文件名,而 path 将包含 WAL 文件的完整路径(包括文件名)。
If true is returned, the server proceeds as if the file was successfully archived, which may include recycling or removing the original WAL file. If false is returned, the server will keep the original WAL file and retry archiving later. file will contain just the file name of the WAL file to archive, while path contains the full path of the WAL file (including the file name).
51.2.4. Shutdown Callback #
在存档进程退出时(例如,在错误出现后)或 archive_library 的值发生改变时,会调用 shutdown_cb 回调。如果没有定义 shutdown_cb ,则在这些情况下不会执行任何特殊操作。如果存档模块有任何状态,则此回调应释放它以避免泄漏。
The shutdown_cb callback is called when the archiver process exits (e.g., after an error) or the value of archive_library changes. If no shutdown_cb is defined, no special action is taken in these situations. If the archive module has any state, this callback should free it to avoid leaks.
typedef void (*ArchiveShutdownCB) (ArchiveModuleState *state);