已关闭
[Bug]: 开启hot_standby_feedback,物理复制槽会带上xmin字段,在做主备切换后,备机存在不活跃的复制槽带有xmin,csnlog无法清理【M】 #8336
zhangxubo创建于  7月21日关闭于  9月8日
zhangxubo
zhangxubo成员
7月21日 创建

测试类型

存储功能

测试版本

7.0.0LTS

问题描述

开启hot_standby_feedback,备机的物理复制槽会带上xmin,在做主备切换后,备机存在不活跃的复制槽带有xmin,csnlog无法清理

操作系统和硬件信息

all

测试环境

企业版主备

被测功能

预置条件

操作步骤

  1. 开启hot_standby_feedback,做一次主备切换。
    备机上(旧主)存在不活跃的复制槽带有xmin
    image.png

  2. 持续运行,备机上csnlog无法清理
    image.png

预期输出

备机残留的物理复制槽xmin不阻塞csnlog回收

实际输出

备机残留的物理复制槽xmin阻塞csnlog回收

日志信息

见截图

提单组织

一线客户

测试代码

likedislike
zhangxubozhangxubo成员
7月21日 添加了label:bug
opengauss_bot
opengauss_bot成员
7月21日 评论:

This issue requires an assignee. Since you haven't specified one, we've assigned TestManager as the default assignee for this issue.

likedislike
opengauss_botopengauss_bot成员
7月21日 将 TestManager 设为负责人
opengauss_botopengauss_bot成员
7月21日 添加了label:sig/StorageEngine,sig/AI,sig/CM,sig/CloudNative,sig/SecurityTechnology,sig/SQLEngine
opengauss_bot
opengauss_bot成员
7月21日 评论:

Welcome To openGauss Community

Hey @zhangxubo , thanks for your contribution to the community.

Bot Usage Manual

I'm the Bot here serving you. You can find the instructions on how to interact with me at Here . That means you can comment below every pull request or issue to trigger Bot Commands.

Contact Guide

If you have any questions, please contact the SIG: StorageEngine, AI, CM, CloudNative, SecurityTechnology, SQLEngine ,
and any of the maintainers: @CarrotGo, @chendong76, @chenxiaobin19, @congzhou2603, @dodders, @hwworkholic, @jemappellehc, @muyulinzhong, @quemingjian, @shenzheng4, @shirley_zhengx, @superlchf, @totaj, @wlff234, @wofanzheng, @ywzq1161327784 ,
and any of the committers: @Igali, @bihua111, @cailei19, @h_ray, @levy53071, @libiao2024, @lihaixiao, @mrzack, @wangfeihuo, @wuyuechuan, @xiong_xjun, @zhangfengzhi123, @zhangxubo, @zhangzq131, @zjh_hw .

likedislike
zhangxubozhangxubo成员
7月21日 关联了看板:openGauss 7.0.0-LTS
zhangxubozhangxubo成员
7月21日 修改标题为 “[Bug]: 开启hot_standby_feedback,物理复制槽会带上xmin字段,在做主备切换后,备机存在不活跃的复制槽带有xmin,csnlog无法清理【M】”,原标题为“[Bug]: 开启hot_standby_feedback,备机的物理复制槽会带上xmin,在做主备切换后,备机存在不活跃的复制槽带有xmin,csnlog无法清理【M】”
zhangxubozhangxubo成员
7月22日 issue优先级由 无优先级 改变为 主要
muyulinzhongmuyulinzhong成员
8月7日 将 shirley_zhengx 设为负责人
muyulinzhongmuyulinzhong成员
8月7日 移除了负责人 TestManager
shirley_zhengx
shirley_zhengx成员
8月21日 评论:

原因分析:

image.png

image.png

hot_standby_feedback 把备机 GetOldestXmin 写进主库物理槽 xmin,用来挡住主库清理。
主备切换时降主不清这个 xmin,槽留在旧主上变成 inactive,但仍算进 ReplicationSlotsComputeRequiredXmin。
结果:旧主(现备)本地 oldest / feedback 被钉死;新主槽虽可被更高 feedback 往前推(只进不退),但 CSN truncate 的 oldestXact 仍可能停在历史残留水位,两边看起来都不推进。
开关 feedback 后,切换未清理物理槽上的 HS xmin,inactive 残留继续拖 oldestxmin / truncate。

likedislike
shirley_zhengx
shirley_zhengx成员
8月22日 评论:

修改后测试步骤:
1.安装主备双节点
gs_guc set -D $PGDATA -c "hot_standby_feedback=on"
gs_ctl reload -D $PGDATA
gs_guc set -D $PGDATA -c "checkpoint_timeout=3min"
gs_ctl reload -D $PGDATA
2.在备机执行gs_ctl switchover -D /data/gauss/data/dn1
3.在备机日志查看,日志第一行是切换完之后,备机的日志看起来并没推进,那是因为全局recentglobalxmin是当时最小值(切换的时候不会被抬高,以当时切换那一瞬间的业务最小值决定),nextid是在切换的时候强制被抬高了一点,所以日志看起来没有推进,需要在主机执行业务后,备机的全局recentglobalxmin才会往前推进,checkpoint时 会通过全局recentglobalxmin 和 所有业务最小xmin 来取最小值去truncate csnlog,不会再把 不活跃槽里面的xmin聚合进来。
image.png
4.在主机执行往前推进的业务,create table t1(id int); insert into t1 values(1); insert into t1 values(2); 或者比如 2次 select txid_current(); 等到checkpoint下次到的时候,备机pg_log就可以看到备机cnslog truncate推进,如上图日志的第二行所示;

likedislike
shirley_zhengxshirley_zhengx成员
8月22日 关联了pull request:fix replication slot too old
shirley_zhengx
shirley_zhengx成员
8月26日 评论:

转测包自验证
旧主(备机) 备机推进后,主机才会推进
image.png
新主
image.png

切换后,一定是旧主 先推进,新主才推进,不是根据checkpoint的次数决定

likedislike
shirley_zhengxshirley_zhengx成员
8月26日 issue状态由 待办的 改变为 待回归
shirley_zhengxshirley_zhengx成员
8月26日 将 zhangxubo 设为负责人
shirley_zhengxshirley_zhengx成员
8月26日 移除了负责人 zhangxubo
jiangyan
jiangyan成员
9月8日 评论:

回归日期:2026年9月8日
回归结论:通过
回归版本:openGauss7.0.0LTS B021
旧主
image.png
新主
image.png

likedislike
jiangyanjiangyan成员
9月8日 issue状态由 待回归 改变为 已验收
jiangyanjiangyan成员
9月8日 关闭了 issue