You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Postgres] Improve handling of "lost" replication slots (#387)
* Add test to reproduce a "lost" replication slot.
* Detect "can no longer access replication slot" error.
* Check replication slot status upfront.
* Limit slot health check based on time, not iterations.
* Fix for invalidation_reason not on pg < 16.
* Skip test on older postgres versions.
* Further tweaks to postgres compatibility fallbacks.
* Remove some version checks.
* Add changeset.
* Resolve todo.
// Switch WAL file. With default settings, each WAL file is around 16MB.
444
+
awaitpool.query(`select pg_switch_wal()`);
445
+
// Checkpoint command forces the old WAL files to be archived/removed.
446
+
awaitpool.query(`checkpoint`);
447
+
// Now check if the slot is still active.
448
+
constslot=pgwireRows(
449
+
awaitcontext.pool.query({
450
+
statement: `select slot_name, wal_status, safe_wal_size, pg_wal_lsn_diff(pg_current_wal_lsn(), restart_lsn) as lag from pg_replication_slots where slot_name = $1`,
451
+
params: [{type: 'varchar',value: slotName}]
452
+
})
453
+
)[0];
454
+
if(slot.wal_status=='lost'){
455
+
break;
456
+
}elseif(i==TRIES-1){
457
+
thrownewError(
458
+
`Could not generate test conditions to expire replication slot. Current status: ${JSONBig.stringify(slot)}`
459
+
);
460
+
}
461
+
}
462
+
463
+
awaitcontext.loadActiveSyncRules();
464
+
465
+
// The error is handled on a higher level, which triggers
0 commit comments