|
3 | 3 | use warnings;
|
4 | 4 | use PostgresNode;
|
5 | 5 | use TestLib;
|
6 |
| -use Test::More tests => 3; |
| 6 | +use Test::More tests => 4; |
7 | 7 | use File::Copy;
|
8 | 8 |
|
9 | 9 | # Initialize master node, doing archives
|
|
21 | 21 |
|
22 | 22 | # Initialize standby node from backup, fetching WAL from archives
|
23 | 23 | my $node_standby = get_new_node('standby');
|
| 24 | +# Note that this makes the standby store its contents on the archives |
| 25 | +# of the primary. |
24 | 26 | $node_standby->init_from_backup($node_master, $backup_name,
|
25 | 27 | has_restoring => 1);
|
26 | 28 | $node_standby->append_conf('postgresql.conf',
|
|
55 | 57 | # file, switch to a timeline large enough to allow a standby to recover
|
56 | 58 | # a history file from an archive. As this requires at least two timeline
|
57 | 59 | # switches, promote the existing standby first. Then create a second
|
58 |
| -# standby based on the promoted one. Finally, the second standby is |
59 |
| -# promoted. |
| 60 | +# standby based on the primary, using its archives. Finally, the second |
| 61 | +# standby is promoted. |
60 | 62 | $node_standby->promote;
|
61 | 63 |
|
| 64 | +# Wait until the history file has been stored on the archives of the |
| 65 | +# primary once the promotion of the standby completes. This ensures that |
| 66 | +# the second standby created below will be able to restore this file, |
| 67 | +# creating a RECOVERYHISTORY. |
| 68 | +my $primary_archive = $node_master->archive_dir; |
| 69 | +$caughtup_query = |
| 70 | + "SELECT size IS NOT NULL FROM pg_stat_file('$primary_archive/00000002.history')"; |
| 71 | +$node_master->poll_query_until('postgres', $caughtup_query) |
| 72 | + or die "Timed out while waiting for archiving of 00000002.history"; |
| 73 | + |
62 | 74 | my $node_standby2 = get_new_node('standby2');
|
63 | 75 | $node_standby2->init_from_backup($node_master, $backup_name,
|
64 | 76 | has_restoring => 1);
|
65 | 77 | $node_standby2->start;
|
66 | 78 |
|
| 79 | +my $log_location = -s $node_standby2->logfile; |
| 80 | + |
67 | 81 | # Now promote standby2, and check that temporary files specifically
|
68 | 82 | # generated during archive recovery are removed by the end of recovery.
|
69 | 83 | $node_standby2->promote;
|
| 84 | + |
| 85 | +# Check the logs of the standby to see that the commands have failed. |
| 86 | +my $log_contents = slurp_file($node_standby2->logfile, $log_location); |
70 | 87 | my $node_standby2_data = $node_standby2->data_dir;
|
| 88 | + |
| 89 | +like( |
| 90 | + $log_contents, |
| 91 | + qr/restored log file "00000002.history" from archive/s, |
| 92 | + "00000002.history retrieved from the archives"); |
71 | 93 | ok( !-f "$node_standby2_data/pg_wal/RECOVERYHISTORY",
|
72 | 94 | "RECOVERYHISTORY removed after promotion");
|
73 | 95 | ok( !-f "$node_standby2_data/pg_wal/RECOVERYXLOG",
|
|
0 commit comments