Re: Shutdown indefinitely stuck due to unflushed FPI_FOR_HINT record
Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
From: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
To: Fujii Masao <masao.fujii@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@postgresql.org>
Date: 2026-03-02T10:38:06Z
Lists: pgsql-hackers
Attachments
- v3-0001-Fix-stuck-shutdown-due-to-unflushed-records.patch (application/octet-stream) patch v3-0001
On Thu, Feb 26, 2026 at 5:20 PM Fujii Masao <masao.fujii@gmail.com> wrote: > Thanks for reporting this issue and for the patch! > > I was able to reproduce the problem on master. Thanks for the confirmation! > I'm a bit concerned that this approach could cause walwriter to attempt > WAL writes more aggressively in some cases, adding overhead during > normal processing. If the goal is only to prevent shutdown from getting stuck, > instead, would it be sufficient for ShutdownXLOG() to call > XLogSetAsyncXactLSN() just before WalSndWaitStopping()? I did something similar with the first version using XLogFlush(WriteRqstPtr), and it indeed fixes the shutdown issue. Though I was under the impression that calling XLogSetAsyncXactLSN() in RecordTransactionAbort was a better approach, as it is similar to reporting the latest async abort. You may have a large backlog of records, like selects pruning a lot of pages and timing out, which the next commit will have to flush. Notifying the walwriter allows it to flush those records it can. Maybe for the context of a backport, patching ShutdownXLOG has the benefit of minimising the amount of changes and risks? I've updated the RecordTransactionAbort approach for now, with a small optimization. XactLastRecEnd may be 0 if nothing was written, and we can skip the unnecessary spinlocks in this case. Regards, Anthonin Bonnefoy
Commits
-
Fix WAL flush LSN used by logical walsender during shutdown
- f15471464650 14.23 landed
- fa9f2e317562 15.18 landed
- da21ecf5798c 16.14 landed
- 8ee536c89517 17.10 landed
- 9804981386a0 18.4 landed
- d927b4bd97c8 19 (unreleased) landed
-
Use GetXLogInsertEndRecPtr in gistGetFakeLSN
- b1f14c967202 19 (unreleased) cited
-
Fix publisher shutdown hang caused by logical walsender busy loop.
- 3bf6f22ce151 14.23 landed
- 42734f296615 15.18 landed
- 82935467a033 16.14 landed
- bbbc0888b356 17.10 landed
- 3eb2fecdbbfc 18.4 landed
- 6eedb2a5fd88 19 (unreleased) landed