mv pdata pdata.org
[postgres@dmdb1 pgdb941]$ ll
total 8
drwxrwxr-x 2 postgres postgres 6 Oct 9 10:36 archive
drwxrwxr-x 2 postgres postgres 21 Oct 9 10:58 logs
drwx------ 19 postgres postgres 4096 Oct 11 15:29 pdata
drwx------ 19 postgres postgres 4096 Oct 11 14:43 pdata.org
drwxrwxr-x 6 postgres postgres 56 Oct 9 10:52 psql
## 停止数据库
此时已经不能正常停止数据库,只能通过Kill进程结束
恢复操作:
1.创建数据目录
mkdir pdata
chmod 0700 pdata ## 如果不修改权限,在启动数据库的时候会出现如下告警
LOG: received fast shutdown request
LOG: aborting any active transactions
LOG: autovacuum launcher shutting down
LOG: shutting down
LOG: database system is shut down
LOG: database system was shut down at 2023-10-11 14:43:25 CST
LOG: database system is ready to accept connections
LOG: autovacuum launcher started
FATAL: data directory "/zabbix_src/pgdb941/pdata" has group or world access
DETAIL: Permissions should be u=rwx (0700).
2.拷贝备份文件到数据目录下
cp /backup/base.tar.gz pdata
tar -zxvf base.tar.gz
3.拷贝recovery.conf.sample到数据目录下
cp /zabbix_src/pgdb941/psql/share/postgresql/recovery.conf.sample ./recovery.conf
4.修改recovery.conf
restore_command = 'cp /zabbix_src/pgdb941/pdata/arch/%f %p'
/zabbix_src/pgdb941/pdata/arch目录是归档的路径
5.查看备份信息
$ cat backup_label
START WAL LOCATION: 0/27000028 (file 000000010000000000000027)
CHECKPOINT LOCATION: 0/27000028
BACKUP METHOD: streamed
BACKUP FROM: master
START TIME: 2023-10-11 12:29:47 CST
LABEL: full_backup
从备份信息中看到备份文件最新的归档文件是000000010000000000000027,确认归档目录下文件是否存在,
如果不存在则需要从备份文件中拷贝到归档目录下,否则恢复的时候会失败。
6.启动数据库
pg_ctl -D $PGDATA start
启动日志:
LOG: database system was interrupted; last known up at 2023-10-11 12:29:47 CST
LOG: starting archive recovery
LOG: restored log file "000000010000000000000027" from archive
LOG: redo starts at 0/27000090
LOG: consistent recovery state reached at 0/270000B8
cp: cannot stat ‘/zabbix_src/pgdb941/pdata/arch/000000010000000000000028’: No such file or directory
LOG: redo done at 0/270000B8
LOG: restored log file "000000010000000000000027" from archive
cp: cannot stat ‘/zabbix_src/pgdb941/pdata/arch/00000002.history’: No such file or directory
LOG: selected new timeline ID: 2
cp: cannot stat ‘/zabbix_src/pgdb941/pdata/arch/00000001.history’: No such file or directory
LOG: archive recovery complete
LOG: autovacuum launcher started
LOG: database system is ready to accept connections
7.验证数据
"public"."testdata3" 38 MB 11 MB 49 MB
"public"."test" 35 MB 0 bytes 35 MB
"public"."testdata2" 15 MB 4408 kB 20 MB
"public"."testdata" 7896 kB 0 bytes 7896 kB
"public"."t_centerprises" 8192 bytes 16 kB 24 kB