PostgreSQL 9.1,9.2,9.3 clean switchover Primary and Standby Patch.

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介:
前段时间在使用9.3 beta2的流复制时发现无法完成主备数据库的角色互相切换. 原因是备节点的receiver进程在知晓主节点的sender进程关闭后也会自动关闭,可能导致无法接收primary节点关闭时完全的xlog信息. 因此角色无法互相切换.
9.3beta2发布的第二天这个补丁就提交了, 如下  : 
author Fujii Masao <fujii@postgresql.org>

Tue, 25 Jun 2013 17:14:37 +0000 (02:14 +0900)
committer Fujii Masao <fujii@postgresql.org>

Tue, 25 Jun 2013 17:14:37 +0000 (02:14 +0900)
commit 985bd7d49726c9f178558491d31a570d47340459
tree 765e3c0e22ee4991c5fb0b00dd8888e8161f4422 tree | snapshot
parent 4f14c86d7434376b95477aeeb07fcc7272f4c47d commit | diff
Support clean switchover.

In replication, when we shutdown the master, walsender tries to send
all the outstanding WAL records to the standby, and then to exit. This
basically means that all the WAL records are fully synced between
two servers after the clean shutdown of the master. So, after
promoting the standby to new master, we can restart the stopped
master as new standby without the need for a fresh backup from
new master.

But there was one problem so far: though walsender tries to send all
the outstanding WAL records, it doesn't wait for them to be replicated
to the standby. Then, before receiving all the WAL records,
walreceiver can detect the closure of connection and exit. We cannot
guarantee that there is no missing WAL in the standby after clean
shutdown of the master. In this case, backup from new master is
required when restarting the stopped master as new standby.

This patch fixes this problem. It just changes walsender so that it
waits for all the outstanding WAL records to be replicated to the
standby before closing the replication connection.

Per discussion, this is a fix that needs to get backpatched rather than
new feature. So, back-patch to 9.1 where enough infrastructure for
this exists.

Patch by me, reviewed by Andres Freund.
src/backend/replication/walsender.c
diff | blob | blame | history

这个补丁支持9.1,9.2,9.3三个版本.
9.0因为流复制架构问题不支持这个补丁.
In 9.0, the standby doesn't send back any message to the master and
there is no way to know whether replication has been done up to
the specified location, so I don't think that we can backpatch.

下面来测试一下. 打补丁.
将新版本的walsender.c下载到源码对应目录下替换原有文件.
例如我这里的话替换 :

pg93@db-172-16-3-39-> ll /opt/soft_bak/postgresql-9.3beta2/src/backend/replication/walsender.c
-rw-r--r-- 1 root root 58K Jul 19 07:50 /opt/soft_bak/postgresql-9.3beta2/src/backend/replication/walsender.c

替换后重新编译安装.
pg93@db-172-16-3-39-> cd /opt/soft_bak/postgresql-9.3beta2
pg93@db-172-16-3-39-> gmake world
pg93@db-172-16-3-39-> gmake install-world

重启数据库 :
pg_ctl restart -m fast

重新做主备角色切换测试正常.
感谢Fujii Masao和Andres Freund.
最后建议大家将9.1, 9.2, 9.3 的版本都打上这个补丁.

[参考]
相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
关系型数据库 流计算 PostgreSQL
|
2月前
|
关系型数据库 分布式数据库 数据库
成都晨云信息技术完成阿里云PolarDB数据库产品生态集成认证
近日,成都晨云信息技术有限责任公司(以下简称晨云信息)与阿里云PolarDB PostgreSQL版数据库产品展开产品集成认证。测试结果表明,晨云信息旗下晨云-站群管理系统(V1.0)与阿里云以下产品:开源云原生数据库PolarDB PostgreSQL版(V11),完全满足产品兼容认证要求,兼容性良好,系统运行稳定。
|
2月前
|
关系型数据库 分布式数据库 数据库
PolarDB常见问题之数据库不能自己减少节点如何解决
PolarDB是阿里云推出的下一代关系型数据库,具有高性能、高可用性和弹性伸缩能力,适用于大规模数据处理场景。本汇总囊括了PolarDB使用中用户可能遭遇的一系列常见问题及解答,旨在为数据库管理员和开发者提供全面的问题指导,确保数据库平稳运行和优化使用体验。
|
6天前
|
分布式计算 DataWorks 关系型数据库
DataWorks产品使用合集之在使用 DataWorks 数据集成同步 PostgreSQL 数据库中的 Geometry 类型数据如何解决
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。
16 0