Skip to content

Commit 2f7b5f0

Browse files
committed
Remove some version checks.
1 parent bd7e7c3 commit 2f7b5f0

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

modules/module-postgres/src/replication/WalStream.ts

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,9 @@ export class WalStream {
297297
// Check if replication slot exists
298298
const slot = pgwire.pgwireRows(
299299
await this.connections.pool.query({
300-
statement: await this.getSlotQuery(),
300+
// We specifically want wal_status and invalidation_reason, but it's not available on older versions,
301+
// so we just query *.
302+
statement: 'SELECT * FROM pg_replication_slots WHERE slot_name = $1',
301303
params: [{ type: 'varchar', value: slotName }]
302304
})
303305
)[0];
@@ -332,8 +334,10 @@ export class WalStream {
332334
* If a replication slot exists, check that it is healthy.
333335
*/
334336
private async checkReplicationSlot(slot: {
335-
wal_status: string;
336-
invalidation_reason: string | null;
337+
// postgres 13+
338+
wal_status?: string;
339+
// postgres 17+
340+
invalidation_reason?: string | null;
337341
}): Promise<{ needsNewSlot: boolean }> {
338342
// Start with a placeholder error, should be replaced if there is an actual issue.
339343
let last_error = new ReplicationAssertionError(`Slot health check failed to execute`);
@@ -342,7 +346,9 @@ export class WalStream {
342346

343347
const lost = slot.wal_status == 'lost';
344348
if (lost) {
345-
this.logger.warn(`Replication slot ${slotName} is invalidated. invalidation_reason: ${slot.invalidation_reason}`);
349+
this.logger.warn(
350+
`Replication slot ${slotName} is invalidated. invalidation_reason: ${slot.invalidation_reason ?? 'unknown'}`
351+
);
346352
return {
347353
needsNewSlot: true
348354
};
@@ -1154,21 +1160,6 @@ WHERE oid = $1::regclass`,
11541160
return version ? version.compareMain('14.0.0') >= 0 : false;
11551161
}
11561162

1157-
/**
1158-
* The pg_replication_slots definition added new debugging features in postgres 13 and in 17, so we selectively use that.
1159-
*/
1160-
protected async getSlotQuery() {
1161-
const version = await this.connections.getServerVersion();
1162-
1163-
if (version!.compareMain('17.0.0') >= 0) {
1164-
return `SELECT wal_status, invalidation_reason FROM pg_replication_slots WHERE slot_name = $1`;
1165-
} else if (version!.compareMain('13.0.0') >= 0) {
1166-
return `SELECT wal_status, 'unknown' as invalidation_reason FROM pg_replication_slots WHERE slot_name = $1`;
1167-
} else {
1168-
return `SELECT 'unknown' as wal_status, 'unknown' as invalidation_reason FROM pg_replication_slots WHERE slot_name = $1`;
1169-
}
1170-
}
1171-
11721163
async getReplicationLagMillis(): Promise<number | undefined> {
11731164
if (this.oldestUncommittedChange == null) {
11741165
if (this.isStartingReplication) {

0 commit comments

Comments
 (0)