PostgreSQL 9.4 Allow time delayed standbys and recovery

PostgreSQL 9.4 支持standby apply xlog有一个时间延迟的配置, 即使XLOG源源不断的从master节点接收过来, standby可以判断一下当前系统时间和xlog rec上的时间戳, 只有xlog rec是比系统时间早过配置的时间的XLOG才允许apply, 否则就暂停apply,

该配置名为min_recovery_apply_delay. 在standby节点的recovery.conf中配置.

例如配置了1个小时, 那么standby节点会接收xlog, 但是apply会在系统时间的前1个小时.

这样可以允许standby弥补一些问题, 例如主库发生了一次误操作, 这次误操作如果在1小时内发现的话, standby其实就是误操作以前的数据库状态.

min_recovery_apply_delay (integer)

By default, a standby server keeps restoring WAL records from the primary as soon as possible. It may be useful to have a time-delayed copy of the data, offering various options to correct data loss errors. This parameter allows you to delay recovery by a fixed period of time, specified in milliseconds if no unit is specified. For example, if you set this parameter to5min, the standby will replay each transaction commit only when the system time on the standby is at least five minutes past the commit time reported by the master.

It is possible that the replication delay between servers exceeds the value of this parameter, in which case no delay is added. Note that the delay is calculated between the WAL timestamp as written on master and the time on the current standby. Delays in transfer because of networks or cascading replication configurations may reduce the actual wait time significantly. If the system clocks on master and standby are not synchronised, this may lead to recovery applying records earlier than expected but is not a major issue because the useful settings of the parameter are much larger than typical time deviation between the servers. Be careful to allow for different timezone settings on master and standby.

The delay occurs only on WAL records for COMMIT and Restore Points. Other records may be replayed earlier than the specified delay, which is not an issue for MVCC though may potentially increase the number of recovery conflicts generated.

The delay occurs until the standby is promoted or triggered. After that the standby will end recovery without further waiting.

This parameter is intended for use with streaming replication deployments, however, if the parameter is specified it will be honoured in all cases. Synchronous replication is not affected by this setting because there is not yet any setting to request synchronous apply of transaction commits. hot_standby_feedback will be delayed by use of this feature which could lead to bloat on the master; use both together with care.

使用注意事项, 

1. 主库和standby节点的时间做好同步, 尽量使用同样的时间服务器.

2. 不要和hot_standby_feedback同时使用. 因为如果配置了feedback的话, 主节点的vacuum会根据feedback来判断是否要回收某些垃圾. 降低conflict

[参考]
1. http://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=36da3cfb457b77a55582f68208d815f11ac1399e

2. http://www.postgresql.org/docs/devel/static/archive-recovery-settings.html

时间: 2024-09-17 03:33:31

PostgreSQL 9.4 Allow time delayed standbys and recovery的相关文章

如何用好PostgreSQL的备份与恢复?

如何用好PostgreSQL的备份与恢复? 作者 赵成 日期 2017-10-22 标签 PostgreSQL , 数据库高可用 , 备份与恢复 高可用性是数据库的关键指标,简单说就是要做到故障时间短,数据不丢失,能够回退到指定位置(时间/事务).实现高可用的基础是数据库的备份与恢复技术. PostgreSQL备份与恢复操作涉及的参数和相关文件较多,内部逻辑关系较复杂,恢复分类方式容易混淆,这些都会影响到PostgreSQL高可用方案的实现. 本文首先介绍通常的数据库故障场景与处理方案,然后通过

PostgreSQL 10 流式物理、逻辑主从 最佳实践

标签 PostgreSQL , 流复制 , 主从 , 逻辑订阅 背景 流复制起源 PostgreSQL 自从2010年推出的9.0版本开始,支持流式物理复制,用户可以通过流式复制,构建只读备库(主备物理复制,块级别一致).流式物理复制可以做到极低的延迟(通常在1毫秒以内). 同步流复制 2011年推出的9.1版本,支持同步复制,当时只支持一个同步流复制备节点(例如配置了3个备,只有一个是同步模式的,其他都是异步模式). 在同步复制模式下,当用户提交事务时,需要等待这笔事务的WAL日志复制到同步流

rsync增量重置备库

--在主从复制环境中,如果从库不小心打开了读写模式(相当单节点的一个数据),比如 touch /usr/local/postgresql/9.3.4/5434/pgsql.recovery.trigger --此时从节点已经于主机点脱离,此时再把这个节点改为从节点时,由于从的timeline高于主,故该节点不能再变成从节点了 [postgres@rudy_01 5434]$ ls | grep recovery recovery.done [postgres@rudy_01 5434]$ pg_

PgSQL · 性能优化 · PostgreSQL TPC-C极限优化玩法

简介 本文以工业界测试模型TPC-C为测试模型,介绍PostgreSQL数据库从系统层面的优化到数据库层面的优化方法. TPmC从 256195.32 提升到 606466.31 是如何做到的. 测试环境介绍 16核开HT共32线程 256G 1600MHz 内存 万兆网卡 3 块 6.4TB AliFlash PCI-E SSD 逻辑卷条带 XFS 数据块对齐 XFS文件系统优化 主要分3块: 逻辑卷优化部分 XFS mkfs 优化部分 XFS mount 优化部分 以上几个部分都可以通过ma

元旦技术大礼包 - 2017金秋将要发布的PostgreSQL 10.0已装备了哪些核武器?

标签 PostgreSQL , 10.0 , 金秋 , 元旦 , 大礼包 , commitfest 背景 早上送给大家的新年大礼包,一年一个大版本是PostgreSQL社区的传统,虽然发布时间通常为秋天,还有一段时间,但是已经迫不及待地想看看2017金秋将要发布的10.0版本已经装备了哪些核武器. 放心,还会有一波又一波的feature和增强搭上开往2017金秋的列车,本文提到的可能只是其中的某一节车厢沃,PGer是不是开始有一点振奋人心的感觉啦. 1. 并行计算专属动态共享内存区,(加速索引扫

PostgreSQL 9.6 攻克金融级多副本可靠性问题

PostgreSQL 9.6 在可靠性方面再出杀手锏.通过流复制功能增强,提供多种可靠性模式可供用户根据需求进行选择,在可靠性和性能方面用户可以自由发挥.最强模式满足金融级的可靠性要求.如何做到的呢?PG允许多个同步流复制standby节点,用户在事务提交时,需要等待多个同步的standby apply xlog,从而保证数据的多副本一致性. 具体的增强如下.1. 事务提交保护级别增强如下支持5个事务提交保护级别,确保事务提交时,XLOG的几种状态.synchronous_commit =on,

为PostgreSQL讨说法 - 浅析《UBER ENGINEERING SWITCHED FROM POSTGRES TO MYSQL》

背景 最近有一篇文档,在国外闹得沸沸扬扬,是关于UBER使用mysql替换postgres原因的文章. 英文原文https://eng.uber.com/mysql-migration/ 来自高可用架构的 中文翻译 文章涉及到 PG数据库的部分,背后的原理并没有深入的剖析,导致读者对PostgreSQL的误解 . uber在文章阐述的遇到的PG问题 We encountered many Postgres limitations: Inefficient architecture for wri

PostgreSQL flashback(闪回) 功能实现与介绍

标签 PostgreSQL , 脏读 , 事务 , flashback , 闪回 , drop , truncate , dml 背景 闪回的需求往往是救命的需求,因为通常情况下数据库正常运行是不需要闪回的,往往是出现了误操作,被攻击,被注入后,数据库的数据被删除或恶意纂改并且纂改的事务已提交,也就是说纂改已经被持久化了. 这种情况下需要闪回来救命,回到被破坏前的状态. 闪回的目标分为两种: DML闪回和DDL闪回. DML闪回指对INSET, UPDATE, DELETE操作的闪回.DDL闪回

PostgreSQL 最佳实践 - pg_rman 数据库恢复示例 与 软件限制解说

背景 pg_rman备份已经讲完了,接下来讲一下数据恢复. 由于pg_rman使用了物理备份,所以恢复时,与普通物理备份的恢复原理是一样的. 需要将数据文件恢复,同时需要提供recovery.conf,在recovery.conf中指定需要恢复到哪个位置,以及如何获取XLOG归档文件等配置. 数据库恢复 pg_rman数据恢复时的两个必要要素 1. 新的$PGDATA 2. 备份目录 命令的选项也很简单,甚至可以不指定任何option Restore options: The parameter