进阶课 5 PolarDB 在线备份
PolarDB 进阶课程5 在线备份
穷鬼玩PolarDB RAC一写多读集群系列已经写了几篇:
《在Docker容器中用loop设备模拟共享存储》 《如何搭建PolarDB容灾(standby)节点》 《共享存储在线扩容》 《计算节点 Switchover》
本篇文章介绍一下如何进行在线备份? 实验环境依赖 《在Docker容器中用loop设备模拟共享存储》 , 如果没有环境, 请自行参考以上文章搭建环境.
还需要参考如下文档:
https://apsaradb.github.io/PolarDB-for-PostgreSQL/zh/operation/backup-and-restore.html
DEMO
b站视频链接
Youtube视频链接
如果你要把共享存储的数据备份到另一个共享存储中, 可以参看这篇文章: 《如何搭建PolarDB容灾(standby)节点》
本文介绍的是把共享存储的数据备份到本地盘中.
本文测试环境继续使用 《如何搭建PolarDB容灾(standby)节点》 容器.
1、安装polardb 二进制
参考《在Docker容器中用loop设备模拟共享存储》 步骤 9、将编译好的二进制拷贝到pb1, pb2的HOME目录, 便于调用
2、配置primary, 允许备份机的IP可以通过流复制协议访问primary.
假设备份机的IP在 172.17.0.0/16 网段内.
# 确认 ~/primary/pg_hba.conf 配置文件已包含备份机的IP
host replication postgres 172.17.0.0/16 trust
# 如果修改了pg_hba.conf配置, 需要reload
pg_ctl reload -D ~/primary
3、创建备份空目录, 修改ownership
sudo mkdir /data/backup
sudo chown postgres:postgres /data/backup
sudo chmod 700 /data/backup
4、在备份机执行, 将实例 Primary 节点的本地数据和共享数据备份到用于部署 Replica 节点的本地存储路径 /data/backup 下:
请跳到第6步, 官网文档的命令不适合共享存储.
模板如下 ( 注意: 这个模板不适合共享存储模式的PolarDB, 会漏备共享目录的内容. 后面恢复时有报错. )
polar_basebackup \
--host=[Primary节点所在IP] \
--port=[Primary节点所在端口号] \
-D /data/backup \
-X stream --progress --write-recovery-conf -v
本文使用如下命令进行备份: ( 注意: 这个例子不适合共享存储模式的PolarDB, 会漏备共享目录的内容. 后面恢复时有报错. )
polar_basebackup \
--host=172.17.0.2 \
--port=5432 \
-D /data/backup \
-X stream --progress --write-recovery-conf -v # 日志如下:
polar_basebackup: initiating base backup, waiting for checkpoint to complete
polar_basebackup: checkpoint completed
polar_basebackup: write-ahead log start point: 0/48572608 on timeline 1
polar_basebackup: starting background WAL receiver
polar_basebackup: created temporary replication slot "pg_basebackup_167"
191377/191377 kB (100%), 2/2 tablespaces
polar_basebackup: write-ahead log end point: 0/485726E0
polar_basebackup: waiting for background process to finish streaming ...
polar_basebackup: syncing data to disk ...
polar_basebackup: renaming backup_manifest.tmp to backup_manifest
polar_basebackup: base backup completed
备份完成后, 可以看到backup目录内的内容如下:
$ cd /data/backup/
postgres@9bab5d9c0b25:/data/backup$ ll
total 256
drwx------ 31 postgres postgres 992 Dec 18 16:12 ./
drwxr-xr-x 8 postgres postgres 256 Dec 18 15:49 ../
-rw------- 1 postgres postgres 227 Dec 18 16:03 backup_label
-rw------- 1 postgres postgres 190107 Dec 18 16:03 backup_manifest
drwx------ 6 postgres postgres 192 Dec 18 16:03 base/
-rw------- 1 postgres postgres 163 Dec 18 16:03 current_logfiles
drwx------ 2 postgres postgres 64 Dec 18 16:03 global/
drwx------ 2 postgres postgres 64 Dec 18 16:03 pg_commit_ts/
drwx------ 2 postgres postgres 64 Dec 18 16:03 pg_dynshmem/
-rw------- 1 postgres postgres 4870 Dec 18 16:03 pg_hba.conf
-rw------- 1 postgres postgres 1636 Dec 18 16:03 pg_ident.conf
drwx------ 37 postgres postgres 1184 Dec 18 16:03 pg_log/
drwx------ 5 postgres postgres 160 Dec 18 16:03 pg_logical/
drwx------ 4 postgres postgres 128 Dec 18 16:03 pg_multixact/
drwx------ 2 postgres postgres 64 Dec 18 16:03 pg_notify/
drwx------ 2 postgres postgres 64 Dec 18 16:03 pg_replslot/
drwx------ 2 postgres postgres 64 Dec 18 16:03 pg_serial/
drwx------ 2 postgres postgres 64 Dec 18 16:03 pg_snapshots/
drwx------ 2 postgres postgres 64 Dec 18 16:03 pg_stat/
drwx------ 2 postgres postgres 64 Dec 18 16:03 pg_stat_tmp/
drwx------ 2 postgres postgres 64 Dec 18 16:03 pg_subtrans/
drwx------ 2 postgres postgres 64 Dec 18 16:03 pg_tblspc/
-rw------- 1 postgres postgres 3 Dec 18 16:03 PG_VERSION
drwx------ 3 postgres postgres 96 Dec 18 16:03 pg_xact/
drwx------ 2 postgres postgres 64 Dec 18 16:03 polar_cache_trash/
-rw------- 1 postgres postgres 205 Dec 18 16:03 polar_settings.conf
drwx------ 15 postgres postgres 480 Dec 18 16:03 polar_shared_data/
-rw------- 1 postgres postgres 9 Dec 18 16:03 polar_shmem_stat_file
-rw------- 1 postgres postgres 462 Dec 18 16:03 postgresql.auto.conf
-rw-------+ 1 postgres postgres 29944 Dec 18 16:12 postgresql.conf
-rw------- 1 postgres postgres 0 Dec 18 16:03 standby.signal
附polar_basebackup命令帮助
$ polar_basebackup --help
polar_basebackup takes a base backup of a running PostgreSQL server. Usage:
polar_basebackup [OPTION]...
Options controlling the output:
-D, --pgdata=DIRECTORY receive base backup into directory
-F, --format=p|t output format (plain (default), tar)
-r, --max-rate=RATE maximum transfer rate to transfer data directory
(in kB/s, or use suffix "k" or "M")
-R, --write-recovery-conf
write configuration for replication
-t, --target=TARGET[:DETAIL]
backup target (if other than client)
-T, --tablespace-mapping=OLDDIR=NEWDIR
relocate tablespace in OLDDIR to NEWDIR
--waldir=WALDIR location for the write-ahead log directory
-X, --wal-method=none|fetch|stream
include required WAL files with specified method
-z, --gzip compress tar output
-Z, --compress=[{client|server}-]METHOD[:DETAIL]
compress on client or server as specified
-Z, --compress=none do not compress tar output
General options:
-c, --checkpoint=fast|spread
set fast or spread checkpointing
-C, --create-slot create replication slot
-l, --label=LABEL set backup label
-n, --no-clean do not clean up after errors
-N, --no-sync do not waitfor changes to be written safely to disk
-P, --progress show progress information
-S, --slot=SLOTNAME replication slot to use
-v, --verbose output verbose messages
-V, --version output version information, thenexit
--manifest-checksums=SHA{224,256,384,512}|CRC32C|NONE
use algorithm for manifest checksums
--manifest-force-encode
hex encode all file names in manifest
--no-estimate-size do not estimate backup size in server side
--no-manifest suppress generation of backup manifest
--no-slot prevent creation of temporary replication slot
--no-verify-checksums
do not verify checksums
-?, --help show this help, thenexit
Connection options:
-d, --dbname=CONNSTR connection string
-h, --host=HOSTNAME database server host or socket directory
-p, --port=PORT database server port number
-s, --status-interval=INTERVAL
time between status packets sent to server (in seconds)
-U, --username=NAME connect as specified database user
-w, --no-password never prompt for password
-W, --password force password prompt (should happen automatically)
--polardata=datadir receive polar data backup into directory
--polar_disk_home=disk polar_disk_home for polar data backup
--polar_host_id=host_id polar_host_id for polar data backup
--polar_storage_cluster_name=cluster_name polar_storage_cluster_name for polar data backup
Report bugs to <[email protected]>.
PostgreSQL home page: <https://www.postgresql.org/>
5、检查一下备份的数据是否可以启动? 不出意外的话, 马上就要发生意外了. 恢复报错
首先要修改postgresql.conf配置, 之前的配置是在pfs环境中启动PolarDB, 现在要在本地盘启动PolarDB.
cd /data/backup
vi postgresql.conf
# 修改和注释如下
# polar_enable_shared_storage_mode=on
polar_disk_name='home'
polar_datadir='file-dio:///data/backup/'
polar_vfs.localfs_mode=true
# polar_storage_cluster_name='disk'
启动实例, 遇到报错
$ pg_ctl start -D /data/backup
waiting for server to start....115 2024-12-18 16:14:35.288 CST LOG: found standby.signal, PolarDB in standby mode, use readwrite mode mount pfs
115 2024-12-18 16:14:35.288 CST LOG: polar_vfs loaded in postmaster 115
115 2024-12-18 16:14:35.288 CST LOG: polar_vfs init done
115 2024-12-18 16:14:35.288 CST LOG: "polar_settings.conf" is in non-sharedstorage mode, additional load it.
postgres: could not find the database system
Expected to find it in the directory "/data/backup",
but could not open file "/data/backup/global/pg_control": No such file or directory
stopped waiting
pg_ctl: could not start server
Examine the log output.
分析这个报错看起来是少备份了内容? global这个目录怎么是空的?
$ ll /data/backup/global/
total 0
drwx------ 2 postgres postgres 64 Dec 18 16:03 ./
drwx------ 31 postgres postgres 992 Dec 18 16:12 ../
在pb1, pb2任意一个容器内查看pfs内容, 可以看到global里面的内容都没有备份下来.
$ sudo pfs -C disk ls /nvme1n1/shared_data/global/
File 1 8192 Wed Dec 18 09:43:41 2024 4182
File 1 16384 Wed Dec 18 09:43:41 2024 2672
File 1 8192 Wed Dec 18 09:43:41 2024 2847
File 1 8192 Wed Dec 18 09:43:41 2024 4061
File 1 24576 Wed Dec 18 09:43:41 2024 1261_fsm
File 1 8192 Wed Dec 18 09:43:41 2024 4186
File 1 0 Wed Dec 18 09:43:41 2024 4181
File 1 16384 Wed Dec 18 09:43:41 2024 2697
File 1 0 Wed Dec 18 09:43:41 2024 6000
File 1 16384 Wed Dec 18 09:43:41 2024 2695
File 1 8192 Wed Dec 18 09:43:41 2024 4178
File 1 16384 Wed Dec 18 09:43:41 2024 2694
File 1 0 Wed Dec 18 09:43:41 2024 4177
File 1 8192 Wed Dec 18 09:43:41 2024 1261
File 1 0 Wed Dec 18 09:43:41 2024 1214
File 1 8192 Wed Dec 18 09:43:41 2024 1213
File 1 8192 Wed Dec 18 09:43:41 2024 2965
File 1 8192 Wed Dec 18 09:43:41 2024 1262
File 1 0 Wed Dec 18 09:43:41 2024 6243
File 1 8192 Wed Dec 18 09:43:41 2024 1260
File 1 0 Wed Dec 18 09:43:41 2024 4175
File 1 8192 Wed Dec 18 09:43:41 2024 6114
File 1 8192 Wed Dec 18 09:43:41 2024 2396_vm
File 1 8192 Wed Dec 18 09:43:41 2024 6002
File 1 0 Wed Dec 18 09:43:41 2024 4183
File 1 16384 Wed Dec 18 09:43:41 2024 2676
File 1 8192 Wed Dec 18 09:43:41 2024 2396
File 1 0 Wed Dec 18 09:43:41 2024 2846
File 1 16384 Wed Dec 18 09:43:41 2024 2671
File 1 8192 Wed Dec 18 09:43:41 2024 1262_vm
File 1 16384 Wed Dec 18 09:43:41 2024 2677
File 1 0 Wed Dec 18 09:43:41 2024 6100
File 1 8192 Wed Dec 18 09:43:41 2024 2967
File 1 8192 Wed Dec 18 09:43:41 2024 6245
File 1 0 Wed Dec 18 09:43:41 2024 4060
File 1 8192 Wed Dec 18 09:43:41 2024 4184
File 1 8192 Wed Dec 18 09:43:41 2024 1260_vm
File 1 8192 Wed Dec 18 09:43:41 2024 6246
File 1 8192 Wed Dec 18 09:43:41 2024 6115
File 1 0 Wed Dec 18 09:43:41 2024 3592
File 1 8192 Wed Dec 18 09:43:41 2024 1261_vm
File 1 8192 Wed Dec 18 09:43:41 2024 6001
File 1 8192 Wed Dec 18 09:43:41 2024 3593
File 1 24576 Wed Dec 18 09:43:41 2024 2396_fsm
File 1 0 Wed Dec 18 09:43:41 2024 2966
File 1 8192 Wed Dec 18 09:43:41 2024 6247
File 1 0 Wed Dec 18 09:43:41 2024 6244
File 1 24576 Wed Dec 18 09:43:41 2024 1213_fsm
File 1 0 Wed Dec 18 09:43:41 2024 2964
File 1 8192 Wed Dec 18 09:43:41 2024 1233
File 1 0 Wed Dec 18 09:43:41 2024 4185
File 1 512 Wed Dec 18 09:43:41 2024 pg_filenode.map
File 1 24576 Wed Dec 18 09:43:41 2024 1260_fsm
File 1 8192 Wed Dec 18 09:43:41 2024 1213_vm
File 1 8192 Wed Dec 18 09:43:41 2024 pg_control
File 1 16384 Wed Dec 18 09:43:41 2024 2698
File 1 8192 Wed Dec 18 09:43:41 2024 4176
File 1 16384 Wed Dec 18 09:43:41 2024 2397
File 1 8192 Wed Dec 18 09:43:41 2024 1232
File 1 24576 Wed Dec 18 09:43:41 2024 1262_fsm
File 1 205 Wed Dec 18 15:48:04 2024 polar_settings.conf
total 376832 (unit: 512Bytes)
所以问题是: 通过polar_basebackup备份的内容不完整吗? 怎么解决呢?
解决办法如下.
6、polar_basebackup备份共享存储PolarDB时, 不仅要指定-D (存放本地实例数据), 还需要指定--polardata= (存放共享数据).
先清理刚才的无效备份目录:
sudo rm -rf /data/backup
sudo mkdir /data/backup
sudo chown postgres:postgres /data/backup
sudo chmod 700 /data/backup
将备份命令改成如下:
polar_basebackup \
--host=172.17.0.2 \
--port=5432 \
-D /data/backup/primary \
--polardata=/data/backup/shared_data \
-X stream --progress --write-recovery-conf -v
日志如下:
polar_basebackup: initiating base backup, waiting for checkpoint to complete
polar_basebackup: checkpoint completed
polar_basebackup: write-ahead log start point: 2/428 on timeline 1
polar_basebackup: starting background WAL receiver
polar_basebackup: created temporary replication slot "pg_basebackup_1654"
193070/193070 kB (100%), 2/2 tablespaces
polar_basebackup: write-ahead log end point: 2/538
polar_basebackup: waiting for background process to finish streaming ...
polar_basebackup: syncing data to disk ...
polar_basebackup: renaming backup_manifest.tmp to backup_manifest
polar_basebackup: base backup completed
查看备份目录内容, 现在完整了
postgres@9bab5d9c0b25:/data/backup$ ll /data/backup/primary
total 256
drwx------ 30 postgres postgres 960 Dec 18 17:53 ./
drwx------ 4 postgres postgres 128 Dec 18 17:53 ../
-rw------- 1 postgres postgres 217 Dec 18 17:53 backup_label
-rw------- 1 postgres postgres 191837 Dec 18 17:53 backup_manifest
drwx------ 6 postgres postgres 192 Dec 18 17:53 base/
-rw------- 1 postgres postgres 163 Dec 18 17:53 current_logfiles
drwx------ 2 postgres postgres 64 Dec 18 17:53 global/
drwx------ 2 postgres postgres 64 Dec 18 17:53 pg_commit_ts/
drwx------ 2 postgres postgres 64 Dec 18 17:53 pg_dynshmem/
-rw------- 1 postgres postgres 4870 Dec 18 17:53 pg_hba.conf
-rw------- 1 postgres postgres 1636 Dec 18 17:53 pg_ident.conf
drwx------ 47 postgres postgres 1504 Dec 18 17:53 pg_log/
drwx------ 5 postgres postgres 160 Dec 18 17:53 pg_logical/
drwx------ 4 postgres postgres 128 Dec 18 17:53 pg_multixact/
drwx------ 2 postgres postgres 64 Dec 18 17:53 pg_notify/
drwx------ 2 postgres postgres 64 Dec 18 17:53 pg_replslot/
drwx------ 2 postgres postgres 64 Dec 18 17:53 pg_serial/
drwx------ 2 postgres postgres 64 Dec 18 17:53 pg_snapshots/
drwx------ 2 postgres postgres 64 Dec 18 17:53 pg_stat/
drwx------ 2 postgres postgres 64 Dec 18 17:53 pg_stat_tmp/
drwx------ 2 postgres postgres 64 Dec 18 17:53 pg_subtrans/
drwx------ 2 postgres postgres 64 Dec 18 17:53 pg_tblspc/
-rw------- 1 postgres postgres 3 Dec 18 17:53 PG_VERSION
drwx------ 3 postgres postgres 96 Dec 18 17:53 pg_xact/
drwx------ 2 postgres postgres 64 Dec 18 17:53 polar_cache_trash/
-rw------- 1 postgres postgres 192 Dec 18 17:53 polar_settings.conf
-rw------- 1 postgres postgres 9 Dec 18 17:53 polar_shmem_stat_file
-rw------- 1 postgres postgres 463 Dec 18 17:53 postgresql.auto.conf
-rw------- 1 postgres postgres 29943 Dec 18 17:53 postgresql.conf
-rw------- 1 postgres postgres 0 Dec 18 17:53 standby.signalpostgres@9bab5d9c0b25:/data/backup$ ll /data/backup/shared_data
total 8
drwx------ 15 postgres postgres 480 Dec 18 17:53 ./
drwx------ 4 postgres postgres 128 Dec 18 17:53 ../
drwxrwxrwx 6 postgres postgres 192 Dec 18 17:53 base/
drwxrwxrwx 63 postgres postgres 2016 Dec 18 17:53 global/
drwxrwxrwx 2 postgres postgres 64 Dec 18 17:53 pg_commit_ts/
drwxrwxrwx 2 postgres postgres 64 Dec 18 17:53 pg_logindex/
drwxrwxrwx 4 postgres postgres 128 Dec 18 17:53 pg_multixact/
drwxrwxrwx 2 postgres postgres 64 Dec 18 17:53 pg_replslot/
drwxrwxrwx 2 postgres postgres 64 Dec 18 17:53 pg_tblspc/
drwxrwxrwx 2 postgres postgres 64 Dec 18 17:53 pg_twophase/
drwxrwxrwx 4 postgres postgres 128 Dec 18 17:53 pg_wal/
drwxrwxrwx 3 postgres postgres 96 Dec 18 17:53 pg_xact/
-rwxrwxrwx 1 postgres postgres 217 Dec 18 17:53 polar_non_exclusive_backup_label*
-rw------- 1 postgres postgres 257 Dec 18 17:53 postgresql.auto.conf
-rw------- 1 postgres postgres 0 Dec 18 17:53 standby.signal
7、使用完整备份集测试恢复, 正常.
修改配置文件
cd /data/backup/primary vi postgresql.conf
# 修改和注释如下
# 使用本地盘模拟共享存储的, 使用如下配置. 未来如果你想用zfs来搭建standby, 可以参考这份配置
polar_disk_name='home'
polar_datadir='file-dio:///data/backup/shared_data'
polar_vfs.localfs_mode=true
# polar_storage_cluster_name='disk'
# 其他配置保持不变即可
huge_pages=off
port=5433
polar_hostid=1
polar_enable_shared_storage_mode=on
shared_preload_libraries='$libdir/polar_vfs,$libdir/polar_worker'
logging_collector=on
log_line_prefix='%p\t%r\t%u\t%m\t'
log_directory='pg_log'
listen_addresses='0.0.0.0'
max_connections=200
# 下面几个参数解决replica不能promote的问题, 因为RO依赖logindex.
polar_logindex_mem_size=64MB
polar_xlog_queue_buffers=64MB
polar_xlog_page_buffers=64MB
# 使用pfs时可以关掉 full page write 和 polar_has_partial_write , 否则请打开这两
full_page_writes = off
polar_has_partial_write = off
polar_resource_manager.enable_resource_manager=off
# 注释掉
#primary_slot_name='replica1'
#primary_conninfo='host=172.17.0.3 port=5432 user=postgres dbname=postgres application_name=replica1' # 注意
再检查一下postgresql.auto.conf文件里的配置, 是否有和postgresql.conf重复的, 因为auto.conf优先级更高, 所以重复的配置将以auto.conf为准.
使用备份集启动数据库
pg_ctl start -D /data/backup/primary
postgres@9bab5d9c0b25:/data/backup/primary$ pg_ctl start -D /data/backup/primary
waiting for server to start....200 2024-12-19 09:19:12.478 CST LOG: found standby.signal, PolarDB in standby mode, use readwrite mode mount pfs
200 2024-12-19 09:19:12.479 CST LOG: polar_vfs loaded in postmaster 200
200 2024-12-19 09:19:12.479 CST LOG: Database will be in readwrite mode
200 2024-12-19 09:19:12.479 CST LOG: pfs in localfs mode
200 2024-12-19 09:19:12.479 CST LOG: polar_vfs init done
200 2024-12-19 09:19:12.481 CST LOG: "polar_settings.conf" is copied from sharedstorage success, additional load it.
200 2024-12-19 09:19:12.483 CST LOG: found standby.signal, PolarDB in standby mode, use readwrite mode mount pfs
200 2024-12-19 09:19:12.483 CST LOG: found standby.signal, PolarDB in standby mode, use readwrite mode mount pfs
200 2024-12-19 09:19:12.483 CST LOG: found standby.signal, PolarDB in standby mode, use readwrite mode mount pfs
200 2024-12-19 09:19:12.484 CST LOG: found standby.signal, PolarDB in standby mode, use readwrite mode mount pfs
200 2024-12-19 09:19:12.484 CST LOG: copy pg_control file from shared storage to local
200 2024-12-19 09:19:12.484 CST LOG: found standby.signal, PolarDB in standby mode, use readwrite mode mount pfs
200 2024-12-19 09:19:12.485 CST LOG: found standby.signal, PolarDB in standby mode, use readwrite mode mount pfs
200 2024-12-19 09:19:12.485 CST LOG: polardb read control file "file-dio:///data/backup/shared_data/global/pg_control" success
200 2024-12-19 09:19:12.485 CST LOG: PolarDB load controlfile in postmaster
200 2024-12-19 09:19:12.493 CST LOG: clog buffer max slot size is 256, and it will be set to 256
200 2024-12-19 09:19:12.493 CST LOG: commit timestamp buffer max slot size is 512, and it will set to 256
200 2024-12-19 09:19:12.495 CST LOG: found standby.signal, PolarDB in standby mode, use readwrite mode mount pfs
200 2024-12-19 09:19:12.495 CST LOG: clog buffer max slot size is 256, and it will be set to 256
200 2024-12-19 09:19:12.495 CST LOG: commit timestamp buffer max slot size is 512, and it will set to 256
200 2024-12-19 09:19:12.495 CST LOG: found standby.signal, PolarDB in standby mode, use readwrite mode mount pfs
200 2024-12-19 09:19:12.499 CST LOG: clog buffer max slot size is 256, and it will be set to 256
200 2024-12-19 09:19:12.499 CST LOG: commit timestamp buffer max slot size is 512, and it will set to 256
200 2024-12-19 09:19:12.503 CST LOG: initialized faultinjector shmem
200 2024-12-19 09:19:12.516 CST LOG: PolarIOStatArray share memory total size is 1220464
200 2024-12-19 09:19:12.520 CST LOG: redirecting log output to logging collector process
200 2024-12-19 09:19:12.520 CST HINT: Future log output will appear in directory "pg_log".
done
server started
检查备份集是否恢复正常
postgres@9bab5d9c0b25:/data/backup/primary$ psql -p 5433
psql (PostgreSQL 15.10 (PolarDB 15.10.2.0 build d4f5477d debug) on aarch64-linux-gnu)
Type "help"forhelp.postgres=# select pg_is_in_recovery();
pg_is_in_recovery
-------------------
t
(1 row)
8、最后:
其实除了以上备份方法, 我还是更喜欢这个方案: 使用zfs文件系统的standby, 打快照备份就可以; 归档的话把standby节点的archive_mode设置为always, 在standby节点进行归档即可. 搭建standby请参考: 《穷鬼玩PolarDB RAC一写多读集群系列 | 创建PolarDB 容灾(standby)节点》 略微改动postgresql.conf , 把 primary、shared_data 目录都拷贝到zfs使用即可.
老鸟肯定还看出少了点什么? 没错, 没有归档的备份是不完整的, 无法实现PITR. 请看下回分解.
参考
《穷鬼玩PolarDB RAC一写多读集群系列 | 在Docker容器中用loop设备模拟共享存储》
《穷鬼玩PolarDB RAC一写多读集群系列 | 如何搭建PolarDB容灾(standby)节点》
《穷鬼玩PolarDB RAC一写多读集群系列 | 共享存储在线扩容》
《穷鬼玩PolarDB RAC一写多读集群系列 | 计算节点 Switchover》
https://apsaradb.github.io/PolarDB-for-PostgreSQL/zh/operation/backup-and-restore.html
《如何创建RDS PG 的秒级 flashback闪回实例, 实时容灾实例 - zfs - snapshot - clone - standby - compress》
《PostgreSQL 最佳实践 - 块级增量备份(ZFS篇)验证 - recovery test script for zfs snapshot clone + postgresql stream replication + archive》
《PostgreSQL 最佳实践 - 块级增量备份(ZFS篇)双机HA与块级备份部署》
《PostgreSQL 最佳实践 - 块级增量备份(ZFS篇)单个数据库采用多个zfs卷(如表空间)时如何一致性备份》
《PostgreSQL 最佳实践 - 块级增量备份(ZFS篇)备份集有效性自动校验》
《PostgreSQL 最佳实践 - 块级增量备份(ZFS篇)方案与实战》
《PostgreSQL 快速大版本升级多种方案 - 含重点介绍fast & safe upgrade to PostgreSQL 9.4 use pg_upgrade & zfs》