对于postgres,恢复postgres db时压缩xlog?
我使用'pg_dump'转储数据库,然后使用'psql'在其他服务器恢复数据库。我发现在pg_xlog /创建了大量的WAL日志,这消耗了大量的磁盘空间。
有什么办法可以让postgres自动压缩这些WAL日志吗?
我在postgres手册中看到'archive_command'设置。这是正确的方向吗?
杨
对于postgres,恢复postgres db时压缩xlog?
我使用'pg_dump'转储数据库,然后使用'psql'在其他服务器恢复数据库。我发现在pg_xlog /创建了大量的WAL日志,这消耗了大量的磁盘空间。
有什么办法可以让postgres自动压缩这些WAL日志吗?
我在postgres手册中看到'archive_command'设置。这是正确的方向吗?
杨
是,archive_command
是你要找的指令。从the manual:
archive_command (string)
的shell命令来执行归档完成的WAL文件段。 字符串中的任何%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'