PostgreSQL PITR无法正常工作

时间:2018-06-05 08:46:29

标签: postgresql postgresql-9.6 pitr

我正在尝试将PostgreSQL数据库恢复到某个时间点。

当我在restore_command中仅使用recovery.conf时,它的工作正常。

restore_command = 'cp /var/lib/pgsql/pg_log_archive/%f %p'

当我使用recovery_target_time parameter时,它不会恢复到目标时间。

restore_command = 'cp /var/lib/pgsql/pg_log_archive/%f %p'
recovery_target_time='2018-06-05 06:43:00.0'

以下是日志文件内容:

2018-06-05 07:31:39.166 UTC [22512] LOG:  database system was interrupted; last known up at 2018-06-05 06:35:52 UTC
2018-06-05 07:31:39.664 UTC [22512] LOG:  starting point-in-time recovery to 2018-06-05 06:43:00+00
2018-06-05 07:31:39.671 UTC [22512] LOG:  restored log file "00000005.history" from archive
2018-06-05 07:31:39.769 UTC [22512] LOG:  restored log file "00000005000000020000008F" from archive
2018-06-05 07:31:39.816 UTC [22512] LOG:  redo starts at 2/8F000028
2018-06-05 07:31:39.817 UTC [22512] LOG:  consistent recovery state reached at 2/8F000130
2018-06-05 07:31:39.818 UTC [22510] LOG:  database system is ready to accept read only connections
2018-06-05 07:31:39.912 UTC [22512] LOG:  restored log file "000000050000000200000090" from archive
2018-06-05 07:31:39.996 UTC [22512] LOG:  recovery stopping before abort of transaction 9525, time 2018-06-05 06:45:02.088502+00
2018-06-05 07:31:39.996 UTC [22512] LOG:  recovery has paused

我正在尝试将数据库实例恢复到06:43:00。为什么恢复到06:45:02?

修改

在第一个场景中,recovery.conf已转换为recovery.done,但这并未在第二个场景中发生

这可能是什么原因?

1 个答案:

答案 0 :(得分:2)

你忘了设置

recovery_target_action = 'promote'

在时间点恢复之后,recovery_target_action确定PostgreSQL将如何继续。

默认值为pause,这意味着PostgreSQL什么都不做,等着你告诉它如何继续。

要完成恢复,请连接到数据库并运行

SELECT pg_wal_replay_resume();

似乎在06:43:00和06:45:02之间没有记录数据库活动。观察日志显示recovery stopping before abort of transaction 9525