Skip to content

Commit ebf6de8

Browse files
committed
Add more TAP coverage for archive status with crash recovery of standbys
This part of the test was included originally in 4e87c48, but got reverted as of f9c1b8d because of timing issues in the test, where, after more analysis, we found that the standbys may not have recovered from the archives all the segments needed by the test. This stabilizes the test by making sure that standbys replay up to the position returned by pg_switch_wal(), meaning that all segments are recovered before the manual checkpoint that tests WAL segment recycling and its interactions with archive status files. Author: Jehan-Guillaume de Rorthais Reviewed-by: Kyotaro Horiguchi, Michael Paquier Discussion: https://postgr.es/m/[email protected]
1 parent 0278d3f commit ebf6de8

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/test/recovery/t/020_archive_status.pl

+36-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use warnings;
66
use PostgresNode;
77
use TestLib;
8-
use Test::More tests => 13;
8+
use Test::More tests => 16;
99
use Config;
1010

1111
my $primary = get_new_node('master');
@@ -119,10 +119,16 @@
119119
$primary->safe_psql(
120120
'postgres', q{
121121
INSERT INTO mine SELECT generate_series(10,20) AS x;
122-
SELECT pg_switch_wal();
123122
CHECKPOINT;
124123
});
125124

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+
126132
$primary->poll_query_until('postgres',
127133
q{ SELECT last_archived_wal FROM pg_stat_archiver },
128134
$segment_name_2)
@@ -134,14 +140,32 @@
134140
$standby1->append_conf('postgresql.conf', "archive_mode = on");
135141
my $standby1_data = $standby1->data_dir;
136142
$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+
137150
$standby1->safe_psql('postgres', q{CHECKPOINT});
138151

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+
139158
# Recovery with archive_mode=on should not create .ready files.
140159
# Note that this segment did not exist in the backup.
141160
ok( !-f "$standby1_data/$segment_path_2_ready",
142161
".ready file for WAL segment $segment_name_2 not created on standby when archive_mode=on on standby"
143162
);
144163

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+
145169
# Test recovery with archive_mode = always, which should always keep
146170
# .ready files if archiving is enabled, though here we want the archive
147171
# command to fail to persist the .ready files. Note that this node
@@ -153,12 +177,22 @@
153177
my $standby2_data = $standby2->data_dir;
154178
$standby2->start;
155179

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+
156186
$standby2->safe_psql('postgres', q{CHECKPOINT});
157187

158188
ok( -f "$standby2_data/$segment_path_1_ready",
159189
".ready file for WAL segment $segment_name_1 existing in backup is kept with archive_mode=always on standby"
160190
);
161191

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+
162196
# Reset statistics of the archiver for the next checks.
163197
$standby2->safe_psql('postgres', q{SELECT pg_stat_reset_shared('archiver')});
164198

0 commit comments

Comments
 (0)