在PostgreSQL 9.2中,流式复制需要归档吗?

时间:2013-10-16 15:33:27

标签: postgresql streaming replication archiving

允许和/或合理地将主PostgreSQL 9.2服务器配置为NOT存档但是执行流复制。配置如下:

wal_level = hot_standby
archive_mode = off

“slave”服务器(热备用)是否可以配置为存档WAL段?

wal_level = hot_standby
hot_standby = on
archive_mode = on

这将允许主服务器上的归档网络流量减少一半(复制但不归档)。这似乎是合理的,文档似乎支持这种配置,但我更喜欢保证我们有一个良好的配置。

2 个答案:

答案 0 :(得分:9)

来自documentation(我自己强力补充):

  

如果您使用没有基于文件的连续存档的流式复制,则必须将主服务器中的 wal_keep_segments 设置为值足够高,以确保旧的WAL段不是过早回收,而待机可能仍需要他们赶上。 如果备用数据库落后太多,则需要从新的基本备份重新初始化。如果设置可从备用数据库访问的WAL存档,则不需要wal_keep_segments,因为备用数据库始终可以使用存档以赶上。

因此,根据我的理解,当你有太多的事务在运行时,奴隶可能有一些困难时间保持同步。特别是如果主服务器在奴隶真正得到内部之前删除了WAL文件。在主服务器上没有archive_mode的情况下,可以删除WAL文件,而不会让任何方法让它们恢复。

如果保持WAL归档到位并在工作热备份与归档结构上添加流,这不可能发生,因为奴隶总是可以访问归档的WAL并且一旦较低的活动就会恢复未同步的事务在流上允许它。如果没有访问存档,风险显然会在一些非常繁重的东西之后失去奴隶的完整性。

答案 1 :(得分:1)

我不知道这是否是真正的“官方认证”,我也不认为这是最近的,但是它来自PostgreSQL Wiki。(https://wiki.postgresql.org/wiki/Streaming_Replication

第5步,指定有趣的评论,与帖子的答案一致:

# To enable read-only queries on a standby server, wal_level must be set to
# "hot_standby". But you can choose "archive" if you never connect to the
# server in standby mode.
wal_level = hot_standby

# Set the maximum number of concurrent connections from the standby servers.
max_wal_senders = 5

# To prevent the primary server from removing the WAL segments required for
# the standby server before shipping them, set the minimum number of segments
# retained in the pg_xlog directory. At least wal_keep_segments should be
# larger than the number of segments generated between the beginning of
# online-backup and the startup of streaming replication. If you enable WAL
# archiving to an archive directory accessible from the standby, this may
# not be necessary.
wal_keep_segments = 32

# 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'