Re: Exit walsender before confirming remote flush in logical replication
Fujii Masao <masao.fujii@gmail.com>
From: Fujii Masao <masao.fujii@gmail.com>
To: Chao Li <li.evan.chao@gmail.com>
Cc: Andres Freund <andres@anarazel.de>,
Andrey Silitskiy <a.silitskiy@postgrespro.ru>, Alexander Korotkov <aekorotkov@gmail.com>,
Greg Sabino Mullane <htamfids@gmail.com>, Japin Li <japinli@hotmail.com>, Ronan Dunklau <ronan@dunklau.fr>, Vitaly Davydov <v.davydov@postgrespro.ru>, "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>, "Takamichi Osumi (Fujitsu)" <osumi.takamichi@fujitsu.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>, "sawada.mshk@gmail.com" <sawada.mshk@gmail.com>,
"michael@paquier.xyz" <michael@paquier.xyz>, "peter.eisentraut@enterprisedb.com" <peter.eisentraut@enterprisedb.com>, "dilipbalaut@gmail.com" <dilipbalaut@gmail.com>,
"amit.kapila16@gmail.com" <amit.kapila16@gmail.com>, Kyotaro Horiguchi <horikyota.ntt@gmail.com>,
Peter Smith <smithpb2250@gmail.com>
Date: 2026-04-23T04:51:53Z
Lists: pgsql-hackers
Attachments
- v1-0001-Avoid-blocking-indefinitely-while-finishing-walse.patch (application/octet-stream) patch v1-0001
On Wed, Apr 22, 2026 at 3:32 AM Fujii Masao <masao.fujii@gmail.com> wrote: > Therefore, since replacing pq_flush() with pq_flush_if_writable() seems to > change behavior only in a limited and acceptable way, I'm thinking to create > the patch doing that replacement. On second thought, replacing pq_flush() with pq_flush_if_writable() is not sufficient. EndCommand(), which WalSndDone() calls before pq_flush(), can also block when the send buffer is full. That happens because EndCommand() uses pq_putmessage() rather than pq_putmessage_noblock(). Also, replacing pq_flush() with pq_flush_if_writable() would cause walsender to give up sending pending messages, including CommandComplete, even before wal_sender_shutdown_timeout expires. That seems a bit odd. I think it is better for walsender to continue honoring wal_sender_shutdown_timeout while attempting to send the final CommandComplete message. I've attached a patch that addresses both issues. For the first, it introduces EndCommandExtended(), which allows CommandComplete to be queued with pq_putmessage_noblock(). For the second, it updates WalSndDone() to use ProcessPendingWrites() instead of pq_flush(), so the walsender write loop can continue processing replies and checking replication and shutdown timeouts while pending output is being flushed. Thoughts? Regards, -- Fujii Masao
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Avoid blocking indefinitely while finishing walsender shutdown
- c0b24b32b0d3 19 (unreleased) landed
-
Add wal_sender_shutdown_timeout GUC to limit shutdown wait for replication
- a8f45dee9176 19 (unreleased) landed
-
pg_upgrade: Add --copy option
- 746915c68669 16.0 cited
-
Prevent possibility of panics during shutdown checkpoint.
- c6c333436491 10.0 cited
-
Support clean switchover.
- 985bd7d49726 9.4.0 cited