PostgreSQL - 使用日志传送增量更新远程只读从站

标签 postgresql replication log-shipping

我公司的网站使用 PostgreSQL 数据库。在我们的数据中心,我们有一个主数据库和一些只读的从数据库,我们使用 Londiste 在它们之间进行连续复制。

我想设置另一个只读从数据库用于报告目的,我希望这个从数据库位于远程位置(数据中心之外)。这个从站不需要 100% 最新。如果它长达 24 小时,那很好。另外,我想尽量减少我放在主数据库上的负载。由于我们的主数据库白天忙,晚上闲置,我认为一个好主意(如果可能的话)是每晚让报告从数据库 catch 一次。

我正在考虑为此使用日志传送,如上所述 http://www.postgresql.org/docs/8.4/static/continuous-archiving.html

我的计划是:

  1. 在主数据库上设置 WAL 归档
  2. 生成完整的数据库快照并将其复制到远程位置
  3. 恢复数据库并 catch 进度
  4. 进入稳定状态,其中:
    • DAYTIME -- 数据库落后但人们可以查询它
    • 晚上 -- 我复制了当天的 WAL 文件并让数据库 catch 了

注意:这里的关键是我只需要复制一次完整的数据库快照。此后,我只需要复制一天的 WAL 文件,就可以再次启动远程从站。

因为我之前没有做过日志传送,所以我想要一些反馈/建议。

这行得通吗? PostgreSQL 支持这种重复恢复吗?

对于如何设置远程半新只读从站,您还有其他建议吗?

谢谢!

--S

最佳答案

您的计划应该可行。
正如 Charles 所说,暖备用是另一种可能的解决方案。它从 8.2 开始受支持,并且对主服务器的性能影响相对较低。 暖待机记录在手册中:PostgreSQL 8.4 Warm Standby

The short procedure for configuring a standby server is as follows. For full details of each step, refer to previous sections as noted.

  1. Set up primary and standby systems as near identically as possible, including two identical copies of PostgreSQL at the same release level.
  2. Set up continuous archiving from the primary to a WAL archive located in a directory on the standby server. Ensure that archive_mode, archive_command and archive_timeout are set appropriately on the primary (see Section 24.3.1).
  3. Make a base backup of the primary server (see Section 24.3.2), and load this data onto the standby.
  4. Begin recovery on the standby server from the local WAL archive, using a recovery.conf that specifies a restore_command that waits as described previously (see Section 24.3.3).

要仅实现夜间同步,您的 archive_command 应该在白天以非零退出状态退出。

附加信息:

Postgres Wiki about Warm Standby

Blog Post Warm Standby Setup

关于PostgreSQL - 使用日志传送增量更新远程只读从站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4825598/

相关文章:

postgresql - 连接到 Postgresql 数据库并执行 SQL 命令时调用 Sqlcmd 失败

database - 通过两个不同的表获取派生属性

sql - 使用 OR 在多个列上优先加入 JOIN

database - 如何在 PostgreSQL 中复制 DDL 更改

azure - Microsoft Azure RA-GRS 存储 - 在 Microsoft 管理的故障转移到次要区域后,数据是否仍进行异地复制?

Postgresql pg_standby 需要永远执行故障转移

mysql - 可以查看数据库的简化或优化的 SQL 查询吗?

MySQL Master <=(Slave,Master)=> Slave

sql-server - 事务日志传送与备份作业=冲突?

postgresql - 日志传送过程(archive_timeout)