From f5a0a11649aea97c420c4eaf3b7ab0a12b5bb05e Mon Sep 17 00:00:00 2001
From: Nisha Moond <nisha.moond412@gmail.com>
Date: Mon, 18 Nov 2024 11:27:18 +0530
Subject: [PATCH v1] Clarify description of `inactive_since` field

Updated the `inactive_since` field description to specify that it
represents the point in time when a slot became inactive, rather
than the duration of deactivation.
---
 doc/src/sgml/system-views.sgml             | 24 ++++++++++++----------
 src/backend/replication/logical/slotsync.c |  2 +-
 src/include/replication/slot.h             |  6 +++++-
 3 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/doc/src/sgml/system-views.sgml b/doc/src/sgml/system-views.sgml
index 61d28e701f..a586156614 100644
--- a/doc/src/sgml/system-views.sgml
+++ b/doc/src/sgml/system-views.sgml
@@ -2435,7 +2435,7 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
        <structfield>active</structfield> <type>bool</type>
       </para>
       <para>
-       True if this slot is currently actively being used
+       True if this slot is currently being streamed
       </para></entry>
      </row>
 
@@ -2444,9 +2444,8 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
        <structfield>active_pid</structfield> <type>int4</type>
       </para>
       <para>
-       The process ID of the session using this slot if the slot
-       is currently actively being used. <literal>NULL</literal> if
-       inactive.
+       The process ID of the session streaming data for this slot.
+       <literal>NULL</literal> if inactive.
       </para></entry>
      </row>
 
@@ -2566,15 +2565,18 @@ SELECT * FROM pg_locks pl LEFT JOIN pg_prepared_xacts ppx
        <structfield>inactive_since</structfield> <type>timestamptz</type>
       </para>
       <para>
-        The time since the slot has become inactive.
-        <literal>NULL</literal> if the slot is currently being used.
+        The time when the slot became inactive. <literal>NULL</literal> if the
+        slot is currently being streamed.
         Note that for slots on the standby that are being synced from a
         primary server (whose <structfield>synced</structfield> field is
-        <literal>true</literal>), the
-        <structfield>inactive_since</structfield> indicates the last
-        synchronization (see
-        <xref linkend="logicaldecoding-replication-slots-synchronization"/>)
-        time.
+        <literal>true</literal>), the <structfield>inactive_since</structfield>
+        indicates the time when slot synchronization (see <xref
+        linkend="logicaldecoding-replication-slots-synchronization"/>)
+        was most recently stopped.  <literal>NULL</literal> if the slot
+        has always been synchronized. On standby, this is useful for slots
+        that are being synced from a primary server (whose
+        <structfield>synced</structfield> field is <literal>true</literal>)
+        so they know when the slot stopped being synchronized.
       </para></entry>
      </row>
 
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index d62186a510..f4f80b2312 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -1515,7 +1515,7 @@ update_synced_slots_inactive_since(void)
 	 * correctly interpret the inactive_since if the standby gets promoted
 	 * without a restart. We don't want the slots to appear inactive for a
 	 * long time after promotion if they haven't been synchronized recently.
-	 * Whoever acquires the slot i.e.makes the slot active will reset it.
+	 * Whoever acquires the slot, i.e., makes the slot active, will reset it.
 	 */
 	if (!StandbyMode)
 		return;
diff --git a/src/include/replication/slot.h b/src/include/replication/slot.h
index 45582cf9d8..d2cf786fd5 100644
--- a/src/include/replication/slot.h
+++ b/src/include/replication/slot.h
@@ -205,7 +205,11 @@ typedef struct ReplicationSlot
 	 */
 	XLogRecPtr	last_saved_confirmed_flush;
 
-	/* The time since the slot has become inactive */
+	/*
+	 * The time when the slot became inactive. For synced slots on a standby
+	 * server, it represents the time when slot synchronization was most
+	 * recently stopped.
+	 */
 	TimestampTz inactive_since;
 } ReplicationSlot;
 
-- 
2.34.1

