PostgreSQL时间点恢复无法正常工作

时间:2018-08-06 15:11:18

标签: postgresql postgresql-9.6 pitr

我们有2个PostgreSQL服务器设置为主从服务器。

我想在以下情况下进行测试

我在master上进行了基本备份,然后使用命令select pg_switch_xlog();删除了表并切换了xlog文件。然后我停了主人。提升了从属服务器作为主服务器,并删除了另外一个表和切换的日志文件。

现在,我已在新服务器上还原了这两个服务器的基本备份和wal文件,并使用recovery_target_time测试PITR。我可以恢复到没有从旧主数据库删除任何表或删除1个表的时间。但是当我从新的母版删除表时,我无法恢复到某个时间点。

以下是相同日志的输出

2018-08-06 14:49:39.564 UTC  [19772] LOG:  starting point-in-time recovery to 2018-08-06 14:20:00+00
cp: cannot stat ‘/var/lib/pgsql/pg_log_archive/00000005.history’: No such file or directory
2018-08-06 14:49:39.579 UTC  [19772] LOG:  restored log file "000000050000000200000046" from archive
2018-08-06 14:49:39.630 UTC  [19772] LOG:  redo starts at 2/46000028
2018-08-06 14:49:39.635 UTC  [19772] LOG:  consistent recovery state reached at 2/460ABCE8
2018-08-06 14:49:39.636 UTC  [19770] LOG:  database system is ready to accept read only connections
2018-08-06 14:49:39.648 UTC  [19772] LOG:  restored log file "000000050000000200000047" from archive
2018-08-06 14:49:39.732 UTC  [19772] LOG:  restored log file "000000050000000200000048" from archive
cp: cannot stat ‘/var/lib/pgsql/pg_log_archive/000000050000000200000049’: No such file or directory
2018-08-06 14:49:39.780 UTC  [19772] LOG:  redo done at 2/48003410
2018-08-06 14:49:39.780 UTC  [19772] LOG:  last completed transaction was at log time 2018-08-06 13:27:00.442816+00
2018-08-06 14:49:39.796 UTC  [19772] LOG:  restored log file "000000050000000200000048" from archive
2018-08-06 14:49:39.843 UTC  [19772] LOG:  restored log file "00000006.history" from archive
cp: cannot stat ‘/var/lib/pgsql/pg_log_archive/00000007.history’: No such file or directory
2018-08-06 14:49:39.845 UTC  [19772] LOG:  selected new timeline ID: 7
cp: cannot stat ‘/var/lib/pgsql/pg_log_archive/00000005.history’: No such file or directory
2018-08-06 14:49:39.903 UTC  [19772] LOG:  archive recovery complete
2018-08-06 14:49:40.006 UTC  [19772] LOG:  MultiXact member wraparound protections are now enabled
2018-08-06 14:49:40.008 UTC  [19770] LOG:  database system is ready to accept connections
2018-08-06 14:49:40.009 UTC  [19786] LOG:  autovacuum launcher started

下面是recovery.conf文件的内容:

restore_command = 'cp /var/lib/pgsql/pg_log_archive/%f %p'
recovery_target_time = '2018-08-06 14:20:00.0'
recovery_target_inclusive = 'true'
recovery_target_action = 'promote'

我在这里做什么错了?

1 个答案:

答案 0 :(得分:1)

恢复没有继续到时间轴6,因为您没有添加

status expired

recovery_target_timeline = 'latest' 。正如the documentation所说:

  

默认设置是按照与进行基本备份时相同的时间表进行恢复。