pgsql: Fix lost wakeups in logical WAL senders

From: Fujii Masao <fujii(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix lost wakeups in logical WAL senders
Date: 2026-11-25 07:16:43
Message-ID: E1xW7FD-00000000Eai-1hkN@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix lost wakeups in logical WAL senders

Logical WAL senders could sleep even when WAL was available for
decoding, delaying logical replication until another event woke them.
When synchronous logical replication is configured, this could also
delay commits waiting for acknowledgment from the subscriber.

Commit bc971f4025c changed WAL sender wakeups to use condition
variables, which notify only senders already on the waitlist.
However, WalSndWaitForWal() checks the flush position on a primary,
or the replay position on a standby, before WalSndWait() joins the
waitlist. If the required WAL becomes available between these two
steps, the wakeup can be missed, leaving the sender asleep despite
having enough WAL to continue decoding.

Fix this by passing the required WAL position to WalSndWait() and
rechecking the flush or replay position after joining the waitlist.
If enough WAL is available, return to WalSndWaitForWal() to reevaluate
its conditions, including any need to wait for standby confirmation.
This allows decoding to proceed without waiting for another wakeup
when the required WAL became available before waitlist registration,
avoiding the resulting replication and synchronous commit delays.

Backpatch to v16, where commit bc971f4025c introduced the
condition-variable wakeup mechanism.

Author: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Reviewed-by: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Discussion: https://postgr.es/m/mvx5bs7q.33b99c32-67d8-4373-8611-7a8250fb2fd3@we.are.superhuman.com
Backpatch-through: 16

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/fc1dbe144d265f61bab632b1ea8aec598f68780a

Modified Files
--------------
src/backend/replication/walsender.c | 41 ++++++++++++++++++++++++++++++++-----
1 file changed, 36 insertions(+), 5 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2026-11-25 07:23:40 pgsql: pg_receivewal, pg_basebackup: Fix temporary file cleanup on erro
Previous Message Michael Paquier 2026-11-25 04:31:19 pgsql: Add more tests for backend statistics