| From: | Nitin Jadhav <nitinjadhavpostgres(at)gmail(dot)com> |
|---|---|
| To: | Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | [PATCH] Check interrupts while draining received WAL |
| Date: | 2026-11-16 08:59:00 |
| Message-ID: | CAMm1aWY-bps8VPCdyTTZo6NZicSRrq0kBArzjKTZoKHdN_wqOA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
Following up on Andres's report [1], the attached patch addresses
delayed SIGTERM processing while the WAL receiver drains continuously
available WAL.
WalReceiverMain() checks interrupts in its outer loop, but not in the
inner loop that processes all immediately available WAL. When the
receiver writes more slowly than the sender supplies WAL, it can
remain in that inner loop with SIGTERM pending. This can delay
receiver termination during server shutdown, promotion, or
reconfiguration. When termination is requested by startup, that
process can remain in ShutdownWalRcv(), visible as the WalReceiverExit
wait event.
The attached patch adds CHECK_FOR_INTERRUPTS() at the start of each
inner loop iteration so that shutdown requests are processed even when
WAL is continuously available.
For local reproduction, I queued approximately 128 MiB of WAL and used
temporary test-only instrumentation to sleep for 10 ms before each
receiver write, following Andres's suggestion [2]. While the receiver
was consuming that backlog, I stopped streaming by clearing
primary_conninfo and reloading on the standby:
ALTER SYSTEM SET primary_conninfo = '';
SELECT pg_reload_conf();
In the unfixed run, the receiver was still present after 5.068 seconds
and startup was waiting in WalReceiverExit. The receiver exited
naturally after 11.055 seconds. With the interrupt check and the same
instrumentation, receiver exit was observed after 0.033 seconds.
The artificial delay was used only for local reproduction and is not
included in the attached patch.
Comments and review would be appreciated
[1] https://www.postgresql.org/message-id/20210511022755.wcb5h4czadxsgewt@alap3.anarazel.de
[2] https://www.postgresql.org/message-id/20210511025940.rkx73zezq3hq3eae@alap3.anarazel.de
Best Regards,
Nitin Jadhav
Microsoft
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Check-interrupts-while-draining-received-WAL.patch | application/octet-stream | 1.1 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | cca5507 | 2026-11-16 08:25:16 | Re: Reduce memory overheads for storing a Memoize tuple |