pg_createsubscriber 是一个核心实用工具,用于将物理备用服务器转换为新的逻辑备用服务器。
pg_createsubscriber 在 PostgreSQL 17 中被添加。
变更历史
- PostgreSQL 18
- PostgreSQL 17
- 添加 (提交 d44032d0)
示例
这个 pg_createsubscriber 的基本用法示例假定有一个由主服务器和两个物理备用服务器组成的三个节点集群,并且正在使用复制槽。
postgres=# SELECT slot_name, slot_type, restart_lsn FROM pg_replication_slots ORDER BY 1; slot_name | slot_type | restart_lsn -----------+-----------+------------- node2 | physical | 0/4000060 node3 | physical | 0/4000060 (2 rows)
要将 node3 转换为逻辑备用服务器,将执行以下步骤:
- 停止
node3node3$ pg_ctl -D /var/lib/pgsql/data/ stop
- 执行
pg_createsubscribernode3$ pg_createsubscriber \ -D /var/lib/pgsql/data/ \ --publisher-server 'host=node1 dbname=postgres user=postgres port=5432' \ -d postgres
- 启动
node3node3$ pg_ctl -D /var/lib/pgsql/data/ start
此时,node3 将作为逻辑备用服务器连接到 node1。
postgres=# SELECT slot_name, slot_type, restart_lsn FROM pg_replication_slots ORDER BY 1;
slot_name | slot_type | restart_lsn
--------------------------------+-----------+-------------
node2 | physical | 0/40382F0
pg_createsubscriber_5_80f3c6f3 | logical | 0/40382B8
(2 rows)
参考资料
- PostgreSQL 文档: pg_createsubscriber
有用链接
- PostgreSQL 17:使用 pg_createsubscriber 将物理副本转换为逻辑副本 - Daniel Westermann / dbi services 于 2024 年 3 月撰写的博客文章
