]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix excessive logging in idle slotsync worker.
authorAmit Kapila <akapila@postgresql.org>
Mon, 13 Apr 2026 04:12:51 +0000 (09:42 +0530)
committerAmit Kapila <akapila@postgresql.org>
Mon, 13 Apr 2026 04:12:51 +0000 (09:42 +0530)
The slotsync worker was incorrectly identifying no-op states as successful
updates, triggering a busy loop to sync slots that logged messages every
200ms. This patch corrects the logic to properly classify these states,
enabling the worker to respect normal sleep intervals when no work is
performed.

Reported-by: Fujii Masao <masao.fujii@gmail.com>
Author: Zhijie Hou <houzj.fnst@fujitsu.com>
Reviewed-by: Amit Kapila <amit.kapila16@gmail.com>
Reviewed-by: shveta malik <shveta.malik@gmail.com>
Backpatch-through: 17, where it was introduced
Discussion: https://postgr.es/m/CAHGQGwF6zG9Z8ws1yb3hY1VqV-WT7hR0qyXCn2HdbjvZQKufDw@mail.gmail.com

src/backend/replication/logical/slotsync.c

index 4cbee197ddb9bda01ce738c771c5db5ea9c9af22..3cbcd77d12fe24754df8c0bcee18ec0e34f9c047 100644 (file)
@@ -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 ||