|
5 | 5 | use warnings;
|
6 | 6 | use PostgresNode;
|
7 | 7 | use TestLib;
|
8 |
| -use Test::More tests => 13; |
| 8 | +use Test::More tests => 16; |
9 | 9 | use Config;
|
10 | 10 |
|
11 | 11 | my $primary = get_new_node('master');
|
|
119 | 119 | $primary->safe_psql(
|
120 | 120 | 'postgres', q{
|
121 | 121 | INSERT INTO mine SELECT generate_series(10,20) AS x;
|
122 |
| - SELECT pg_switch_wal(); |
123 | 122 | CHECKPOINT;
|
124 | 123 | });
|
125 | 124 |
|
| 125 | +# Switch to a new segment and use the returned LSN to make sure that |
| 126 | +# standbys have caught up to this point. |
| 127 | +my $primary_lsn = $primary->safe_psql( |
| 128 | + 'postgres', q{ |
| 129 | + SELECT pg_switch_wal(); |
| 130 | +}); |
| 131 | + |
126 | 132 | $primary->poll_query_until('postgres',
|
127 | 133 | q{ SELECT last_archived_wal FROM pg_stat_archiver },
|
128 | 134 | $segment_name_2)
|
|
134 | 140 | $standby1->append_conf('postgresql.conf', "archive_mode = on");
|
135 | 141 | my $standby1_data = $standby1->data_dir;
|
136 | 142 | $standby1->start;
|
| 143 | + |
| 144 | +# Wait for the replay of the segment switch done previously, ensuring |
| 145 | +# that all segments needed are restored from the archives. |
| 146 | +$standby1->poll_query_until('postgres', |
| 147 | + qq{ SELECT pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '$primary_lsn') >= 0 } |
| 148 | +) or die "Timed out while waiting for xlog replay on standby2"; |
| 149 | + |
137 | 150 | $standby1->safe_psql('postgres', q{CHECKPOINT});
|
138 | 151 |
|
| 152 | +# Recovery with archive_mode=on does not keep .ready signal files inherited |
| 153 | +# from backup. Note that this WAL segment existed in the backup. |
| 154 | +ok( !-f "$standby1_data/$segment_path_1_ready", |
| 155 | + ".ready file for WAL segment $segment_name_1 present in backup got removed with archive_mode=on on standby" |
| 156 | +); |
| 157 | + |
139 | 158 | # Recovery with archive_mode=on should not create .ready files.
|
140 | 159 | # Note that this segment did not exist in the backup.
|
141 | 160 | ok( !-f "$standby1_data/$segment_path_2_ready",
|
142 | 161 | ".ready file for WAL segment $segment_name_2 not created on standby when archive_mode=on on standby"
|
143 | 162 | );
|
144 | 163 |
|
| 164 | +# Recovery with archive_mode = on creates .done files. |
| 165 | +ok( -f "$standby1_data/$segment_path_2_done", |
| 166 | + ".done file for WAL segment $segment_name_2 created when archive_mode=on on standby" |
| 167 | +); |
| 168 | + |
145 | 169 | # Test recovery with archive_mode = always, which should always keep
|
146 | 170 | # .ready files if archiving is enabled, though here we want the archive
|
147 | 171 | # command to fail to persist the .ready files. Note that this node
|
|
153 | 177 | my $standby2_data = $standby2->data_dir;
|
154 | 178 | $standby2->start;
|
155 | 179 |
|
| 180 | +# Wait for the replay of the segment switch done previously, ensuring |
| 181 | +# that all segments needed are restored from the archives. |
| 182 | +$standby2->poll_query_until('postgres', |
| 183 | + qq{ SELECT pg_wal_lsn_diff(pg_last_wal_replay_lsn(), '$primary_lsn') >= 0 } |
| 184 | +) or die "Timed out while waiting for xlog replay on standby2"; |
| 185 | + |
156 | 186 | $standby2->safe_psql('postgres', q{CHECKPOINT});
|
157 | 187 |
|
158 | 188 | ok( -f "$standby2_data/$segment_path_1_ready",
|
159 | 189 | ".ready file for WAL segment $segment_name_1 existing in backup is kept with archive_mode=always on standby"
|
160 | 190 | );
|
161 | 191 |
|
| 192 | +ok( -f "$standby2_data/$segment_path_2_ready", |
| 193 | + ".ready file for WAL segment $segment_name_2 created with archive_mode=always on standby" |
| 194 | +); |
| 195 | + |
162 | 196 | # Reset statistics of the archiver for the next checks.
|
163 | 197 | $standby2->safe_psql('postgres', q{SELECT pg_stat_reset_shared('archiver')});
|
164 | 198 |
|
|
0 commit comments