PolarDB开源数据库进阶课5 在线备份

本文涉及的产品
云原生数据库 PolarDB MySQL 版,通用型 2核8GB 50GB
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
简介: 本文介绍了如何在PolarDB RAC一写多读集群中进行在线备份,特别针对共享存储模式。通过使用`polar_basebackup`工具,可以将实例的本地数据和共享数据备份到本地盘中。实验环境依赖于Docker容器中用loop设备模拟的共享存储。

背景

穷鬼玩PolarDB RAC一写多读集群系列已经写了几篇:

本篇文章介绍一下如何进行在线备份? 实验环境依赖 《在Docker容器中用loop设备模拟共享存储》 , 如果没有环境, 请自行参考以上文章搭建环境.

还需要参考如下文档:

DEMO

b站视频链接

Youtube视频链接

如果你要把共享存储的数据备份到另一个共享存储中, 可以参看这篇文章: 《如何搭建PolarDB容灾(standby)节点》

本文介绍的是把共享存储的数据备份到本地盘中.

本文测试环境继续使用 《如何搭建PolarDB容灾(standby)节点》 容器.

1、安装polardb 二进制

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 wait for 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, then exit  
      --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, then exit  
  
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 <pgsql-bugs@lists.postgresql.org>.  
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.signal
postgres@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" for help.
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》

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
打赏
0
1
1
0
20690
分享
相关文章
定期备份数据库:基于 Shell 脚本的自动化方案
本篇文章分享一个简单的 Shell 脚本,用于定期备份 MySQL 数据库,并自动将备份传输到远程服务器,帮助防止数据丢失。
喜报|PolarDB开源社区荣获“2024数据库国内活跃开源项目”奖
喜报|PolarDB开源社区荣获“2024数据库国内活跃开源项目”奖
首届全国大学生计算机系统能力大赛PolarDB数据库创新设计赛(天池杯)圆满收官
首届全国大学生计算机系统能力大赛PolarDB数据库创新设计赛(天池杯)圆满收官
世界第一!阿里云PolarDB登顶全球数据库性能及性价比排行榜!
2月26日,阿里云PolarDB在2025开发者大会上登顶全球数据库性能及性价比排行榜。此次突破标志着中国基础软件取得里程碑成就,PolarDB凭借创新的云原生架构,成功应对全球最大规模并发交易峰值,在性能、可扩展性等方面领先全球。
PolarDB开源数据库进阶课18 通过pg_bulkload适配pfs实现批量导入提速
本文介绍了如何修改 `pg_bulkload` 工具以适配 PolarDB 的 PFS(Polar File System),从而加速批量导入数据。实验环境依赖于 Docker 容器中的 loop 设备模拟共享存储。通过对 `writer_direct.c` 文件的修改,替换了一些标准文件操作接口为 PFS 对应接口,实现了对 PolarDB 15 版本的支持。测试结果显示,使用 `pg_bulkload` 导入 1000 万条数据的速度是 COPY 命令的三倍多。此外,文章还提供了详细的步骤和代码示例,帮助读者理解和实践这一过程。
46 0
PolarDB开源数据库进阶课17 集成数据湖功能
本文介绍了如何在PolarDB数据库中接入pg_duckdb、pg_mooncake插件以支持数据湖功能, 可以读写对象存储的远程数据, 支持csv, parquet等格式, 支持delta等框架, 并显著提升OLAP性能。
59 1
PolarDB开源数据库进阶课11 激活容灾(Standby)节点
本文介绍了如何激活PolarDB容灾(Standby)节点,实验环境依赖于Docker容器中用loop设备模拟共享存储。通过`pg_ctl promote`命令可以将Standby节点提升为主节点,使其能够接收读写请求。激活后,原Standby节点不能再成为PolarDB集群的Standby节点。建议删除对应的复制槽位以避免WAL文件堆积。相关操作和配置请参考系列文章及视频教程。
37 1
PolarDB开源数据库进阶课15 集成DeepSeek等大模型
本文介绍了如何在PolarDB数据库中接入私有化大模型服务,以实现多种应用场景。实验环境依赖于Docker容器中的loop设备模拟共享存储,具体搭建方法可参考相关系列文章。文中详细描述了部署ollama服务、编译并安装http和openai插件的过程,并通过示例展示了如何使用这些插件调用大模型API进行文本分析和情感分类等任务。此外,还探讨了如何设计表结构及触发器函数自动处理客户反馈数据,以及生成满足需求的SQL查询语句。最后对比了不同模型的回答效果,展示了deepseek-r1模型的优势。
101 0

相关产品

  • 云原生数据库 PolarDB
  • AI助理

    你好,我是AI助理

    可以解答问题、推荐解决方案等