|
59 | 59 | is($result, "reserved|t", 'check the catching-up state');
|
60 | 60 |
|
61 | 61 | # Advance WAL by five segments (= 5MB) on primary
|
62 |
| -advance_wal($node_primary, 1); |
| 62 | +$node_primary->advance_wal(1); |
63 | 63 | $node_primary->safe_psql('postgres', "CHECKPOINT;");
|
64 | 64 |
|
65 | 65 | # The slot is always "safe" when fitting max_wal_size
|
|
69 | 69 | is($result, "reserved|t",
|
70 | 70 | 'check that it is safe if WAL fits in max_wal_size');
|
71 | 71 |
|
72 |
| -advance_wal($node_primary, 4); |
| 72 | +$node_primary->advance_wal(4); |
73 | 73 | $node_primary->safe_psql('postgres', "CHECKPOINT;");
|
74 | 74 |
|
75 | 75 | # The slot is always "safe" when max_slot_wal_keep_size is not set
|
|
100 | 100 | is($result, "reserved", 'check that max_slot_wal_keep_size is working');
|
101 | 101 |
|
102 | 102 | # Advance WAL again then checkpoint, reducing remain by 2 MB.
|
103 |
| -advance_wal($node_primary, 2); |
| 103 | +$node_primary->advance_wal(2); |
104 | 104 | $node_primary->safe_psql('postgres', "CHECKPOINT;");
|
105 | 105 |
|
106 | 106 | # The slot is still working
|
|
118 | 118 | $result = $node_primary->safe_psql('postgres',
|
119 | 119 | "ALTER SYSTEM SET wal_keep_size to '8MB'; SELECT pg_reload_conf();");
|
120 | 120 | # Advance WAL again then checkpoint, reducing remain by 6 MB.
|
121 |
| -advance_wal($node_primary, 6); |
| 121 | +$node_primary->advance_wal(6); |
122 | 122 | $result = $node_primary->safe_psql('postgres',
|
123 | 123 | "SELECT wal_status as remain FROM pg_replication_slots WHERE slot_name = 'rep1'"
|
124 | 124 | );
|
|
134 | 134 | $node_standby->stop;
|
135 | 135 |
|
136 | 136 | # Advance WAL again without checkpoint, reducing remain by 6 MB.
|
137 |
| -advance_wal($node_primary, 6); |
| 137 | +$node_primary->advance_wal(6); |
138 | 138 |
|
139 | 139 | # Slot gets into 'reserved' state
|
140 | 140 | $result = $node_primary->safe_psql('postgres',
|
|
145 | 145 | $node_primary->safe_psql('postgres', "CHECKPOINT;");
|
146 | 146 |
|
147 | 147 | # Advance WAL again without checkpoint; remain goes to 0.
|
148 |
| -advance_wal($node_primary, 1); |
| 148 | +$node_primary->advance_wal(1); |
149 | 149 |
|
150 | 150 | # Slot gets into 'unreserved' state and safe_wal_size is negative
|
151 | 151 | $result = $node_primary->safe_psql('postgres',
|
|
174 | 174 |
|
175 | 175 | # Advance WAL again. The slot loses the oldest segment by the next checkpoint
|
176 | 176 | my $logstart = -s $node_primary->logfile;
|
177 |
| -advance_wal($node_primary, 7); |
| 177 | +$node_primary->advance_wal(7); |
178 | 178 |
|
179 | 179 | # Now create another checkpoint and wait until the WARNING is issued
|
180 | 180 | $node_primary->safe_psql('postgres',
|
|
275 | 275 | has_streaming => 1);
|
276 | 276 | $node_standby->append_conf('postgresql.conf', "primary_slot_name = 'rep1'");
|
277 | 277 | $node_standby->start;
|
278 |
| -my @result = |
279 |
| - split( |
280 |
| - '\n', |
281 |
| - $node_primary2->safe_psql( |
282 |
| - 'postgres', |
283 |
| - "CREATE TABLE tt(); |
284 |
| - DROP TABLE tt; |
285 |
| - SELECT pg_switch_wal(); |
286 |
| - CHECKPOINT; |
287 |
| - SELECT 'finished';", |
288 |
| - timeout => $PostgreSQL::Test::Utils::timeout_default)); |
289 |
| -is($result[1], 'finished', 'check if checkpoint command is not blocked'); |
| 278 | +$node_primary2->advance_wal(1); |
| 279 | +$result = $node_primary2->safe_psql( |
| 280 | + 'postgres', |
| 281 | + "CHECKPOINT; SELECT 'finished';", |
| 282 | + timeout => $PostgreSQL::Test::Utils::timeout_default); |
| 283 | +is($result, 'finished', 'check if checkpoint command is not blocked'); |
290 | 284 |
|
291 | 285 | $node_primary2->stop;
|
292 | 286 | $node_standby->stop;
|
|
372 | 366 | # freeze walsender and walreceiver. Slot will still be active, but walreceiver
|
373 | 367 | # won't get anything anymore.
|
374 | 368 | kill 'STOP', $senderpid, $receiverpid;
|
375 |
| -advance_wal($node_primary3, 2); |
| 369 | +$node_primary3->advance_wal(2); |
376 | 370 |
|
377 | 371 | my $msg_logged = 0;
|
378 | 372 | my $max_attempts = $PostgreSQL::Test::Utils::timeout_default;
|
|
418 | 412 | $node_primary3->stop;
|
419 | 413 | $node_standby3->stop;
|
420 | 414 |
|
421 |
| -##################################### |
422 |
| -# Advance WAL of $node by $n segments |
423 |
| -sub advance_wal |
424 |
| -{ |
425 |
| - my ($node, $n) = @_; |
426 |
| - |
427 |
| - # Advance by $n segments (= (wal_segment_size * $n) bytes) on primary. |
428 |
| - for (my $i = 0; $i < $n; $i++) |
429 |
| - { |
430 |
| - $node->safe_psql('postgres', |
431 |
| - "CREATE TABLE t (); DROP TABLE t; SELECT pg_switch_wal();"); |
432 |
| - } |
433 |
| - return; |
434 |
| -} |
435 |
| - |
436 | 415 | done_testing();
|
0 commit comments