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