1.Base基础/3.Icon图标/操作/search备份
1.Base基础/3.Icon图标/操作/search备份
EN
文档
关于AntDB
部署与升级
快速入门
使用教程
运维
调优
工具和插件
数据安全
参考
  • 文档首页 /
  • 高级服务 /
  • Ultra_Sync /
  • Ultra_Sync的维护

Ultra_Sync的维护

更新时间:2024-07-01 14:39:45

版本要求

要求:AntDB6.3.15, AntDB adbhamgr 1.0.2 或以上版本

为集群新增 Ultra Sync 节点

为集群新增 Ultra Sync 节点 请参考本文【双中心引入 Ultra Sync 】章节。

启动 Ultra Sync

sudo systemctl start adbhamgr

停止 Ultra Sync

Ultra Sync 节点的停止,需要停掉对应的 adbhamgr。

sudo systemctl stop adbhamgr

重启 Ultra Sync

使用 adbhamgr 命令可以重启 Ultra Sync 节点:

# 用户交互命令,输入y表示确定重启,输入N表示撤回重启操作。
# restart 后面跟两个参数,第一个是集群名称,第二个是节点名称
[antdb@phy-10-1-206-130 ~]$ adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml restart antdb-cluster adbhamgr-3
+ Cluster: antdb-cluster (7224418384555371402) ------------+-----+-----------+
| Member     | Host               | Role         | State   |  TL | Lag in MB |
+------------+--------------------+--------------+---------+-----+-----------+
| adbhamgr-1 | 10.1.206.128:55551 | Leader       | running | 124 |           |
| adbhamgr-2 | 10.1.206.129:55551 | Sync Standby | running | 124 |         0 |
| adbhamgr-3 | 10.1.206.130:55551 | Ultra Sync   | running | 124 |         0 |
+------------+--------------------+--------------+---------+-----+-----------+
When should the restart take place (e.g. 2023-05-19T12:04)  [now]:
Are you sure you want to restart members adbhamgr-3? [y/N]: y
Restart if the PostgreSQL version is less than provided (e.g. 9.5.2)  []:
Success: restart on member adbhamgr-3


# 无需用户交互,强制重启,restart后面跟三个参数,第一个是集群名称,第二个是节点名称,第三个--force强制重启
[antdb@phy-10-1-206-130 ~]$ adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml restart antdb-cluster adbhamgr-3 --force
+ Cluster: antdb-cluster (7224418384555371402) ------------+-----+-----------+
| Member     | Host               | Role         | State   |  TL | Lag in MB |
+------------+--------------------+--------------+---------+-----+-----------+
| adbhamgr-1 | 10.1.206.128:55551 | Leader       | running | 124 |           |
| adbhamgr-2 | 10.1.206.129:55551 | Sync Standby | running | 124 |         0 |
| adbhamgr-3 | 10.1.206.130:55551 | Ultra Sync   | running | 124 |         0 |
+------------+--------------------+--------------+---------+-----+-----------+
Success: restart on member adbhamgr-3

重新初始化 Ultra Sync

使用 adbhamgr 命令可以重新初始化 Ultra Sync 节点:

# 用户交互命令,输入y表示确定初始化,输入N表示撤回初始化操作。
# reinit 后面跟两个参数,第一个是集群名称,第二个是节点名称
[antdb@phy-10-1-206-130 ~]$ adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml reinit antdb-cluster adbhamgr-3
+ Cluster: antdb-cluster (7224418384555371402) ------------+-----+-----------+
| Member     | Host               | Role         | State   |  TL | Lag in MB |
+------------+--------------------+--------------+---------+-----+-----------+
| adbhamgr-1 | 10.1.206.128:55551 | Leader       | running | 124 |           |
| adbhamgr-2 | 10.1.206.129:55551 | Sync Standby | running | 124 |         0 |
| adbhamgr-3 | 10.1.206.130:55551 | Ultra Sync   | running | 124 |         0 |
+------------+--------------------+--------------+---------+-----+-----------+
Are you sure you want to reinitialize members adbhamgr-3? [y/N]: y
Success: reinitialize for member adbhamgr-3

# 无需用户交互,强制重新初始化,reinit后面跟三个参数,第一个是集群名称,第二个是节点名称,第三个--force强制重启
[antdb@phy-10-1-206-130 ~]$ adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml reinit antdb-cluster adbhamgr-3 --force
Success: reinitialize for member adbhamgr-3

参数修改

节点参数修改用 adbhamgr 的 edit-config 选项:

# 修改参数:
adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml edit-config      

# 改完后有些参数需要restart 集群才能生效(antdb-cluster为集群名称)
adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml restart antdb-cluster   

把 Ultra Sync 踢出集群

将 Ultra Sync 节点移除集群,需要以下几步:

1. 停止Ultra Sync 节点的adbhamgr
sudo systemctl stop adbhamgr

2. 登陆主节点,删除Ultra Sync 节点的复制槽
antdb=# SELECT * from pg_replication_slots;      #查询Ultra Sync 节点的复制槽名称,这里为adbhamgr-3
 slot_name | plugin | slot_type | datoid | database | temporary | active | active_pid | xmin | catalog_xmin | restart_lsn  | confirmed_flush_lsn | wal_status | safe_wal_size
-----------+--------+-----------+--------+----------+-----------+--------+------------+------+--------------+--------------+---------------------+------------+---------------
 adbhamgr-3  |        | physical  |        |          | f         | f      |            |      |              | 20A/C00001D0 |                     | reserved   |
 adbhamgr-2  |        | physical  |        |          | f         | t      |     564898 |      |              | 20A/C00001D0 |                     | reserved   |
(2 rows)

antdb=# SELECT pg_drop_replication_slot('adbhamgr-3');   # 删除Ultra Sync 节点的复制槽
 pg_drop_replication_slot
--------------------------

(1 row)

3. 修改synchronous_node_count参数
# Ultra Sync 节点移除集群后,由于修改synchronous_node_count参数值为2,就会有两个同步备节点,
# 要想恢复成一主一备,可以修改修改synchronous_node_count参数为1,改完后重启集群即可
adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml edit-config

#将下面synchronous_node_count参数的值改为1
loop_wait: 5
master_start_timeout: 300
maximum_lag_on_failover: 1048576
postgresql:
  parameters:
    archive_command: ls
    archive_mode: true
    hot_standby: 'on'
    listen_addresses: '*'
    log_destination: csvlog
    log_directory: pg_log
    logging_collector: true
    max_connections: 20000
    max_prepared_transactions: 10
    max_wal_senders: 50
    max_worker_processes: 16
    port: 55551
    wal_keep_size: 1024
    wal_level: logical
    wal_segment_size: 1024
  use_pg_rewind: true
retry_timeout: 5
synchronous_mode: true
synchronous_mode_strict: true
synchronous_node_count: 1               #改为1
ttl: 15

重启集群:
adbhamgrctl -c /etc/adbhamgr/adbhamgr_antdbcluster.yaml restart antdb-cluster --force

为 Ultra Sync 配置级联备机

为 Ultra Sync 配置级联备机需要注意的是 adb_basebackup 的复制源必须是主库,详细步骤如下所示:

初始化级联在 Ultra Sync 上的备库:

1.通过adb_basebackup同步数据,注意,这里adb_basebackup的复制源必须是主库
	adb_basebackup -D DATA_DIR -Fp -R -Xs -v -P -h 主库ip -p 主库端口 -U antdb

2.修改postgresql.auto.conf:
  primary_conninfo和primary_slot_name这两个参数分别需要调整为Ultra Sync 节点的ip和复制槽名

3.启动备库
	adb_ctl -D DATA_DIR start

确认流复制是否正常:

1.在主库确认,Ultra Sync 节点应该处于同步复制模式
	SELECT * from pg_stat_replication;

2.在Ultra Sync 节点确认,级联的备库应该处于异步复制模式
	SELECT * from pg_stat_replication;

Ultra Sync 相关的常用操作

流复制相关

# 查看流复制信息:
SELECT * from pg_stat_replication;

# 查看流复制同步到磁盘的最后一个预写式日志位置:
SELECT pg_last_wal_receive_lsn();

复制槽相关

# 查看集群复制槽:
 SELECT * FROM pg_replication_slots;

# 创建复制槽:
# 手动搭建不含adbdcs+adbhamgr环境的Ultra Sync 节点的时候,需要手动创建复制槽,命令如下:
SELECT pg_create_physical_replication_slot('slot22', true);  #slot22为复制槽名,自定义

# 删除复制槽:
SELECT pg_drop_replication_slot('slot20');    #slot20为复制槽名
问题反馈