public inbox for [email protected]
help / color / mirror / Atom feedFrom: Zhijie Hou (Fujitsu) <[email protected]>
To: Amit Kapila <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Cc: Fujii Masao <[email protected]>
Subject: RE: Fix slotsync worker busy loop causing repeated log messages
Date: Fri, 10 Apr 2026 10:28:29 +0000
Message-ID: <TYRPR01MB14195D4C2B45E2DC986A3E7B294592@TYRPR01MB14195.jpnprd01.prod.outlook.com> (raw)
In-Reply-To: <CAA4eK1++dGmvReJ4pRw09qdrUED=iUfyiEM-fN03D2VVK1de1A@mail.gmail.com>
References: <CAHGQGwF6zG9Z8ws1yb3hY1VqV-WT7hR0qyXCn2HdbjvZQKufDw@mail.gmail.com>
<CAA4eK1KLk+TWyNPJ=z6SzQQXySc-N9Gs3eR-QKfV+MX7vfJWiw@mail.gmail.com>
<CAHGQGwG1br8SQQnBieyJeRAmnMejEtJrVmurfTPxNouLHSW=jA@mail.gmail.com>
<CAA4eK1KB6geysORVyOh-dJ+9U57CBC30K2XD3fQ6SKZc0Hsi3Q@mail.gmail.com>
<TYRPR01MB14195ED854BE834AFDC815E9494592@TYRPR01MB14195.jpnprd01.prod.outlook.com>
<CAA4eK1++dGmvReJ4pRw09qdrUED=iUfyiEM-fN03D2VVK1de1A@mail.gmail.com>
On Friday, April 10, 2026 5:53 PM Amit Kapila <[email protected]> wrote:
> On Fri, Apr 10, 2026 at 8:28 AM Zhijie Hou (Fujitsu) <[email protected]>
> wrote:
> >
> >
> > Perhaps we could simply compare the slot's old and new LSN/xmin to
> > determine whether updated_xmin_or_lsn needs to be set.
> >
>
> The patch works for me. Can we change the comment to as follows: "It is
> possible that the slot's xmin or LSNs are not updated, when the synced slot
> has reached consistent snapshot state or cannot build the one at all."?
Changed as suggested.
Here are the patches for both HEAD and back branches.
Best Regards,
Hou zj
Attachments:
[application/octet-stream] v4-0001-Fix-slotsync-worker-busy-loop-causing-repeated-lo.patch (2.3K, 2-v4-0001-Fix-slotsync-worker-busy-loop-causing-repeated-lo.patch)
download | inline diff:
From 52c53fa9c2e7648565103aea82650964bff2385c Mon Sep 17 00:00:00 2001
From: Zhijie Hou <[email protected]>
Date: Thu, 9 Apr 2026 20:11:40 +0800
Subject: [PATCH v4] Fix slotsync worker busy loop causing repeated logical
decoding logs.
Previously, the slotsync worker could enter a busy loop and emit four logical
log messages every 200 ms, even when both the primary and standby were idle.
This happened because the worker incorrectly treated certain cases as
successful slot updates, causing it to use the minimum sleep interval and
repeatedly restart slot syncing.
This commit fixes this by ensuring the worker does not treat such cases as
updates, allowing it to sleep normally and avoid excessive log output.
---
src/backend/replication/logical/slotsync.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index f90653e5232..64db2e9fd8c 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -332,10 +332,15 @@ update_local_synced_slot(RemoteSlot *remote_slot, Oid remote_dbid)
slot->data.confirmed_flush = remote_slot->confirmed_lsn;
slot->data.catalog_xmin = remote_slot->catalog_xmin;
SpinLockRelease(&slot->mutex);
+
+ updated_xmin_or_lsn = true;
}
else
{
bool found_consistent_snapshot;
+ XLogRecPtr old_confirmed_lsn = slot->data.confirmed_flush;
+ XLogRecPtr old_restart_lsn = slot->data.restart_lsn;
+ XLogRecPtr old_catalog_xmin = slot->data.catalog_xmin;
LogicalSlotAdvanceAndCheckSnapState(remote_slot->confirmed_lsn,
&found_consistent_snapshot);
@@ -365,9 +370,16 @@ update_local_synced_slot(RemoteSlot *remote_slot, Oid remote_dbid)
skip_reason = SS_SKIP_NO_CONSISTENT_SNAPSHOT;
}
- }
- updated_xmin_or_lsn = true;
+ /*
+ * It is possible that the slot's xmin or LSNs are not updated,
+ * when the synced slot has reached consistent snapshot state or
+ * cannot build one at all.
+ */
+ updated_xmin_or_lsn = (old_confirmed_lsn != slot->data.confirmed_flush ||
+ old_restart_lsn != slot->data.restart_lsn ||
+ old_catalog_xmin != slot->data.catalog_xmin);
+ }
}
/* Update slot sync skip stats */
--
2.31.1
[application/octet-stream] v4_PG17_18-0001-Fix-slotsync-worker-busy-loop-causing-rep.patch (2.3K, 3-v4_PG17_18-0001-Fix-slotsync-worker-busy-loop-causing-rep.patch)
download | inline diff:
From c3744118809796e34faa37640a1e3b428705a8b9 Mon Sep 17 00:00:00 2001
From: Zhijie Hou <[email protected]>
Date: Fri, 10 Apr 2026 16:28:44 +0800
Subject: [PATCH v4_PG17_18] Fix slotsync worker busy loop causing repeated
logical decoding logs.
Previously, the slotsync worker could enter a busy loop and emit four logical
log messages every 200 ms, even when both the primary and standby were idle.
This happened because the worker incorrectly treated certain cases as
successful slot updates, causing it to use the minimum sleep interval and
repeatedly restart slot syncing.
This commit fixes this by ensuring the worker does not treat such cases as
updates, allowing it to sleep normally and avoid excessive log output.
---
src/backend/replication/logical/slotsync.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index 4cbee197ddb..3cbcd77d12f 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -275,9 +275,15 @@ update_local_synced_slot(RemoteSlot *remote_slot, Oid remote_dbid,
if (found_consistent_snapshot)
*found_consistent_snapshot = true;
+
+ updated_xmin_or_lsn = true;
}
else
{
+ XLogRecPtr old_confirmed_lsn = slot->data.confirmed_flush;
+ XLogRecPtr old_restart_lsn = slot->data.restart_lsn;
+ XLogRecPtr old_catalog_xmin = slot->data.catalog_xmin;
+
LogicalSlotAdvanceAndCheckSnapState(remote_slot->confirmed_lsn,
found_consistent_snapshot);
@@ -289,9 +295,16 @@ update_local_synced_slot(RemoteSlot *remote_slot, Oid remote_dbid,
errdetail_internal("Remote slot has LSN %X/%X but local slot has LSN %X/%X.",
LSN_FORMAT_ARGS(remote_slot->confirmed_lsn),
LSN_FORMAT_ARGS(slot->data.confirmed_flush)));
- }
- updated_xmin_or_lsn = true;
+ /*
+ * It is possible that the slot's xmin or LSNs are not updated,
+ * when the synced slot has reached consistent snapshot state or
+ * cannot build one at all.
+ */
+ updated_xmin_or_lsn = (old_confirmed_lsn != slot->data.confirmed_flush ||
+ old_restart_lsn != slot->data.restart_lsn ||
+ old_catalog_xmin != slot->data.catalog_xmin);
+ }
}
if (remote_dbid != slot->data.database ||
--
2.53.0.windows.2
view thread (13+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: RE: Fix slotsync worker busy loop causing repeated log messages
In-Reply-To: <TYRPR01MB14195D4C2B45E2DC986A3E7B294592@TYRPR01MB14195.jpnprd01.prod.outlook.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox