diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index f012e99c9d7..d7fb9f5a67f 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -788,44 +788,46 @@ ReplicationSlotRelease(void) */ ReplicationSlotDropAcquired(is_logical); } - - /* - * If slot needed to temporarily restrain both data and catalog xmin to - * create the catalog snapshot, remove that temporary constraint. - * Snapshots can only be exported while the initial snapshot is still - * acquired. - */ - if (!TransactionIdIsValid(slot->data.xmin) && - TransactionIdIsValid(slot->effective_xmin)) - { - SpinLockAcquire(&slot->mutex); - slot->effective_xmin = InvalidTransactionId; - SpinLockRelease(&slot->mutex); - ReplicationSlotsComputeRequiredXmin(false); - } - - /* - * Set the time since the slot has become inactive. We get the current - * time beforehand to avoid system call while holding the spinlock. - */ - now = GetCurrentTimestamp(); - - if (slot->data.persistency == RS_PERSISTENT) + else { /* - * Mark persistent slot inactive. We're not freeing it, just - * disconnecting, but wake up others that may be waiting for it. + * If slot needed to temporarily restrain both data and catalog xmin + * to create the catalog snapshot, remove that temporary constraint. + * Snapshots can only be exported while the initial snapshot is still + * acquired. */ - SpinLockAcquire(&slot->mutex); - slot->active_proc = INVALID_PROC_NUMBER; - ReplicationSlotSetInactiveSince(slot, now, false); - SpinLockRelease(&slot->mutex); - ConditionVariableBroadcast(&slot->active_cv); - } - else - ReplicationSlotSetInactiveSince(slot, now, true); + if (!TransactionIdIsValid(slot->data.xmin) && + TransactionIdIsValid(slot->effective_xmin)) + { + SpinLockAcquire(&slot->mutex); + slot->effective_xmin = InvalidTransactionId; + SpinLockRelease(&slot->mutex); + ReplicationSlotsComputeRequiredXmin(false); + } - MyReplicationSlot = NULL; + /* + * Set the time since the slot has become inactive. We get the current + * time beforehand to avoid system call while holding the spinlock. + */ + now = GetCurrentTimestamp(); + + if (slot->data.persistency == RS_PERSISTENT) + { + /* + * Mark persistent slot inactive. We're not freeing it, just + * disconnecting, but wake up others that may be waiting for it. + */ + SpinLockAcquire(&slot->mutex); + slot->active_proc = INVALID_PROC_NUMBER; + ReplicationSlotSetInactiveSince(slot, now, false); + SpinLockRelease(&slot->mutex); + ConditionVariableBroadcast(&slot->active_cv); + } + else + ReplicationSlotSetInactiveSince(slot, now, true); + + MyReplicationSlot = NULL; + } /* might not have been set when we've been a plain slot */ LWLockAcquire(ProcArrayLock, LW_EXCLUSIVE);