【问题标题】:In PostgreSQL 9.2, is archiving required for streaming replication?在 PostgreSQL 9.2 中,流复制是否需要归档?
【发布时间】:2013-10-16 15:33:27
【问题描述】:

是否允许和/或合理地将主 PostgreSQL 9.2 服务器配置为不归档但执行流复制。就是这样配置的:

wal_level = hot_standby
archive_mode = off

可以将“从”服务器(热备用)配置为归档 WAL 段吗?

wal_level = hot_standby
hot_standby = on
archive_mode = on

这将使主服务器上的归档网络流量减少一半(复制但不归档)。这似乎是合理的,文档似乎支持这种配置,但我更希望我们有一个很好的配置。

【问题讨论】:

    标签: postgresql streaming replication archiving


    【解决方案1】:

    来自documentation(强由我自己添加):

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

    因此,据我了解,当您运行的事务过多时,从属服务器可能很难保持同步。特别是如果主人在奴隶真正得到里面的东西之前删除了 WAL 文件。如果 master 上没有archive_mode,WAL 文件可能会被删除,而不会留下任何取回它们的方法。

    如果您将 WAL 归档保留在适当的位置,并将流添加到工作的 hot-standby-with-archives 结构上,则不会发生这种情况,因为从站始终可以访问已归档的 WAL,并且会在活动减少时立即取回未同步的事务在流上允许它。如果无法访问存档,风险显然是在一些非常重的东西之后失去你的奴隶完整性。

    【讨论】:

    • 如果使用archive_mode,请注意这些日志的归档位置。重要的是不要将位置放在引导分区或 Postgres 使用的分区上,因为它们最终会填满该分区并且你会被淹没。存档位置最好在不同的服务器上。
    • @medley56 是的,根据定义,archiving 的目标是将这些文件放在安全的地方,/boot 在同一台服务器上将是存储备份的最糟糕的地方之一。
    • 如果archive_mode = off,是否意味着postgres会自动将WAL日志轮换出pg_xlog
    【解决方案2】:

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

    第5步,指定有趣的cmets,和帖子的答案不谋而合:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-28
      相关资源
      最近更新 更多