From: Fujii Masao <fujii@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix lost wakeups in logical WAL senders
Date: Wed, 25 Nov 2026 07:16:43 +0000
Message-ID: <E1xW7FD-00000000Ean-1umv@gemulon.postgresql.org> (raw)
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.fujii@gmail.com>
Reviewed-by: Xuneng Zhou <xunengzhou@gmail.com>
Discussion: https://postgr.es/m/mvx5bs7q.33b99c32-67d8-4373-8611-7a8250fb2fd3@we.are.superhuman.com
Backpatch-through: 16
Branch
------
REL_16_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/2161e1732f5a4113f0b21e2dbc9ed0b86fb3e07e
Modified Files
--------------
src/backend/replication/walsender.c | 42 ++++++++++++++++++++++++++++++++-----
1 file changed, 37 insertions(+), 5 deletions(-)
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: fujii@postgresql.org
Subject: Re: pgsql: Fix lost wakeups in logical WAL senders
In-Reply-To: <E1xW7FD-00000000Ean-1umv@gemulon.postgresql.org>
References: <E1xW7FD-00000000Ean-1umv@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox