我公司的网站使用 PostgreSQL 数据库。在我们的数据中心,我们有一个主数据库和一些只读的从数据库,我们使用 Londiste 在它们之间进行连续复制。
我想设置另一个只读从数据库用于报告目的,我希望这个从数据库位于远程位置(数据中心之外)。这个从站不需要 100% 最新。如果它长达 24 小时,那很好。另外,我想尽量减少我放在主数据库上的负载。由于我们的主数据库白天忙,晚上闲置,我认为一个好主意(如果可能的话)是每晚让报告从数据库 catch 一次。
我正在考虑为此使用日志传送,如上所述 http://www.postgresql.org/docs/8.4/static/continuous-archiving.html
我的计划是:
- 在主数据库上设置 WAL 归档
- 生成完整的数据库快照并将其复制到远程位置
- 恢复数据库并 catch 进度
- 进入稳定状态,其中:
- 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.
- Set up primary and standby systems as near identically as possible, including two identical copies of PostgreSQL at the same release level.
- 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).
- Make a base backup of the primary server (see Section 24.3.2), and load this data onto the standby.
- 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 应该在白天以非零退出状态退出。
附加信息:
关于PostgreSQL - 使用日志传送增量更新远程只读从站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4825598/