PostgreSQL 时间点恢复不起作用
Posted
技术标签:
【中文标题】PostgreSQL 时间点恢复不起作用【英文标题】:PostgreSQL Point in time recovery not working 【发布时间】:2018-08-06 15:11:17 【问题描述】:我们有 2 台 PostgreSQL 服务器设置为主从服务器。
我想测试以下场景
我在 master 进行了基本备份,然后使用命令 select pg_switch_xlog();
删除了一个表并切换了 xlog 文件。然后我阻止了主人。将slave提升为master并删除了一张表并切换了日志文件。
现在我已在新服务器上恢复了两台服务器的基本备份和 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】:恢复不会继续到时间线 6,因为您没有添加
recovery_target_timeline = 'latest'
到recovery.conf
。正如the documentation 所说:
默认设置是沿进行基本备份时的当前时间线进行恢复。
【讨论】:
目前我在 recovery.conf 中使用 restore_command、recovery_target_time、recovery_target_inclusive、recovery_target_action。现在我正在添加 recovery_target_timeline。现在对于时间点恢复是否完美? 我应该这么说。您能否自行编辑您的问题以添加正确的信息?以上是关于PostgreSQL 时间点恢复不起作用的主要内容,如果未能解决你的问题,请参考以下文章
SQLAlchemy 使用合并更新 PostgreSQL 数组不起作用
Postgresql 复合唯一键(LastName、FirstName、MiddleName)不起作用?