0

对于postgres,

我使用“pg_dump”转储数据库,然后使用“psql”在另一台服务器上恢复数据库。我发现在 pg_xlog/ 创建了大量的 WAL 日志,这消耗了大量的磁盘空间。

postgres 有没有办法自动压缩这些 WAL 日志?

我在 postgres 的手册中看到了“archive_command”设置。这是正确的方向吗?

4

1 回答 1

0

是的,archive_command是您正在寻找的指令。从手册

archive_command (string)

要执行以归档已完成的 WAL 文件段的 shell 命令。字符串中的任何 %p 都将替换为要归档的文件的路径名,而任何 %f 仅替换为文件名。(路径名是相对于服务器的工作目录,即集群的数据目录。) 使用%% 在命令中嵌入一个实际的% 字符。该命令只有在成功时才返回零退出状态,这一点很重要。有关详细信息,请参阅第 24.3.1 节。

此参数只能在 postgresql.conf 文件或服务器命令行中设置。除非在服务器启动时启用了 archive_mode,否则它会被忽略。如果 archive_command 是一个空字符串(默认值),而 archive_mode 被启用,WAL 归档被暂时禁用,但服务器继续积累 WAL 段文件,以期很快就会提供一个命令。将archive_command 设置为只返回true 的命令,例如/bin/true(Windows 上的REM),有效地禁用归档,但也会破坏归档恢复所需的WAL 文件链,因此它应该只在不寻常的情况下使用。

Postgres wiki有一个例子:

# Enable WAL archiving on the primary to an archive directory accessible from
# the standby. If wal_keep_segments is a high enough number to retain the WAL
# segments required for the standby server, this is not necessary.
archive_mode    = on
archive_command = 'cp %p /path_to/archive/%f'
于 2014-01-16T20:45:58.310 回答