Search code examples
postgresqlpostgresql-9.6pitr

PostgreSQL Point in time recovery not working


We have 2 PostgreSQL servers setup as master-slave.

I want to test below scenario

I took a base backup at master and then deleted a table and switched xlog file using command select pg_switch_xlog();. Then I stopped the master. Promoted slave as the master and deleted one more table and switched log file.

Now I have restored this base backup and wal files of both servers on a new server and used recovery_target_time to test PITR. I am able to recover to a time when I haven't deleted any table or deleted 1 table from the old master. But I am not able to recover to a point in time when I deleted a table from the new master.

Below is the log output for the same

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

Below is the content of the recovery.conf file:

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'

What am I doing wrong here?


Solution

  • Recovery does not proceed to timeline 6 because you didn't add

    recovery_target_timeline = 'latest'
    

    to recovery.conf. As the documentation says:

    The default is to recover along the same timeline that was current when the base backup was taken.