在什么时候PostgreSQL开始恢复

时间:2015-10-08 15:33:02

标签: postgresql recovery

我要从备用服务器进行备份。我使用以下命令创建二进制备份:

psql -c 'select pg_xlog_replay_pause()'
tar c data --exclude=pg_xlog/* | lzop --fast > /mnt/nfs/backup/xxxx.tar.lzop
psql -c 'select pg_xlog_replay_resume()'

来自master数据库的所有WAL日志都存储在外部存储上几天,使用这些日志进行恢复非常有效。但是,清除日志后备份将变为无效。解决方案是从备份完成后将所有需要的WAL日志从某个点复制到最后一个日志。

问题是第一个文件是什么?

pg_controldata显示:

pg_control version number:            942
Catalog version number:               201409291
Database system identifier:           6185091942558520564
Database cluster state:               in archive recovery
pg_control last modified:             Thu 08 Oct 2015 03:14:23 PM UTC
Latest checkpoint location:           1C41/F662E1F8
Prior checkpoint location:            1C41/B4435EE8
Latest checkpoint's REDO location:    1C41/DE003400
Latest checkpoint's REDO WAL file:    0000000200001C41000000DE
Latest checkpoint's TimeLineID:       2
Latest checkpoint's PrevTimeLineID:   2
Latest checkpoint's full_page_writes: on
Latest checkpoint's NextXID:          0/3550951620
Latest checkpoint's NextOID:          83806
Latest checkpoint's NextMultiXactId:  1
Latest checkpoint's NextMultiOffset:  0
Latest checkpoint's oldestXID:        3152230057
Latest checkpoint's oldestXID's DB:   16385
Latest checkpoint's oldestActiveXID:  3550951620
Latest checkpoint's oldestMultiXid:   1
Latest checkpoint's oldestMulti's DB: 16385
Time of latest checkpoint:            Thu 08 Oct 2015 03:10:44 PM UTC
Fake LSN counter for unlogged rels:   0/1
Minimum recovery ending location:     1C42/4CC934E0

那么第一个文件是什么? AFAIK PostgreSQL总是从检查点开始恢复。我试图恢复多个备份,并注意到PostgreSQL从Prior checkpoint location开始恢复。这总是如此吗? Prior checkpoint locationLatest checkpoint location之间的区别是什么?

根据pg_controldata:

First file: 1C41/B4
Minimum last file: 1C42/4C (Must be greater of equal to `Minimum recovery ending location`)

我是对的吗?

1 个答案:

答案 0 :(得分:2)

您需要从“最后检查点的重做位置” - 第一个WAL用“最后检查点的REDO WAL文件”标识 - 到时间线“最后检查点的TimeLineID”上包含“最小恢复结束位置”的WAL段。

在您的示例中,1C41/DE003400 1C42/4CC934E0位于LSN TimeLineID2

这对应于WAL段0000000200001C41000000DE0000000200001C42????????