文档章节

Postgresql HA cluster-Sync Rep+pg_rewind - part 2

s
 sysarch
发布于 2015/06/27 13:43
字数 585
阅读 219
收藏 0

This article explain how to build a data consistency capable Postgresql HA architecture by using Chained Cascading Replication. 

First of all,  async replication will cause 'time-delay data inconsistency'  is expected and  some type of applications can accept this kind of data inconsistency.   Within secnonds, the data in the stand-by machine will become consistent with the master machine. 

On the other hand,  'failure caused data inconsistency' may not be accpted by applications.  After failover,  an async replicated stand-by machine may contain a transaction  commit WAL record  which is NOT in the WAL records of  the promoted master machine.   The async stand-by machine may already send the transaction records to the customer thru read-only query.


Consider the following "parallel replication" topology:

A Master machine - MA1

A hot-standby machine connected to MA1 thru sync replication - SB1

Another hot-standby machine connected to MA1 thru async replication - SB2

If the below worst case scenario happen:

Here, T1, T2,… represent time point in the time line

T1.   MA1  issue a transaction (xid: TX1) Commit

T2.   MA1 Flush TX1 WAL to disk WAL records

T3.   WAL-sender from MA1 to SB1 is corrupted and MA1 CANNOT  send TX1 WAL records to SB1

T4.   MA1 send TX1 WAL records to SB2 thru another WAL sender (async replication)

T5.   TX1 is NOT committed in MA1 buffer memory and db storage, MA1 still wait for ack from SB1

T6.   SB2 apply the TX1 WAL records and answered a read-only query

T7.   MA1 fail

T8.   some how, SB2 fail also

T9.   Failover execute,  SB1 become the new master, name it   MA-SB1

The WAL-sender from MA1 to SB1 is corrupted at time T3,  there is no commit record for transaction TX1 MA-SB1.   Since SB1 is now the new master  MA-SB1,  SB2 should sync with MA-SB1.  However,  at time  T6,  SB2 apply the TX1 WAL records and answered a read-only query.  In this case, 'failure caused data inconsistency'!   Application need to take care and rectify this kind of data inconsistency


Consider the following "chained cascading replication" topology:

A Master machine - MA1

A hot-standby machine connected to MA1 thru sync replication - SB1

Another hot-standby machine connected to SB1 thru  cascading  async replication - SB2

The below scenario happen:

Here, T1, T2,… represent time point in the time line

T1.   MA1 issue a transaction (xid: TX1) Commit

T2.   MA1 Flush TX1 WAL to disk WAL records

T3.   WAL-sender from MA1 to SB1 is corrupted and MA1 CANNOT  send TX1 WAL records to SB1

T4.   SB2 can  only receive WAL records from SB1   (async replication),  on disk WAL record in SB2 is a SUBSET of  SB1 on disk  WAL records.

T5.   TX1 is NOT committed in MA1 buffer memory and db storage, MA1 still wait for ack from SB1

T6.   TX1 WAL records DOES NOT EXIST in  SB2,  NO record selected for the read-only query about TX1

T7.   MA1 fail

T8.   Failover execute,  SB1 become the new master, name it   MA-SB1,  on disk WAL record in SB2 is still a SUBSET of  SB1 on disk  WAL records.

T9.   Upgrade  SB2 to sync rep from MA-SB1

The  'failure caused data inconsistency' happened in "paralle replicatiion" CANNOT happen in "chained cascading replication" topology.


To make use of  postgresql  hot-standy HA, a load-balance component is needed.  For postgresql,  pgpool2 is a popular one.   I will talk about it in the next article.



Postgresql HA cluster-Sync Rep+pg_rewind - part 1

http://my.oschina.net/u/2399919/blog/469330

© 著作权归作者所有

共有 人打赏支持
s
粉丝 0
博文 3
码字总数 1710
作品 0
香港
PostgreSQL 11 preview - Allow on-line enabling and disabling of data checksums

标签 PostgreSQL , checksum , online modify , pgverifychecksums , pgenabledatachecksums , pgdisabledatachecksums 背景 PostgreSQL的数据文件是以数据块组织的,由于数据块可能比文件系......

德哥
05/06
0
0
PostgreSQL 一主多从(多副本,强同步)简明手册 - 配置、压测、监控、切换、防脑裂、修复、0丢失 - 珍藏级

标签 PostgreSQL , 多副本 , 一主多从 , 流复制 背景 PostgreSQL物理流复制有几个特点 1、延迟及低,毫不畏惧大事务 2、支持断点续传 3、支持多副本 4、配置简单,看本文 5、备库与主库物理完...

德哥
04/18
0
0
PostgreSQL jdbc multi-host 配置与简单HA、Load Balance实现

标签 PostgreSQL , HA , jdbc , multi host , targetsessionattrs 背景 pg jdbc 与libpq一样,都是PG的连接驱动,都支持multi-master ,同时pg jdbc还支持了loadbalance。 《PostgreSQL libp......

德哥
09/15
0
0
PostgreSQL数据库的升级

小版本升级 小版本升级基本上差不多,具体看postgresql的release note,注意其中的注意事项。 以9.2.4升级到9.2.7为例 1、备份原数据目录文件,以防万一。 2、下载9.2.7:wget http://get.e...

章郎虫
2014/03/03
0
0
PostgreSQL基于流复制的HA实现

继上两周由DBA+杭州群联合发起人周正中带来的数据库安全专题分享,本周起,他将为大家分享数据库管理专题,以下讲解的是PostgreSQL基于流复制的HA实现。 专家简介 周正中 网名:德哥@Digoal...

德哥@Digoal
2015/10/27
0
0

没有更多内容

加载失败,请刷新页面

加载更多

为什么 vue 默认导出的是 vue.common.js,它和 vue.js 的区别在哪里,又有什么关系?

这个问题在囧克斯的博客中有提到。 Vue 最早会打包生成三个文件,一个是 runtime only 的文件 vue.common.js,一个是 compiler only 的文件 compiler.js,一个是 runtime + compiler 的文件 ...

粒子数反转
21分钟前
1
0
php正则表达式替换图片地址

<?php /*PHP正则提取图片img标记中的任意属性*/ $str = '<center><img src="/uploads/images/20100516000.jpg" height="120" width="120"><br />PHP正则提取或更改图片img标记中的任意属性<......

mdoo
25分钟前
0
0
一个简单的系统监控脚本

一个简单的系统信息监控脚本 #!/bin/bash# DATE:20181018# System monitor by Kxvzinterval=5while :doecho '==========================================================...

Kxvz
28分钟前
1
0
七牛云助你度寒冬 | 每天 10:24, 新用户抢全额免单

近年来,中美贸易战、股市暴跌、房地产变天、人民币贬值等等,企业艰难生存于冰川夹缝之中,融资发展难上加难。 凛冬将至, 七牛云特此推出免单好礼,为新用户(2018 年 10 月 10 日后新注册...

七牛云
29分钟前
0
0
Echarts X轴刻度标签换行显示

xAxis: [ { 'type':'category', splitLine: {show: false}, axisLabel: { show: true,//是否显示 interval:0,//强制显示 ......

郭周园
34分钟前
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部