pg_basebackup物理备份与还原

pg_basebackup被用于获得一个正在运行的PostgreSQL数据库集簇的基础备份,简单记录下过程

1、初始化数据库(pg版本12.1)

./initdb -USYSTEM -W -D ./data

 

 

 

 2、修改配置文件

1、vim postgresql.conf
listen_addresses = '*'
wal_level = replica
archive_mode = on
archive_command = 'cp %p /home/cli/bin/%f && echo %f >> /home/cli/bin/archive.list' max_wal_senders= 10 wal_keep_segments=1024 hot_standby = on
2、vim postgresql.conf
host    replication     all             192.168.1.108/32            trust

3、创建基础备份

主机启动数据库
./pg_ctl -D data/ start

备机创建备份集

  ./pg_basebackup -D /home/cli/pg/bin/back -Ft -v -P -USYSTEM -h 192.168.1.108 -p5432 -R

-----------------

[cli@localhost bin]$ ./pg_basebackup -D /home/cli/pg/bin/back -Ft -v -P -USYSTEM -h 192.168.1.108 -p5432 -R
pg_basebackup: 开始基础备份,等待检查点完成
pg_basebackup: 已完成检查点
pg_basebackup: 预写日志起始于时间点: 0/2000028, 基于时间轴1
pg_basebackup: 启动后台 WAL 接收进程
pg_basebackup: 已创建临时复制槽"pg_basebackup_52255"
24761/24761 kB (100%), 1/1 表空间
pg_basebackup: 预写日志结束点: 0/2000100
pg_basebackup: 等待后台进程结束流操作...
pg_basebackup: 同步数据到磁盘...
pg_basebackup: 基础备份已完成

4、备机进行恢复

1、查看备份文件
[
cli@localhost back]$ ls base.tar pg_wal.tar

2、解压备份文件至数据库data目录
[cli@localhost back]$ tar -xvf base.tar -C ../data/
3、查看data目录文件
[cli@localhost data]$ ls
backup_label pg_commit_ts pg_ident.conf pg_notify pg_snapshots pg_subtrans PG_VERSION postgresql.auto.conf tablespace_map
base pg_dynshmem pg_logical pg_replslot pg_stat pg_tblspc pg_wal postgresql.conf
global pg_hba.conf pg_multixact pg_serial pg_stat_tmp pg_twophase pg_xact standby.signal
4、复制pg_wal目录下的日志文件至archive目录下(/home/cli/bin)
5、修改postgresql.auto.conf,
restore_command = 'cp /home/cli/bin/%f %p'
6、启动备机数据库,恢复完成

 

posted @ 2020-02-10 17:42  明矾  阅读(6582)  评论(0编辑  收藏  举报