diff --git a/src/backend/replication/logical/logical.c b/src/backend/replication/logical/logical.c index 124bb63..8417790 100644 --- a/src/backend/replication/logical/logical.c +++ b/src/backend/replication/logical/logical.c @@ -228,7 +228,7 @@ CreateInitDecodingContext(char *plugin, elog(ERROR, "cannot initialize logical decoding without a specified plugin"); /* Make sure the passed slot is suitable. These are user facing errors. */ - if (slot->data.database == InvalidOid) + if (SlotIsPhysical(slot)) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), errmsg("cannot use physical replication slot for logical decoding"))); @@ -332,7 +332,7 @@ CreateDecodingContext(XLogRecPtr start_lsn, elog(ERROR, "cannot perform logical decoding without an acquired slot"); /* make sure the passed slot is suitable, these are user facing errors */ - if (slot->data.database == InvalidOid) + if (SlotIsPhysical(slot)) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), (errmsg("cannot use physical replication slot for logical decoding")))); diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index eacf519..079dd3f 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -693,7 +693,7 @@ ReplicationSlotsComputeLogicalRestartLSN(void) continue; /* we're only interested in logical slots */ - if (s->data.database == InvalidOid) + if (!SlotIsLogical(s)) continue; /* read once, it's ok if it increases while we're checking */ @@ -740,8 +740,8 @@ ReplicationSlotsCountDBSlots(Oid dboid, int *nslots, int *nactive) if (!s->in_use) continue; - /* not database specific, skip */ - if (s->data.database == InvalidOid) + /* not database specific logical slot, skip */ + if (!SlotIsLogical(s)) continue; /* not our database, skip */ @@ -819,7 +819,7 @@ ReplicationSlotRegisterRestartLSN() * needed for physical replication slots, as they rely on the snapshot * created by checkpoint when the base backup starts. */ - if (slot->data.database != InvalidOid) + if (SlotIsLogical(slot)) { /* make sure we have enough information to start */ flushptr = LogStandbySnapshot(); diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index eb1b89b..e1bab07 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -514,7 +514,7 @@ StartReplication(StartReplicationCmd *cmd) if (cmd->slotname) { ReplicationSlotAcquire(cmd->slotname); - if (MyReplicationSlot->data.database != InvalidOid) + if (SlotIsLogical(MyReplicationSlot)) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), (errmsg("cannot use a logical replication slot for physical replication")))); @@ -1564,7 +1564,7 @@ ProcessStandbyReplyMessage(void) */ if (MyReplicationSlot && flushPtr != InvalidXLogRecPtr) { - if (MyReplicationSlot->data.database != InvalidOid) + if (SlotIsLogical(MyReplicationSlot)) LogicalConfirmReceivedLocation(flushPtr); else PhysicalConfirmReceivedLocation(flushPtr); diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h index 2bafe62..0237b6b 100644 --- a/src/include/replication/slot.h +++ b/src/include/replication/slot.h @@ -125,6 +125,10 @@ typedef struct ReplicationSlot XLogRecPtr candidate_restart_lsn; } ReplicationSlot; + +#define SlotIsPhysical(slot) (slot->data.database == InvalidOid) +#define SlotIsLogical(slot) (slot->data.database != InvalidOid) + /* * Shared memory control area for all of replication slots. */