PANIC at shutdown when a reload changes full_page_writes
Thread notes
1 note#bug
hackorum-bot#bug
@global #bug
Hi,
Since 87a6690cc69 ("Change shutdown sequence to terminate checkpointer
last", 18) the checkpointer doesn't exit after ShutdownXLOG(), but
waits for SIGUSR2 in a loop that calls ProcessCheckpointerInterrupts().
A SIGHUP that arrived during the shutdown checkpoint, or later (during
a smart shutdown the postmaster keeps forwarding it), is processed
there. If it changes full_page_writes, UpdateFullPageWrites() tries to
insert XLOG_FPW_CHANGE after CreateCheckPoint() has set
LocalXLogInsertAllowed = 0, inside a critical section, and the
shutdown ends in a PANIC.
Reproducer, with enough dirty buffers for the shutdown checkpoint to
take a few seconds:
$ pg_ctl stop -m smart --no-wait
# while "checkpoint starting: shutdown fast" is in progress
$ echo "full_page_writes = off" >> $PGDATA/postgresql.auto.conf
$ pg_ctl reload
Unpatched master (log shortened, ckpt = checkpointer, pm = postmaster):
34:59.588 ckpt LOG: checkpoint starting: shutdown fast
35:02.650 pm LOG: parameter "full_page_writes" changed to "off"
35:48.998 ckpt LOG: checkpoint complete: shutdown fast: wrote 66679
buffers (25.4%), ...
35:48.999 ckpt PANIC: cannot make new WAL entries during recovery
35:49.157 pm LOG: checkpointer process (PID 83) was terminated by
signal 6: Aborted
#0 UpdateSharedMemoryConfig () at checkpointer.c:1493
#1 ProcessCheckpointerInterrupts () at checkpointer.c:681
#2 CheckpointerMain (...) at checkpointer.c:641
The shutdown checkpoint is already written, so pg_controldata says
"shut down" and the next start doesn't need recovery, but the server
still goes down with a PANIC instead of a clean shutdown. Reproduced
with the commands above on master, and on REL_19_STABLE and
REL_18_STABLE with gdb holding the checkpointer in the shutdown
checkpoint.
The attached patch ignores SIGHUP right after ShutdownXLOG() and drops
a pending reload, since there is nothing left to apply at that point.
With it the same sequence ends cleanly and the next start doesn't need
recovery:
57:24.028 ckpt LOG: checkpoint starting: shutdown fast
57:27.093 pm LOG: parameter "full_page_writes" changed to "off"
58:12.419 ckpt LOG: checkpoint complete: shutdown fast: wrote 66679
buffers (25.4%), ...
58:12.621 pm LOG: database system is shut down
The nocfbot-REL_19-* and nocfbot-REL_18-* files are the same fix for
those branches (REL_18 uses SIG_IGN). On REL_19_STABLE and
REL_18_STABLE it was verified together with the patch from [1]/messages/by-id/CANwKhkMTkckNSoz0kUYFvaMDA_6g2uuABcvhoowu64e9e+op=A@mail.gmail.com, which
doesn't touch this code path. There is no TAP test: once the shutdown
checkpoint starts, no session is left to wake an injection point.
Found while reviewing [1]/messages/by-id/CANwKhkMTkckNSoz0kUYFvaMDA_6g2uuABcvhoowu64e9e+op=A@mail.gmail.com.
[1]: /messages/by-id/CANwKhkMTkckNSoz0kUYFvaMDA_6g2uuABcvhoowu64e9e+op=A@mail.gmail.com
--
Aleksandr Korchak
Attachments:
t259801_1v1-0001-Ignore-SIGHUP-in-checkpointer-after-the-shutdown-.patchapplication/octet-stream; name=v1-0001-Ignore-SIGHUP-in-checkpointer-after-the-shutdown-.patchDownload+3-1
nocfbot-REL_18-v1-0001-Ignore-SIGHUP-in-checkpointer-after-the-shutdown-.patchapplication/octet-stream; name=nocfbot-REL_18-v1-0001-Ignore-SIGHUP-in-checkpointer-after-the-shutdown-.patchDownload+3-1
nocfbot-REL_19-v1-0001-Ignore-SIGHUP-in-checkpointer-after-the-shutdown-.patchapplication/octet-stream; name=nocfbot-REL_19-v1-0001-Ignore-SIGHUP-in-checkpointer-after-the-shutdown-.patchDownload+3-1
On Wed, Nov 25, 2026 at 05:53:13PM +0200, Aleksandr Korchak wrote:
Since 87a6690cc69 ("Change shutdown sequence to terminate checkpointer
last", 18) the checkpointer doesn't exit after ShutdownXLOG(), but
waits for SIGUSR2 in a loop that calls ProcessCheckpointerInterrupts().
A SIGHUP that arrived during the shutdown checkpoint, or later (during
a smart shutdown the postmaster keeps forwarding it), is processed
there. If it changes full_page_writes, UpdateFullPageWrites() tries to
insert XLOG_FPW_CHANGE after CreateCheckPoint() has set
LocalXLogInsertAllowed = 0, inside a critical section, and the
shutdown ends in a PANIC.[...]
The shutdown checkpoint is already written, so pg_controldata says
"shut down" and the next start doesn't need recovery, but the server
still goes down with a PANIC instead of a clean shutdown. Reproduced
with the commands above on master, and on REL_19_STABLE and
REL_18_STABLE with gdb holding the checkpointer in the shutdown
checkpoint.
It sounds like even if this scenario did occur in practice (which seems
highly unlikely), the only bad effect is the exit code. If that
characterization is true, I'm not sure we need to worry about fixing it.
IMO we have bigger fish to fry.
--
nathan