pg_createsubscriber

一个将物理副本转换为逻辑副本的实用工具

pg_createsubscriber 是一个核心实用工具,用于将物理备用服务器转换为新的逻辑备用服务器。

pg_createsubscriberPostgreSQL 17 中被添加。

变更历史

示例

这个 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 转换为逻辑备用服务器,将执行以下步骤:

  1. 停止 node3
    node3$ pg_ctl -D /var/lib/pgsql/data/ stop
  2. 执行 pg_createsubscriber
    node3$ pg_createsubscriber \
      -D /var/lib/pgsql/data/ \
      --publisher-server 'host=node1 dbname=postgres user=postgres port=5432' \
      -d postgres
  3. 启动 node3
    node3$ 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)

分类

核心实用工具, 逻辑复制, 管理/运维

另请参阅

pg_basebackup

反馈

提交有关“pg_createsubscriber”的任何评论、建议或更正,请在此处提交