diff options
Diffstat (limited to 'src/backend/replication/slot.c')
-rw-r--r-- | src/backend/replication/slot.c | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 2217af70d43..c35ea7c35bf 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -502,6 +502,14 @@ retry: /* We made this slot active, so it's ours now. */ MyReplicationSlot = s; + + /* + * The call to pgstat_acquire_replslot() protects against stats for + * a different slot, from before a restart or such, being present during + * pgstat_report_replslot(). + */ + if (SlotIsLogical(s)) + pgstat_acquire_replslot(s); } /* @@ -746,20 +754,10 @@ ReplicationSlotDropPtr(ReplicationSlot *slot) elog(DEBUG3, "replication slot drop: %s: removed directory", NameStr(slot->data.name)); /* - * Send a message to drop the replication slot to the stats collector. - * Since there is no guarantee of the order of message transfer on a UDP - * connection, it's possible that a message for creating a new slot - * reaches before a message for removing the old slot. We send the drop - * and create messages while holding ReplicationSlotAllocationLock to - * reduce that possibility. If the messages reached in reverse, we would - * lose one statistics update message. But the next update message will - * create the statistics for the replication slot. - * - * XXX In case, the messages for creation and drop slot of the same name - * get lost and create happens before (auto)vacuum cleans up the dead - * slot, the stats will be accumulated into the old slot. One can imagine - * having OIDs for each slot to avoid the accumulation of stats but that - * doesn't seem worth doing as in practice this won't happen frequently. + * Drop the statistics entry for the replication slot. Do this while + * holding ReplicationSlotAllocationLock so that we don't drop a + * statistics entry for another slot with the same name just created in + * another session. */ if (SlotIsLogical(slot)) pgstat_drop_replslot(slot); |