|
24 | 24 |
|
25 | 25 | # Initialize standby node from backup, fetching WAL from archives
|
26 | 26 | my $node_standby = PostgreSQL::Test::Cluster->new('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',
|
|
81 | 83 | # file, switch to a timeline large enough to allow a standby to recover
|
82 | 84 | # a history file from an archive. As this requires at least two timeline
|
83 | 85 | # switches, promote the existing standby first. Then create a second
|
84 |
| -# standby based on the promoted one. Finally, the second standby is |
85 |
| -# promoted. |
| 86 | +# standby based on the primary, using its archives. Finally, the second |
| 87 | +# standby is promoted. |
86 | 88 | $node_standby->promote;
|
87 | 89 |
|
| 90 | +# Wait until the history file has been stored on the archives of the |
| 91 | +# primary once the promotion of the standby completes. This ensures that |
| 92 | +# the second standby created below will be able to restore this file, |
| 93 | +# creating a RECOVERYHISTORY. |
| 94 | +my $primary_archive = $node_primary->archive_dir; |
| 95 | +$caughtup_query = |
| 96 | + "SELECT size IS NOT NULL FROM pg_stat_file('$primary_archive/00000002.history')"; |
| 97 | +$node_primary->poll_query_until('postgres', $caughtup_query) |
| 98 | + or die "Timed out while waiting for archiving of 00000002.history"; |
| 99 | + |
88 | 100 | # recovery_end_command should have been triggered on promotion.
|
89 | 101 | ok( -f "$data_dir/$recovery_end_command_file",
|
90 | 102 | 'recovery_end_command executed after promotion');
|
|
108 | 120 | # Now promote standby2, and check that temporary files specifically
|
109 | 121 | # generated during archive recovery are removed by the end of recovery.
|
110 | 122 | $node_standby2->promote;
|
| 123 | + |
| 124 | +# Check the logs of the standby to see that the commands have failed. |
| 125 | +my $log_contents = slurp_file($node_standby2->logfile, $log_location); |
111 | 126 | my $node_standby2_data = $node_standby2->data_dir;
|
| 127 | + |
| 128 | +like( |
| 129 | + $log_contents, |
| 130 | + qr/restored log file "00000002.history" from archive/s, |
| 131 | + "00000002.history retrieved from the archives"); |
112 | 132 | ok( !-f "$node_standby2_data/pg_wal/RECOVERYHISTORY",
|
113 | 133 | "RECOVERYHISTORY removed after promotion");
|
114 | 134 | ok( !-f "$node_standby2_data/pg_wal/RECOVERYXLOG",
|
115 | 135 | "RECOVERYXLOG removed after promotion");
|
116 |
| - |
117 |
| -# Check the logs of the standby to see that the commands have failed. |
118 |
| -my $log_contents = slurp_file($node_standby2->logfile, $log_location); |
119 | 136 | like(
|
120 | 137 | $log_contents,
|
121 | 138 | qr/WARNING:.*recovery_end_command/s,
|
|
0 commit comments