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

简介: 本文介绍了如何在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数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
3月前
|
SQL 关系型数据库 MySQL
开源新发布|PolarDB-X v2.4.2开源生态适配升级
PolarDB-X v2.4.2开源发布,重点完善生态能力:新增客户端驱动、开源polardbx-proxy组件,支持读写分离与高可用;强化DDL变更、扩缩容等运维能力,并兼容MySQL主备复制及MCP AI生态。
开源新发布|PolarDB-X v2.4.2开源生态适配升级
|
3月前
|
SQL 关系型数据库 MySQL
开源新发布|PolarDB-X v2.4.2开源生态适配升级
PolarDB-X v2.4.2发布,新增开源Proxy组件与客户端驱动,支持读写分离、无感高可用切换及DDL在线变更,兼容MySQL生态,提升千亿级大表运维稳定性。
791 24
开源新发布|PolarDB-X v2.4.2开源生态适配升级
|
6月前
|
存储 关系型数据库 分布式数据库
喜报|阿里云PolarDB数据库(分布式版)荣获国内首台(套)产品奖项
阿里云PolarDB数据库管理软件(分布式版)荣获「2024年度国内首版次软件」称号,并跻身《2024年度浙江省首台(套)推广应用典型案例》。
|
7月前
|
关系型数据库 分布式数据库 数据库
再获殊荣,阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
内存池化技术新突破,阿里云PolarDB蝉联SIGMOD最佳论文奖
|
4月前
|
Cloud Native 关系型数据库 MySQL
免费体验!高效实现自建 MySQL 数据库平滑迁移至 PolarDB-X
PolarDB-X 是阿里云推出的云原生分布式数据库,支持PB级存储扩展、高并发访问与数据强一致,助力企业实现MySQL平滑迁移。现已开放免费体验,点击即享高效、稳定的数据库升级方案。
免费体验!高效实现自建 MySQL 数据库平滑迁移至 PolarDB-X
|
4月前
|
关系型数据库 MySQL 分布式数据库
阿里云PolarDB云原生数据库收费价格:MySQL和PostgreSQL详细介绍
阿里云PolarDB兼容MySQL、PostgreSQL及Oracle语法,支持集中式与分布式架构。标准版2核4G年费1116元起,企业版最高性能达4核16G,支持HTAP与多级高可用,广泛应用于金融、政务、互联网等领域,TCO成本降低50%。
|
5月前
|
人工智能 关系型数据库 MySQL
开源PolarDB-X:单节点误删除binlog恢复
本文由邵亚鹏撰写,分享了在使用开源PolarDB-X过程中,因误删binlog导致数据库服务无法启动的问题及恢复过程。作者结合实践经验,详细介绍了在无备份情况下如何通过单节点恢复机制重启数据库,并提出了避免类似问题的几点建议,包括采用高可用部署、定期备份及升级至最新版本等。
|
6月前
|
关系型数据库 分布式数据库 数据库
阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
阿里云PolarDB凭借全球首创基于CXL Switch的分布式内存池技术,在SIGMOD 2025上荣获工业赛道“最佳论文奖”,连续两年蝉联该顶会最高奖项。其创新架构PolarCXLMem打破传统RDMA技术瓶颈,性能提升2.1倍,并已落地应用于内存池化场景,推动大模型推理与多模态存储发展,展现CXL Switch在高速互联中的巨大潜力。
阿里云PolarDB数据库蝉联SIGMOD最佳论文奖
|
7月前
|
Cloud Native 关系型数据库 分布式数据库
客户说|知乎基于阿里云PolarDB,实现最大数据库集群云原生升级
近日,知乎最大的风控业务数据库集群,基于阿里云瑶池数据库完成了云原生技术架构的升级。此次升级不仅显著提升了系统的高可用性和性能上限,还大幅降低了底层资源成本。
|
存储 关系型数据库 MySQL
开源PolarDB- X|替换Opengemini时序数据场景下产品力校验
本文作者:黄周霖,数据库技术专家,就职于南京北路智控股份有限公司,负责数据库运维及大数据开发。

相关产品

  • 云原生数据库 PolarDB