PostgreSQL - 使用日志传送增量更新远程只读从属服务器
我公司的网站使用PostgreSQL数据库。在我们的数据中心,我们有一个主数据库和一些只读从数据库,我们使用 Londiste 在它们之间进行连续复制。
我想设置另一个只读从属数据库用于报告目的,并且我希望该从属数据库位于远程位置(数据中心之外)。该从站不需要 100% 是最新的。如果长达 24 小时,那就没问题。另外,我想尽量减少主数据库上的负载。由于我们的主数据库白天忙碌,晚上空闲,所以我认为一个好主意(如果可能的话)是让报告从属数据库每晚赶上一次。
我正在考虑为此使用日志传送,如上所述 http://www.postgresql.org/docs/8.4/static/continuous -archiving.html
我的计划是:
- 在主数据库上设置 WAL 归档
- 生成完整的数据库快照并将其复制到远程位置
- 恢复数据库并让它恢复正常
- 进入稳定状态,其中:
- 白天——数据库落后了,但人们可以查询它
- 晚上——我复制一天的 WAL 文件并让数据库赶上
注意:这里的关键是我只需要复制一次完整的数据库快照。此后,我只需复制一天的 WAL 文件即可让远程从属设备再次恢复正常。
因为我之前没有做过日志传送,所以我想要一些反馈/建议。
这行得通吗? PostgreSQL支持这种重复恢复吗?
对于如何设置远程半新鲜只读从站,您还有其他建议吗?
谢谢!
--S
My company's website uses a PostgreSQL database. In our data center we have a master DB and a few read-only slave DB's, and we use Londiste for continuous replication between them.
I would like to setup another read-only slave DB for reporting purposes, and I'd like this slave to be in a remote location (outside the data center). This slave doesn't need to be 100% up-to-date. If it's up to 24 hours old, that's fine. Also, I'd like to minimize the load I'm putting on the master DB. Since our master DB is busy during the day and idle at night, I figure a good idea (if possible) is to get the reporting slave caught up once each night.
I'm thinking about using log shipping for this, as described on
http://www.postgresql.org/docs/8.4/static/continuous-archiving.html
My plan is:
- Setup WAL archiving on the master DB
- Produce a full DB snapshot and copy it to the remote location
- Restore the DB and get it caught up
- Go into steady state where:
- DAYTIME -- the DB falls behind but people can query it
- NIGHT -- I copy over the day's worth of WAL files and get the DB caught up
Note: the key here is that I only need to copy a full DB snapshot one time. Thereafter I should only have to copy a day's worth of WAL files in order to get the remote slave caught up again.
Since I haven't done log-shipping before I'd like some feedback / advice.
Will this work? Does PostgreSQL support this kind of repeated recovery?
Do you have other suggestions for how to set up a remote semi-fresh read-only slave?
thanks!
--S
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的计划应该可行。
正如查尔斯所说,热备用是另一种可能的解决方案。它从 8.2 开始受支持,对主服务器的性能影响相对较低。
热备份在手册中有记录:PostgreSQL 8.4 热备份
要仅实现夜间同步,您的 archive_command 应在白天以非零退出状态退出。
其他信息:
有关热备份的 Postgres Wiki
博客文章热备份设置
Your plan should work.
As Charles says, warm standby is another possible solution. It's supported since 8.2 and has relatively low performance impact on the primary server.
Warm Standby is documented in the Manual: PostgreSQL 8.4 Warm Standby
To achieve only nightly syncs, your archive_command should exit with a non-zero exit status during daytime.
Additional Informations:
Postgres Wiki about Warm Standby
Blog Post Warm Standby Setup
9.0内置的WAL流式复制旨在完成一些应该满足您的目标的事情——可以接受只读查询的温备用或热备用。您是否考虑过使用它,或者您现在还停留在 8.4 上?
(此外,即将发布的 9.1 版本预计将包括 pg_basebackup,一个为新从站创建初始备份点的工具。)
更新:PostgreSQL 9.1 将包含通过简单的函数调用暂停和恢复流复制的功能在奴隶上。
9.0's built-in WAL streaming replication is designed to accomplish something that should meet your goals -- a warm or hot standby that can accept read-only queries. Have you considered using it, or are you stuck on 8.4 for now?
(Also, the upcoming 9.1 release is expected to include an updated/rewritten version of pg_basebackup, a tool for creating the initial backup point for a fresh slave.)
Update: PostgreSQL 9.1 will include the ability to pause and resume streaming replication with a simple function call on the slave.