From: Fujii Masao Date: Tue, 3 Feb 2026 02:14:00 +0000 (+0900) Subject: Release synchronous replication waiters immediately on configuration changes. X-Git-Url: http://git.postgresql.org/gitweb/We?a=commitdiff_plain;p=postgresql.git Release synchronous replication waiters immediately on configuration changes. Previously, when synchronous_standby_names was changed (for example, by reducing the number of required synchronous standbys or modifying the standby list), backends waiting for synchronous replication were not released immediately, even if the new configuration no longer required them to wait. They could remain blocked until additional messages arrived from standbys and triggered their release. This commit improves walsender so that backends waiting for synchronous replication are released as soon as the updated configuration takes effect and the new settings no longer require them to wait, by calling SyncRepReleaseWaiters() when configuration changes are processed. As part of this change, the duplicated code that handles configuration changes in walsender has been refactored into a new helper function, which is now used at the three existing call places. Since this is an improvement rather than a bug fix, it is applied only to the master branch. Author: Shinya Kato Reviewed-by: Chao Li Reviewed-by: Fujii Masao Reviewed-by: Xuneng Zhou Discussion: https://postgr.es/m/CAOzEurSRii0tEYhu5cePmRcvS=ZrxTLEvxm3Kj0d7_uKGdM23g@mail.gmail.com --- diff --git a/src/backend/replication/walsender.c b/src/backend/replication/walsender.c index a0e6a3d200c..2cde8ebc729 100644 --- a/src/backend/replication/walsender.c +++ b/src/backend/replication/walsender.c @@ -1611,6 +1611,32 @@ WalSndWriteData(LogicalDecodingContext *ctx, XLogRecPtr lsn, TransactionId xid, ProcessPendingWrites(); } +/* + * Handle configuration reload. + * + * Process the pending configuration file reload and reinitializes synchronous + * replication settings. Also releases any waiters that may now be satisfied due + * to changes in synchronous replication requirements. + */ +static void +WalSndHandleConfigReload(void) +{ + if (!ConfigReloadPending) + return; + + ConfigReloadPending = false; + ProcessConfigFile(PGC_SIGHUP); + SyncRepInitConfig(); + + /* + * Recheck and release any now-satisfied waiters after config reload + * changes synchronous replication requirements (e.g., reducing the number + * of sync standbys or changing the standby names). + */ + if (!am_cascading_walsender) + SyncRepReleaseWaiters(); +} + /* * Wait until there is no pending write. Also process replies from the other * side and check timeouts during that. @@ -1646,12 +1672,7 @@ ProcessPendingWrites(void) CHECK_FOR_INTERRUPTS(); /* Process any requests or signals received recently */ - if (ConfigReloadPending) - { - ConfigReloadPending = false; - ProcessConfigFile(PGC_SIGHUP); - SyncRepInitConfig(); - } + WalSndHandleConfigReload(); /* Try to flush pending output to the client */ if (pq_flush_if_writable() != 0) @@ -1854,12 +1875,7 @@ WalSndWaitForWal(XLogRecPtr loc) CHECK_FOR_INTERRUPTS(); /* Process any requests or signals received recently */ - if (ConfigReloadPending) - { - ConfigReloadPending = false; - ProcessConfigFile(PGC_SIGHUP); - SyncRepInitConfig(); - } + WalSndHandleConfigReload(); /* Check for input from the client */ ProcessRepliesIfAny(); @@ -2899,12 +2915,7 @@ WalSndLoop(WalSndSendDataCallback send_data) CHECK_FOR_INTERRUPTS(); /* Process any requests or signals received recently */ - if (ConfigReloadPending) - { - ConfigReloadPending = false; - ProcessConfigFile(PGC_SIGHUP); - SyncRepInitConfig(); - } + WalSndHandleConfigReload(); /* Check for input from the client */ ProcessRepliesIfAny();