PostgreSQL 18 preview - pg_createsubscriber增加--all选项, 方便全实例逻辑订阅
PostgreSQL 18 preview - pg_createsubscriber增加--all选项, 方便全实例逻辑订阅
pg_createsubscriber增加--all选项, 方便全实例逻辑订阅
特别是在用standby节点进行大版本升级后, 同步增量数据库. 缩短停机时间.
1、promote standby 2、pg_upgrade 升级大版本 3、使用 pg_createsubscriber --all 从 primary 节点 同步全实例增量 4、同步完成后删除订阅, 切换应用到新节点.
https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=fb2ea12f42b9453853be043b8ed107e136e1ccb7
pg_createsubscriber: Add '--all' option. master github/master
author Amit Kapila <[email protected]>
Fri, 28 Mar 2025 06:56:39 +0000 (12:26 +0530)
committer Amit Kapila <[email protected]>
Fri, 28 Mar 2025 06:56:39 +0000 (12:26 +0530)
commit fb2ea12f42b9453853be043b8ed107e136e1ccb7
tree 883577e3fdf4417f80006447288cfe05a818bb94 tree
parent 890fc826c91f153ae8c084d3a008f91798495b13 commit | diff
pg_createsubscriber: Add '--all' option. The '--all' option indicates that the tool queries the source server
(publisher) for all databases and creates subscriptions on the target
server (subscriber) for databases with matching names. Without this user
needs to explicitly specify all databases by using -d option for each
database.
This simplifies converting a physical standby to a logical subscriber,
particularly during upgrades.
The options '--database', '--publication', '--subscription', and
'--replication-slot' cannot be used when '--all' is specified.
Author: Shubham Khanna <[email protected]>
Reviewed-by: vignesh C <[email protected]>
Reviewed-by: Ashutosh Bapat <[email protected]>
Reviewed-by: Euler Taveira <[email protected]>
Reviewed-by: Hayato Kuroda <[email protected]>
Reviewed-by: Amit Kapila <[email protected]>
Reviewed-by: Peter Smith <[email protected]>
Reviewed-by: Shlok Kyal <[email protected]>
Discussion: https://postgr.es/m/CAHv8RjKhA=_h5vAbozzJ1Opnv=KXYQHQ-fJyaMfqfRqPpnC2bA@mail.gmail.com
AI 解读
这个补丁为 pg_createsubscriber 工具新增了 --all 选项,以下是详细解读:
核心功能
自动化多数据库订阅
原工具要求用户用 -d为每个数据库单独指定订阅新选项 --all自动从发布者服务器获取 所有数据库列表,并在订阅者上为 同名数据库 创建订阅
典型应用场景
特别简化了从物理备库到逻辑订阅者的转换(如大版本升级时)
使用限制
互斥选项
以下选项与--all不能同时使用:--database # 原单数据库指定模式
--publication # 发布名称手动指定
--subscription # 订阅名称手动指定
--replication-slot # 复制槽手动指定隐式行为
自动匹配发布者与订阅者的 数据库名称 所有订阅使用 相同的发布/订阅命名模式(如 ${dbname}_pub)
设计动机
减少人工操作
标准化流程
在物理备库转换场景中,通常需要同步所有数据库,手动指定容易出错
实现细节
工作流程
错误处理
跳过订阅者上不存在的数据库 保留原有工具的其他校验逻辑(如权限检查)
社区协作
审阅过程
补丁经过 7 位核心开发者的审阅,涵盖逻辑复制、升级工具等领域的专家:包括逻辑复制模块维护者(Amit Kapila) 富士通升级工具开发者(Hayato Kuroda) 逻辑复制专家(Euler Taveira) 讨论重点
邮件线程显示主要关注:选项冲突的合理性 是否需要对不存在的数据库给出警告 未来扩展性(如支持过滤规则)
使用示例
# 旧方式(需手动指定每个库)
pg_createsubscriber -h publisher -d db1 -d db2 -d db3...
# 新方式(一键同步所有库)
pg_createsubscriber -h publisher --all
这个改进显著提升了多数据库环境下的操作效率,尤其在大型系统升级场景中。