From ddfe0a371599bc7bf9af6ba2e7dfad04673fb372 Mon Sep 17 00:00:00 2001 From: Bharath Rupireddy Date: Tue, 28 Dec 2021 06:53:16 +0000 Subject: [PATCH v2] Add LOG messages when replication slots become active and inactive These logs will be extremely useful on production servers to debug and analyze inactive replication slot issues. --- src/backend/replication/slot.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/backend/replication/slot.c b/src/backend/replication/slot.c index 90ba9b417d..2fdb60927f 100644 --- a/src/backend/replication/slot.c +++ b/src/backend/replication/slot.c @@ -337,6 +337,13 @@ ReplicationSlotCreate(const char *name, bool db_specific, /* Let everybody know we've modified this slot */ ConditionVariableBroadcast(&slot->active_cv); + + ereport(LOG, + (errmsg("created %s %s replication slot \"%s\"", + (slot->data.persistency == RS_TEMPORARY ? "temporary" : "persistent"), + (SlotIsPhysical(slot) ? "physical" : "logical"), + NameStr(slot->data.name)), + errhidestmt(true))); } /* @@ -457,6 +464,13 @@ retry: /* We made this slot active, so it's ours now. */ MyReplicationSlot = s; + + ereport(LOG, + (errmsg("acquired %s %s replication slot \"%s\"", + (s->data.persistency == RS_TEMPORARY ? "temporary" : "persistent"), + (SlotIsPhysical(s) ? "physical" : "logical"), + NameStr(s->data.name)), + errhidestmt(true))); } /* @@ -516,6 +530,13 @@ ReplicationSlotRelease(void) MyProc->statusFlags &= ~PROC_IN_LOGICAL_DECODING; ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags; LWLockRelease(ProcArrayLock); + + ereport(LOG, + (errmsg("released %s %s replication slot \"%s\"", + (slot->data.persistency == RS_TEMPORARY ? "temporary" : "persistent"), + (SlotIsPhysical(slot) ? "physical" : "logical"), + NameStr(slot->data.name)), + errhidestmt(true))); } /* @@ -700,6 +721,13 @@ ReplicationSlotDropPtr(ReplicationSlot *slot) * a slot while we're still cleaning up the detritus of the old one. */ LWLockRelease(ReplicationSlotAllocationLock); + + ereport(LOG, + (errmsg("dropped %s %s replication slot \"%s\"", + (slot->data.persistency == RS_TEMPORARY ? "temporary" : "persistent"), + (SlotIsPhysical(slot) ? "physical" : "logical"), + NameStr(slot->data.name)), + errhidestmt(true))); } /* -- 2.25.1