创建基础备份:
pg_basebackup -Ft -Pv -Xf -z -Z5 -p 5432 -D /pgdata/10/backup/
1.移除故障的数据目录或者新建数据目录:
2.创建数据目录并且解压使用pg_basebackup创建的备份:
mkdir -p /pgdata/10/data1
chmod 0700 /pgdata/10/data1
tar xvzf base.tar.gz -C /pgdata/10/data1/
3.创建recovery.conf文件进行配置:
cp /opt/pg10/share/postgresql/recovery.conf.sample /pgdata/10/data1/recovery.conf
chmod 0600 recovery.conf
select current_timestamp;
vi recovery.conf
a.恢复到最新:
restore_command = ‘cp /pgdata/10/archive_wal/%f %p‘
recovery_target_timeline = ‘latest‘
b.恢复到指定的时间点:
restore_command = ‘cp /pgdata/10/archive_wal/%f %p‘
recovery_target_time = ‘2019-04-02 13:16:49.007657+08‘
c.创建还原点:
SELECT pg_create_restore_point(‘restore_point1‘);
d.恢复到还原点:
restore_command = ‘cp /pgdata/10/archive_wal/%f %p‘
recovery_target_name =‘restore_point1‘
备注,在做的时候最好切换一个日志:select pg_switch_wal();
启动数据库进行恢复:
pg_ctl start -D /pgdata/10/data1/
原文地址:https://blog.51cto.com/1937519/2373012