PostgreSQL PITR无法正常工作。

5

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

如果只使用recovery.conf中的restore_command,则可以正常工作。

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

当我使用recovery_target_time参数时,它没有恢复到目标时间。

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个回答

5
您忘记设置了。
recovery_target_action = 'promote'

在点时间恢复之后,recovery_target_action 决定了 PostgreSQL 接下来的步骤。

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

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

SELECT pg_wal_replay_resume();

似乎在06:43:00至06:45:02期间没有记录任何数据库活动。请注意日志显示:恢复在事务9525中结束之前停止


YogeshR在06:43:00指定了停止点,并且实际上在事务9525中止之前就停止了,那么实际恢复停止点的确切逻辑或定义是什么?能帮忙解释一下吗? - undefined
@QiuYangfan 根据 recovery_target_inclusive 的设置,它会在第一笔交易达到恢复目标时停止,无论是大于还是大于等于恢复目标。 - undefined
非常感谢!如果设置了recovery_target_time=T1,是否真的会回放一些比T1更靠后但在下一个事务结束之前的LSN呢? - undefined
不,我说的是它只会停在那里,不会再播放恢复目标之后的任何内容。 - undefined
嗯,在我这个空闲的Postgres案例中,我在T1时刻获取了时间戳,然后在T1+d时刻删除了表,并使用recovery_target_time=T1进行恢复操作,表被恢复了但是被锁定了。我很困惑,如果停止点是T1,为什么表会被锁定呢? - undefined
@QiuYangfan 因为那个时候已经被锁定了。你应该另外提一个新的问题。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接