| From: | Aleksandr Korchak <korchakan(at)gmail(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Cc: | andres(at)anarazel(dot)de |
| Subject: | PANIC at shutdown when a reload changes full_page_writes |
| Date: | 2026-11-25 15:53:13 |
| Message-ID: | CAEBMo=D+fQ6vAw_TOpTQyL4h_+jHo1CMEDEuMzapN79-PsnKEw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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], 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].
[1] https://postgr.es/m/CANwKhkMTkckNSoz0kUYFvaMDA_6g2uuABcvhoowu64e9e+op=A@mail.gmail.com
--
Aleksandr Korchak
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Ignore-SIGHUP-in-checkpointer-after-the-shutdown-.patch | application/octet-stream | 1.7 KB |
| nocfbot-REL_18-v1-0001-Ignore-SIGHUP-in-checkpointer-after-the-shutdown-.patch | application/octet-stream | 1.7 KB |
| nocfbot-REL_19-v1-0001-Ignore-SIGHUP-in-checkpointer-after-the-shutdown-.patch | application/octet-stream | 1.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Matthias van de Meent | 2026-11-25 15:59:47 | Re: [PATCH] Use the table AM relation_size callback in the SQL size functions |
| Previous Message | Greg Sabino Mullane | 2026-11-25 15:46:34 | Re: passwordcheck: Make the user name check case-insensitive |