@@ -146,6 +146,20 @@ sub test_target_session_attrs
146
146
" wal_receiver_status_interval = 1" );
147
147
$node_standby_2 -> restart;
148
148
149
+ # Wait for given condition on slot's pg_replication_slots row --- useful for
150
+ # ensuring we've reached a quiescent condition for reading slot xmins
151
+ sub wait_slot_xmins
152
+ {
153
+ my ($node , $slot_name , $check_expr ) = @_ ;
154
+
155
+ $node -> poll_query_until(' postgres' , qq[
156
+ SELECT $check_expr
157
+ FROM pg_catalog.pg_replication_slots
158
+ WHERE slot_name = '$slot_name ';
159
+ ] );
160
+ }
161
+
162
+ # Fetch xmin columns from slot's pg_replication_slots row
149
163
sub get_slot_xmins
150
164
{
151
165
my ($node , $slotname ) = @_ ;
@@ -156,12 +170,12 @@ sub get_slot_xmins
156
170
# There's no hot standby feedback and there are no logical slots on either peer
157
171
# so xmin and catalog_xmin should be null on both slots.
158
172
my ($xmin , $catalog_xmin ) = get_slot_xmins($node_master , $slotname_1 );
159
- is($xmin , ' ' , ' non-cascaded slot xmin null with no hs_feedback' );
160
- is($catalog_xmin , ' ' , ' non-cascaded slot xmin null with no hs_feedback' );
173
+ is($xmin , ' ' , ' xmin of non-cascaded slot null with no hs_feedback' );
174
+ is($catalog_xmin , ' ' , ' catalog xmin of non-cascaded slot null with no hs_feedback' );
161
175
162
176
($xmin , $catalog_xmin ) = get_slot_xmins($node_standby_1 , $slotname_2 );
163
- is($xmin , ' ' , ' cascaded slot xmin null with no hs_feedback' );
164
- is($catalog_xmin , ' ' , ' cascaded slot xmin null with no hs_feedback' );
177
+ is($xmin , ' ' , ' xmin of cascaded slot null with no hs_feedback' );
178
+ is($catalog_xmin , ' ' , ' catalog xmin of cascaded slot null with no hs_feedback' );
165
179
166
180
# Replication still works?
167
181
$node_master -> safe_psql(' postgres' , ' CREATE TABLE replayed(val integer);' );
@@ -196,15 +210,18 @@ sub replay_check
196
210
' ALTER SYSTEM SET hot_standby_feedback = on;' );
197
211
$node_standby_2 -> reload;
198
212
replay_check();
199
- sleep (2);
213
+
214
+ wait_slot_xmins($node_master , $slotname_1 ,
215
+ " xmin IS NOT NULL AND catalog_xmin IS NULL" );
200
216
201
217
($xmin , $catalog_xmin ) = get_slot_xmins($node_master , $slotname_1 );
202
- isnt($xmin , ' ' , ' non-cascaded slot xmin non-null with hs feedback' );
203
- is($catalog_xmin , ' ' , ' non-cascaded slot xmin still null with hs_feedback' );
218
+ isnt($xmin , ' ' , ' xmin of non-cascaded slot non-null with hs feedback' );
219
+ is($catalog_xmin , ' ' ,
220
+ ' catalog xmin of non-cascaded slot still null with hs_feedback' );
204
221
205
222
($xmin , $catalog_xmin ) = get_slot_xmins($node_standby_1 , $slotname_2 );
206
- isnt($xmin , ' ' , ' cascaded slot xmin non-null with hs feedback' );
207
- is($catalog_xmin , ' ' , ' cascaded slot xmin still null with hs_feedback' );
223
+ isnt($xmin , ' ' , ' xmin of cascaded slot non-null with hs feedback' );
224
+ is($catalog_xmin , ' ' , ' catalog xmin of cascaded slot still null with hs_feedback' );
208
225
209
226
note " doing some work to advance xmin" ;
210
227
for my $i (10000 .. 11000)
@@ -216,15 +233,15 @@ sub replay_check
216
233
217
234
my ($xmin2 , $catalog_xmin2 ) = get_slot_xmins($node_master , $slotname_1 );
218
235
note " new xmin $xmin2 , old xmin $xmin " ;
219
- isnt($xmin2 , $xmin , ' non-cascaded slot xmin with hs feedback has changed' );
236
+ isnt($xmin2 , $xmin , ' xmin of non-cascaded slot with hs feedback has changed' );
220
237
is($catalog_xmin2 , ' ' ,
221
- ' non-cascaded slot xmin still null with hs_feedback unchanged' );
238
+ ' catalog xmin of non-cascaded slot still null with hs_feedback unchanged' );
222
239
223
240
($xmin2 , $catalog_xmin2 ) = get_slot_xmins($node_standby_1 , $slotname_2 );
224
241
note " new xmin $xmin2 , old xmin $xmin " ;
225
- isnt($xmin2 , $xmin , ' cascaded slot xmin with hs feedback has changed' );
242
+ isnt($xmin2 , $xmin , ' xmin of cascaded slot with hs feedback has changed' );
226
243
is($catalog_xmin2 , ' ' ,
227
- ' cascaded slot xmin still null with hs_feedback unchanged' );
244
+ ' catalog xmin of cascaded slot still null with hs_feedback unchanged' );
228
245
229
246
note " disabling hot_standby_feedback" ;
230
247
@@ -236,16 +253,22 @@ sub replay_check
236
253
' ALTER SYSTEM SET hot_standby_feedback = off;' );
237
254
$node_standby_2 -> reload;
238
255
replay_check();
239
- sleep (2);
256
+
257
+ wait_slot_xmins($node_master , $slotname_1 ,
258
+ " xmin IS NULL AND catalog_xmin IS NULL" );
240
259
241
260
($xmin , $catalog_xmin ) = get_slot_xmins($node_master , $slotname_1 );
242
- is($xmin , ' ' , ' non-cascaded slot xmin null with hs feedback reset' );
261
+ is($xmin , ' ' , ' xmin of non-cascaded slot null with hs feedback reset' );
243
262
is($catalog_xmin , ' ' ,
244
- ' non-cascaded slot xmin still null with hs_feedback reset' );
263
+ ' catalog xmin of non-cascaded slot still null with hs_feedback reset' );
264
+
265
+ wait_slot_xmins($node_standby_1 , $slotname_2 ,
266
+ " xmin IS NULL AND catalog_xmin IS NULL" );
245
267
246
268
($xmin , $catalog_xmin ) = get_slot_xmins($node_standby_1 , $slotname_2 );
247
- is($xmin , ' ' , ' cascaded slot xmin null with hs feedback reset' );
248
- is($catalog_xmin , ' ' , ' cascaded slot xmin still null with hs_feedback reset' );
269
+ is($xmin , ' ' , ' xmin of cascaded slot null with hs feedback reset' );
270
+ is($catalog_xmin , ' ' ,
271
+ ' catalog xmin of cascaded slot still null with hs_feedback reset' );
249
272
250
273
note " re-enabling hot_standby_feedback and disabling while stopped" ;
251
274
$node_standby_2 -> safe_psql(' postgres' ,
@@ -260,11 +283,13 @@ sub replay_check
260
283
$node_standby_2 -> stop;
261
284
262
285
($xmin , $catalog_xmin ) = get_slot_xmins($node_standby_1 , $slotname_2 );
263
- isnt($xmin , ' ' , ' cascaded slot xmin non-null with postgres shut down' );
286
+ isnt($xmin , ' ' , ' xmin of cascaded slot non-null with postgres shut down' );
264
287
265
288
# Xmin from a previous run should be cleared on startup.
266
289
$node_standby_2 -> start;
267
290
291
+ wait_slot_xmins($node_standby_1 , $slotname_2 , " xmin IS NULL" );
292
+
268
293
($xmin , $catalog_xmin ) = get_slot_xmins($node_standby_1 , $slotname_2 );
269
294
is($xmin , ' ' ,
270
- ' cascaded slot xmin reset after startup with hs feedback reset' );
295
+ ' xmin of cascaded slot reset after startup with hs feedback reset' );
0 commit comments