From: Amit Kapila Date: Mon, 13 Apr 2026 04:36:50 +0000 (+0530) Subject: Fix excessive logging in idle slotsync worker. X-Git-Tag: REL_19_BETA1~347 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=85c17f6;p=thirdparty%2Fpostgresql.git Fix excessive logging in idle slotsync worker. 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 Author: Zhijie Hou Reviewed-by: Amit Kapila Reviewed-by: shveta malik Backpatch-through: 17, where it was introduced Discussion: https://postgr.es/m/CAHGQGwF6zG9Z8ws1yb3hY1VqV-WT7hR0qyXCn2HdbjvZQKufDw@mail.gmail.com --- diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c index 2b1c5cf50d2..d01b401cd28 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 */