Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c3fb50

Browse files
author
Amit Kapila
committed
Log messages for replication slot acquisition and release.
This commit log messages (at LOG level when log_replication_commands is set, otherwise at DEBUG1 level) when walsenders acquire and release replication slots. These messages help to know the lifetime of a replication slot - one can know how long a streaming standby, logical subscriber, or replication slot consumer is down. These messages will be useful on production servers to debug and analyze inactive replication slots. Note that these messages are emitted only for walsenders but not for backends. This is because walsenders are the ones that typically hold replication slots for longer durations, unlike backends which hold them for executing replication related functions. Author: Bharath Rupireddy Reviewed-by: Peter Smith, Amit Kapila, Alvaro Herrera Discussion: http://postgr.es/m/CALj2ACX17G7F-jeLt+7KhJ6YxVeRwR8Zk0rDh4VnT546o0UpTQ@mail.gmail.com
1 parent 07cb297 commit 7c3fb50

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

doc/src/sgml/config.sgml

+6-5
Original file line numberDiff line numberDiff line change
@@ -7510,11 +7510,12 @@ log_line_prefix = '%m [%p] %q%u@%d/%a '
75107510
</term>
75117511
<listitem>
75127512
<para>
7513-
Causes each replication command to be logged in the server log.
7514-
See <xref linkend="protocol-replication"/> for more information about
7515-
replication command. The default value is <literal>off</literal>.
7516-
Only superusers and users with the appropriate <literal>SET</literal>
7517-
privilege can change this setting.
7513+
Causes each replication command and <literal>walsender</literal>
7514+
process's replication slot acquisition/release to be logged in the
7515+
server log. See <xref linkend="protocol-replication"/> for more
7516+
information about replication command. The default value is
7517+
<literal>off</literal>. Only superusers and users with the appropriate
7518+
<literal>SET</literal> privilege can change this setting.
75187519
</para>
75197520
</listitem>
75207521
</varlistentry>

src/backend/replication/slot.c

+30
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,16 @@ ReplicationSlotAcquire(const char *name, bool nowait)
537537
*/
538538
if (SlotIsLogical(s))
539539
pgstat_acquire_replslot(s);
540+
541+
if (am_walsender)
542+
{
543+
ereport(log_replication_commands ? LOG : DEBUG1,
544+
SlotIsLogical(s)
545+
? errmsg("acquired logical replication slot \"%s\"",
546+
NameStr(s->data.name))
547+
: errmsg("acquired physical replication slot \"%s\"",
548+
NameStr(s->data.name)));
549+
}
540550
}
541551

542552
/*
@@ -549,9 +559,17 @@ void
549559
ReplicationSlotRelease(void)
550560
{
551561
ReplicationSlot *slot = MyReplicationSlot;
562+
char *slotname = NULL; /* keep compiler quiet */
563+
bool is_logical = false; /* keep compiler quiet */
552564

553565
Assert(slot != NULL && slot->active_pid != 0);
554566

567+
if (am_walsender)
568+
{
569+
slotname = pstrdup(NameStr(slot->data.name));
570+
is_logical = SlotIsLogical(slot);
571+
}
572+
555573
if (slot->data.persistency == RS_EPHEMERAL)
556574
{
557575
/*
@@ -596,6 +614,18 @@ ReplicationSlotRelease(void)
596614
MyProc->statusFlags &= ~PROC_IN_LOGICAL_DECODING;
597615
ProcGlobal->statusFlags[MyProc->pgxactoff] = MyProc->statusFlags;
598616
LWLockRelease(ProcArrayLock);
617+
618+
if (am_walsender)
619+
{
620+
ereport(log_replication_commands ? LOG : DEBUG1,
621+
is_logical
622+
? errmsg("released logical replication slot \"%s\"",
623+
slotname)
624+
: errmsg("released physical replication slot \"%s\"",
625+
slotname));
626+
627+
pfree(slotname);
628+
}
599629
}
600630

601631
/*

0 commit comments

Comments
 (0)