北京oracle培训_oracle培训哪家好_CUUG官方论坛_CUUG培训怎么样_CUUG官网

 找回密码
 立即注册
查看: 191|回复: 0

PolarDB for PostgreSQL 备份并恢复一个 Standby 节点

[复制链接]
发表于 2023-8-28 14:04:18 | 显示全部楼层 |阅读模式
PolarDB for PostgreSQL 备份并恢复一个 Standby 节点
基础备份也可以用于搭建一个新的 Standby 节点。如下图所示,Standby 节点与 Primary / Replica 节点各自使用独立的共享存储,与 Primary 节点使用物理复制保持同步。Standby 节点可用于作为主共享存储的灾备。
PFS 文件系统格式化和挂载
假设此时用于部署 Standby 计算节点的机器已经准备好用于后备的共享存储 nvme2n1:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
nvme0n1 259:1 0 40G 0 disk
└─nvme0n1p1 259:2 0 40G 0 part /etc/hosts
nvme2n1 259:3 0 70G 0 disk
nvme1n1 259:0 0 60G 0 disk
将这个共享存储格式化为 PFS 格式,并启动 PFSD 守护进程挂载到 PFS 文件系统:
sudo pfs -C disk mkfs nvme2n1
sudo /usr/local/polarstore/pfsd/bin/start_pfsd.sh -p nvme2n1 -w 2
备份数据到本地存储和共享存储
在用于部署 Standby 节点的机器上执行备份,以 ~/standby 作为本地数据目录,以 /nvme2n1/shared_data 作为共享存储目录:
polar_basebackup \
--host=[Primary节点所在IP] \
--port=[Primary节点所在端口号] \
-D /home/postgres/standby \
--polardata=/nvme2n1/shared_data/ \
--polar_storage_cluster_name=disk \
--polar_disk_name=nvme2n1 \
--polar_host_id=3 \
-X stream --progress --write-recovery-conf -v
将会看到如下输出。其中,除了 polar_basebackup 的输出以外,还有 PFS 的输出日志:
[PFSD_SDK INF Jan 11 10:11:27.247112][99]pfs_mount_prepare 103: begin prepare mount cluster(disk), PBD(nvme2n1), hostid(3),flags(0x13)
[PFSD_SDK INF Jan 11 10:11:27.247161][99]pfs_mount_prepare 165: pfs_mount_prepare success for nvme2n1 hostid 3
[PFSD_SDK INF Jan 11 10:11:27.293900][99]chnl_connection_poll_shm 1238: ack data update s_mount_epoch 1
[PFSD_SDK INF Jan 11 10:11:27.293912][99]chnl_connection_poll_shm 1266: connect and got ack data from svr, err = 0, mntid 0
[PFSD_SDK INF Jan 11 10:11:27.293979][99]pfsd_sdk_init 191: pfsd_chnl_connect success
[PFSD_SDK INF Jan 11 10:11:27.293987][99]pfs_mount_post 208: pfs_mount_post err : 0
[PFSD_SDK ERR Jan 11 10:11:27.297257][99]pfsd_opendir 1437: opendir /nvme2n1/shared_data/ error: No such file or directory
[PFSD_SDK INF Jan 11 10:11:27.297396][99]pfsd_mkdir 1320: mkdir /nvme2n1/shared_data
polar_basebackup: initiating base backup, waiting for checkpoint to complete
WARNING: a labelfile "/nvme1n1/shared_data//polar_non_exclusive_backup_label" is already on disk
HINT: POLAR: we overwrite it
polar_basebackup: checkpoint completed
polar_basebackup: write-ahead log start point: 0/16C91F8 on timeline 1
polar_basebackup: starting background WAL receiver
polar_basebackup: created temporary replication slot "pg_basebackup_373"
...
[PFSD_SDK INF Jan 11 10:11:32.992005][99]pfsd_open 539: open /nvme2n1/shared_data/polar_non_exclusive_backup_label with inode 6325, fd 0
[PFSD_SDK INF Jan 11 10:11:32.993074][99]pfsd_open 539: open /nvme2n1/shared_data/global/pg_control with inode 8373, fd 0
851396/851396 kB (100%), 2/2 tablespaces
polar_basebackup: write-ahead log end point: 0/16C9300
polar_basebackup: waiting for background process to finish streaming ...
polar_basebackup: base backup completed
[PFSD_SDK INF Jan 11 10:11:52.378220][99]pfsd_umount_force 247: pbdname nvme2n1
[PFSD_SDK INF Jan 11 10:11:52.378229][99]pfs_umount_prepare 269: pfs_umount_prepare. pbdname:nvme2n1
[PFSD_SDK INF Jan 11 10:11:52.404010][99]chnl_connection_release_shm 1164: client umount return : deleted /var/run/pfsd//nvme2n1/99.pid
[PFSD_SDK INF Jan 11 10:11:52.404171][99]pfs_umount_post 281: pfs_umount_post. pbdname:nvme2n1
[PFSD_SDK INF Jan 11 10:11:52.404174][99]pfsd_umount_force 261: umount success for nvme2n1
上述命令会在当前机器的本地存储上备份 Primary 节点的本地数据目录,在参数指定的共享存储目录上备份共享数据目录。
重新配置 Standby 节点
重新编辑 Standby 节点的配置文件 ~/standby/postgresql.conf:
-polar_hostid=1
+polar_hostid=3
-polar_disk_name='nvme1n1'
-polar_datadir='/nvme1n1/shared_data/'
+polar_disk_name='nvme2n1'
+polar_datadir='/nvme2n1/shared_data/'
-synchronous_standby_names='replica1'
在 Standby 节点的复制配置文件 ~/standby/recovery.conf 中添加:
+recovery_target_timeline = 'latest'
+primary_slot_name = 'standby1'
Standby 节点启动
在 Primary 节点上创建用于与 Standby 进行物理复制的复制槽:
$ psql \
--host=[Primary节点所在IP] --port=5432 \
-d postgres \
-c "SELECT * FROM pg_create_physical_replication_slot('standby1');"
slot_name | lsn
-----------+-----
standby1 |
(1 row)
启动 Standby 节点:
pg_ctl -D $HOME/standby start
Standby 节点验证
在 Primary 节点上创建表并插入数据,在 Standby 节点上可以查询到数据:
$ psql -q \
-h [Primary节点所在IP] \
-p 5432 \
-d postgres \
-c "CREATE TABLE t (t1 INT PRIMARY KEY, t2 INT); INSERT INTO t VALUES (1, 1),(2, 3),(3, 3);"
$ psql -q \
-h [Standby节点所在IP] \
-p 5432 \
-d postgres \
-c "SELECT * FROM t;"
t1 | t2
----+----
1 | 1
2 | 3
3 | 3
(3 rows)

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|CUUG认证培训 ( 京ICP备11008061号 )

GMT+8, 2024-11-28 09:41 , Processed in 0.020631 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表