repmgr出现双主,并且时间线分叉,删除了最新的时间线节点

news2024/9/23 7:30:54

 遇到的问题如下:

2023-08-17 20:24:21.566 CST [1556001] LOG:  database system was interrupted; last known up at 2023-08-17 20:21:41 CST
2023-08-17 20:24:21.770 CST [1556001] LOG:  restored log file "00000009.history" from archive
cp: 无法获取'/home/postgres/pgarch/0000000A.history' 的文件状态(stat): 没有那个文件或目录
2023-08-17 20:24:21.771 CST [1556001] LOG:  entering standby mode
2023-08-17 20:24:21.772 CST [1556001] LOG:  restored log file "00000009.history" from archive
cp: 无法获取'/home/postgres/pgarch/000000090000010200000066' 的文件状态(stat): 没有那个文件或目录
2023-08-17 20:24:21.784 CST [1556001] LOG:  restored log file "000000080000010200000066" from archive
2023-08-17 20:24:21.851 CST [1556001] FATAL:  requested timeline 9 is not a child of this server's history
2023-08-17 20:24:21.851 CST [1556001] DETAIL:  Latest checkpoint is at 102/66000060 on timeline 8, but in the history of the requested timeline, the server forked off from that timeline at 102/580000A0.
2023-08-17 20:24:21.851 CST [1555991] LOG:  startup process (PID 1556001) exited with exit code 1
2023-08-17 20:24:21.851 CST [1555991] LOG:  aborting startup due to startup process failure
2023-08-17 20:24:21.851 CST [1555991] LOG:  database system is shut down
 

出现上面的原因是repmgr出现了双主。

在db206的主机上修改了shared_preload_libraries = 'pg_stat_statements',试图重启,发现无法启动(没有提前创建pg_stat_statements扩展)导致。

[postgres@db206 data]$ vi postgresql.conf
[postgres@db206 data]$ pg_ctl restart
waiting for server to shut down...... done
server stopped
waiting for server to start....2023-08-17 18:11:53.086 CST [6497] FATAL:  could not access file "pg_stat_statements": 没有那个文件或目录
2023-08-17 18:11:53.086 CST [6497] LOG:  database system is shut down
 stopped waiting
pg_ctl: could not start server

这个时候 vi postgresql.conf 把shared_preload_libraries = 'pg_stat_statements'去掉,再次启动数据库,可以启动,试图创建,这个时候备机已经接管主机了

这个时候想起来先去修改db223的shared_preload_libraries = 'pg_stat_statements'(先在备机上给加上)

[postgres@db223 ~]$ vi pg14/data/postgresql.conf

这个时候发现出现了双主(暂时还不知道为什么会出现双主),这个时候时间线也不一样,新主是9,旧主是8

[postgres@db206 data]$  repmgr -f ~/repmgr/repmgr.conf  cluster show
 ID | Name  | Role    | Status               | Upstream | Location | Priority | Timeline | Connection string
----+-------+---------+----------------------+----------+----------+----------+----------+------------------------------------------------------------------------
 1  | db223 | standby | ! running as primary |          | default  | 100      | 9        | host=db223 dbname=repmgr user=repmgr password=repmgr connect_timeout=2
 2  | db206 | primary | * running            |          | default  | 100      | 8        | host=db206 dbname=repmgr user=repmgr password=repmgr connect_timeout=2

WARNING: following issues were detected
  - node "db223" (ID: 1) is registered as standby but running as primary


 试图对从节点进行重新注册操作,提示需要先启动数据库。

 

[postgres@db206 data]$ repmgr -f /home/postgres/repmgr/repmgr.conf standby unregister
INFO: connecting to local standby
ERROR: connection to database failed
DETAIL:
connection to server at "db206" (172.20.101.206), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?

DETAIL: attempted to connect using:
  user=repmgr password=repmgr connect_timeout=2 dbname=repmgr host=db206 fallback_application_name=repmgr options=-csearch_path=

 启动之后重新执行命令,又提示现在是主节点。

[postgres@db206 data]$ repmgr -f /home/postgres/repmgr/repmgr.conf standby unregister
INFO: connecting to local standby
INFO: connecting to primary database
ERROR: node 2 is not a standby server

 然后试图对主节点执行注销操作,又说db233节点仍然将此节点作为其上游节点。提示:使用“repmgr standby follow”确保这些节点遵循当前的主节点。

[postgres@db206 data]$ repmgr -f /home/postgres/repmgr/repmgr.conf primary unregister
ERROR: 1 other node still has this node as its upstream node
HINT: ensure these nodes are following the current primary with "repmgr standby follow"
DETAIL: the affected node(s) are:
  db223 (ID: 1)

这个时候对db223重新加入集群,发现不能在正在运行的节点上执行

[postgres@db223 ~]$ repmgr -f ~/repmgr/repmgr.conf node rejoin -d 'host=db206 port=5432 user=repmgr dbname=repmgr password=repmgr'
ERROR: database is still running in state "in production"
HINT: "repmgr node rejoin" cannot be executed on a running node
 

 停止数据库后,再次执行,这个时候没有报错

[postgres@db223 ~]$ repmgr -f ~/repmgr/repmgr.conf node rejoin -d 'host=db206 port=5432 user=repmgr dbname=repmgr password=repmgr' -F
NOTICE: rejoin target is node "db206" (ID: 2)
NOTICE: pg_rewind execution required for this node to attach to rejoin target node 2
HINT: provide --force-rewind
 

重新启动db223,发现还是作为主节点加入,这就很崩溃了。

pg_ctl start

[postgres@db223 ~]$ repmgr -f ~/repmgr/repmgr.conf cluster show
 ID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+------------------------------------------------------------------------
 1  | db223 | primary | * running |          | default  | 100      | 9        | host=db223 dbname=repmgr user=repmgr password=repmgr connect_timeout=2
 2  | db206 | primary | ! running |          | default  | 100      | 8        | host=db206 dbname=repmgr user=repmgr password=repmgr connect_timeout=2

WARNING: following issues were detected
  - node "db206" (ID: 2) is running but the repmgr node record is inactive

 

 这个时候加上pg_rewind操作是不是就好了呢,发现还是不行,无法读到时间线9的,不知道为什么要读9的时间线,估计还是作为主节点加入吧。

[postgres@db223 ~]$ repmgr -f ~/repmgr/repmgr.conf node rejoin -d 'host=db206 port=5432 user=repmgr dbname=repmgr password=repmgr' --force-rewind
NOTICE: rejoin target is node "db206" (ID: 2)
NOTICE: executing pg_rewind
DETAIL: pg_rewind command is "/home/postgres/pg14/bin/pg_rewind -D '/home/postgres/pg14/data' --source-server='host=db206 dbname=repmgr user=repmgr password=repmgr connect_timeout=2'"
ERROR: pg_rewind execution failed
DETAIL: pg_rewind: servers diverged at WAL location 102/580000A0 on timeline 8
pg_rewind: error: could not open file "/home/postgres/pg14/data/pg_wal/000000090000010200000058": 没有那个文件或目录
pg_rewind: fatal: could not find previous WAL record at 102/580000A0

 

 最终极的方法是删掉重建,这个时候删掉的是时间线9的,虽然重建好了,但是pg_ctl start无法启动。

[postgres@db223 data]$ rm -rf *
[postgres@db223 data]$ ll
总用量 0
[postgres@db223 data]$ repmgr -h db206  -U repmgr -d repmgr -f /home/postgres/repmgr/repmgr.conf standby clone
NOTICE: destination directory "/home/postgres/pg14/data" provided
INFO: connecting to source node
DETAIL: connection string is: host=db206 user=repmgr dbname=repmgr
DETAIL: current installation size is 12 GB
INFO: replication slot usage not requested;  no replication slot will be set up for this standby
NOTICE: checking for available walsenders on the source node (2 required)
NOTICE: checking replication connections can be made to the source server (2 required)
INFO: checking and correcting permissions on existing directory "/home/postgres/pg14/data"
NOTICE: starting backup (using pg_basebackup)...
HINT: this may take some time; consider using the -c/--fast-checkpoint option
INFO: executing:
  /home/postgres/pg14/bin/pg_basebackup -l "repmgr base backup"  -D /home/postgres/pg14/data -h db206 -p 5432 -U repmgr -X stream
NOTICE: standby clone (using pg_basebackup) complete
NOTICE: you can now start your PostgreSQL server
HINT: for example: pg_ctl -D /home/postgres/pg14/data start
HINT: after starting the server, you need to re-register this standby with "repmgr standby register --force" to update the existing node record
[postgres@db223 data]$ ^C
[postgres@db223 data]$ pg_ctl start
waiting for server to start....2023-08-17 19:48:33.265 CST [1532642] LOG:  redirecting log output to logging collector process
2023-08-17 19:48:33.265 CST [1532642] HINT:  Future log output will appear in directory "log".
 stopped waiting
pg_ctl: could not start server
 

查看log日志就是开头的,还是要读取时间线9,但是主库db203是没有时间线8的。又崩溃了。。。

2023-08-17 20:24:21.566 CST [1556001] LOG:  database system was interrupted; last known up at 2023-08-17 20:21:41 CST
2023-08-17 20:24:21.770 CST [1556001] LOG:  restored log file "00000009.history" from archive
cp: 无法获取'/home/postgres/pgarch/0000000A.history' 的文件状态(stat): 没有那个文件或目录
2023-08-17 20:24:21.771 CST [1556001] LOG:  entering standby mode
2023-08-17 20:24:21.772 CST [1556001] LOG:  restored log file "00000009.history" from archive
cp: 无法获取'/home/postgres/pgarch/000000090000010200000066' 的文件状态(stat): 没有那个文件或目录
2023-08-17 20:24:21.784 CST [1556001] LOG:  restored log file "000000080000010200000066" from archive
2023-08-17 20:24:21.851 CST [1556001] FATAL:  requested timeline 9 is not a child of this server's history
2023-08-17 20:24:21.851 CST [1556001] DETAIL:  Latest checkpoint is at 102/66000060 on timeline 8, but in the history of the requested timeline, the server forked off from that timeline at 102/580000A0.
2023-08-17 20:24:21.851 CST [1555991] LOG:  startup process (PID 1556001) exited with exit code 1
2023-08-17 20:24:21.851 CST [1555991] LOG:  aborting startup due to startup process failure
2023-08-17 20:24:21.851 CST [1555991] LOG:  database system is shut down

这个时候看了看db223的参数,是不是读取的归档路径不对,然后就看到基于时间线恢复recovery_target_timeline参数

archive_mode = on

archive_command = 'scp %p postgres@172.20.101.208:/home/postgres/pgarch/%f' 

archive_cleanup_command = 'pg_archivecleanup /home/postgres/pgarch %r'

restore_command = 'cp /home/postgres/pgarch/%f %p'   

recovery_target_timeline = 'latest'

修改了recovery_target_timeline = 'current'之后,再次启动db223就好了。

[postgres@db206 ~]$ repmgr -f ~/repmgr/repmgr.conf cluster show
 ID | Name  | Role    | Status    | Upstream | Location | Priority | Timeline | Connection string
----+-------+---------+-----------+----------+----------+----------+----------+------------------------------------------------------------------------
 1  | db223 | standby |   running | db206    | default  | 100      | 8        | host=db223 dbname=repmgr user=repmgr password=repmgr connect_timeout=2
 2  | db206 | primary | * running |          | default  | 100      | 8        | host=db206 dbname=repmgr user=repmgr password=repmgr connect_timeout=2

 

总结:

1、暂时还不知道为什么会出现双主,这个还需要复现一下。

2、考虑加一个见证节点(不知道能不能预防双主的出现),有待研究。

3、对recovery_target_timeline 知其然而不知所以然,抽空研究一下。

4、对recovery_target_timeline 在备机上修改完current之后,是否还需要再修改成laster(个人认为是不需要的)。

5大概看了一眼如下博客,解决的很顺利????

repmgr 集群双主问题处理

repmgr 集群双主问题处理_repmgr 把主库down 了_瀚高PG实验室的博客-CSDN博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/890925.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【从零开始学爬虫】采集中国国际招标网招标数据

l 采集网站 【场景描述】采集中国国际招标网招标数据。 【源网站介绍】中国国际招标网致力于为企业提供招标、采购、拟在建项目信息及网上招标采购等一系列商务服务。 【使用工具】前嗅ForeSpider数据采集系统 http://www.forenose.com/view/forespider/view/download.html 【…

LVS-DR模式下(RS检测)ldirectord工具实现部分节点掉点后将请求发往正常设备进行处理

基于前文的LVS-DR集群构建环境 一.下载ldirectord软件 二.将模板文件中的LVS-DR模式相关文件拷贝到/etc/ha.d主配置目录并按实际设备修改 三.配置两台RS匹配规则 四.停止RS1的http服务进行测试 RS1失去工作能力,RS2接替RS1 基于前文的LVS-DR集群构建环境 一.下…

ARM--day5(C语言点灯实验、总线、串口通信信息、串口通讯协议)

函数分装实现点灯 gpio.c: #include "gpio.h" //函数功能:GPIO引脚初始化操作 //参数1:GPIO组号 //参数2:引脚编号 //参数3:初始化内容 void hal_gpio_init(volatile gpio_t*gpiox,unsigned int pin,gpio_init_t* ini…

浏览器控制台调试代码和JavaScript控制台方法介绍

浏览器控制台调试代码和JavaScript控制台方法介绍 浏览器控制台调试代码 浏览器控制台(Console)是浏览器提供的一个开发工具,用于在浏览器中执行和调试 JavaScript 代码。它提供了一个交互式环境,可以输入 JavaScript 代码&#…

计算机竞赛 wifi指纹室内定位系统

简介 今天来介绍一下室内定位相关的原理以及实现方法; WIFI全称WirelessFidelity,在中文里又称作“行动热点”,是Wi-Fi联盟制造商的商标做为产品的品牌认证,是一个创建于IEEE 802.11标准的无线局域网技术。基于两套系统的密切相关&#xff…

UGUI组件Rect Transform

一. Rect Transform概述 画布上UI对象都附加一个Rect Transform组件,和一般对象附加的Transform对象相比,Rect Transform多了Width,Height,Anchor,Pivot属性。 二.位置属性 UI对象的坐标是其轴心到锚点之间的像素值,如下图所示。 三.Pivot(…

同时负责多个项目,团队成员还参与多个项目开发,如何有效管理?分享9个策略

如果你正在管理一个团队或项目,可能会需要同时在进行多个项目的管理。在这种情况下,追踪所有进行中的项目部分可能会迅速变得非常复杂。没有合适的管理过程,就难以确定哪些工作应该优先处理,也不容易确保团队有效管理工作量&#…

WPF显示初始界面--SplashScreen

WPF显示初始界面–SplashScreen 前言 WPF应用程序的运行速度快,但并不能在瞬间启动。当第一次启动应用程序时,会有一些延迟,因为公共语言运行时(CLR)首先需要初始化.NET环境,然后启动应用程序。 对于WPF中…

Spring基础梳理(一):一定要先全局掌握Spring

越活越完蛋了,看着看着现在又想梳理梳理Spring基础,搞点原始真解吧,不过技术人每个阶段看相同东西的理解都是不同的,只是现在浮躁的技术中又有多少人能够一本书啃两遍以上呢,我也一样,徜徉于业务之中&#…

【国护攻防场景下的沙箱技术对比】

目录 前言 沙箱技术分析 总结 前言 真高兴呀,又是受到红队大佬青睐的一天,今天下午很荣幸的收到了来自红队大佬的恶意投喂,把我们各位在座100年工作经验的蓝队师傅们吓得赶忙拔掉自己的电脑电源,断掉自己的网线,…

基于Helm管理Kubernetes应用

目录 基于kubeadm部署K8S集群 一、环境准备 1.1、主机初始化配置 1.2、部署docker环境 二、部署kubernetes集群 2.1、组件介绍 2.2、配置阿里云yum源 2.3、安装kubelet kubeadm kubectl 2.4、配置init-config.yaml 2.5、安装master节点 2.6、安装node节点 2.7、安装…

Linux驱动开发(Day4)

字符设备驱动分步注册:

OpenCV实战(OCR识别和高级基础)

目录 图像特征harris角点检测基本原理实现 Scale Invariant Feature Transform(SIFT)图像尺度空间多分辨率金字塔高斯差分金字塔(DOG)DoG空间极值检测关键点的精确定位消除边界响应特征点的主方向生成特征描述 特征匹配Brute-Forc…

Linux命令200例:crontab详解及应用场景(常用)

🏆作者简介,黑夜开发者,全栈领域新星创作者✌。CSDN专家博主,阿里云社区专家博主,2023年6月csdn上海赛道top4。 🏆数年电商行业从业经验,历任核心研发工程师,项目技术负责人。 &…

视频智能分析/视频云存储/集中存储EasyCVR平台AI分析告警列表定制

安防监控视频集中存储/云存储EasyCVR视频汇聚平台基于云边端一体化架构,可支持多协议、多类型设备接入,视频监控综合管理平台具有强大的数据接入、处理及分发能力,能在复杂的网络环境中,将分散的各类视频资源进行统一汇聚、整合、…

Effective C++学习笔记(7)

目录 条款41:了解隐式接口和编译多态条款42:了解typename的双重意义条款43:学习处理模板化基类内的名称条款44:将与参数无关的代码抽离templates条款45:运用成员函数模板接受所有兼容类型条款46:需要类型转…

100. 相同的树

100. 相同的树 题目-简单难度示例1. dfs2. bfs 题目-简单难度 给你两棵二叉树的根节点 p 和 q ,编写一个函数来检验这两棵树是否相同。 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。 示例 示例 1: 输入…

Stable Diffusion XL(SDXL)原理详解

技术报告:SDXL: Improving Latent Diffusion Models for High-Resolution Image Synthesis 官方代码:Stability-AI-generative-models 模型权重:HuggingFace-Stability AI 非官方代码:Linaqruf/kohya-trainer diffuser库&#xf…

Redis实战:Redis的安装及简单使用

本片将介绍 Redis 的安装及简单使用 文章目录 1、Redis安装1.1、Windows下Redis的安装1.2、Linux下Redis的安装1.3、Mac下Redis的安装(使用Homebrew) 2、Redis使用2.1、启动服务端客户端2.2、Redis简单命令 3、Redis命令大全 1、Redis安装 1.1、Windows…

Redis持久化——AOF

介绍 Redis是运行在内存中的数据库,当我们关闭了Redis服务器后,内存中的数据会丢失吗? 答案是不会的,因为Redis有持久化功能,能够将内存中的数据保存到磁盘中的文件,以此来实现数据的永久保存。 在Redis中…