From 507b0a16b07a51c6bdaee2c9af1088886c4a20f2 Mon Sep 17 00:00:00 2001 From: Ants Aasma Date: Thu, 19 Nov 2026 15:07:44 +0000 Subject: [PATCH REL_19 v2 1/2] Update checkpointer config even during fast checkpoint CheckpointWriteDelay() processed a pending config reload only when the checkpoint was neither fast nor behind schedule. The checkpointer applies synchronous_standby_names (the SYNC_STANDBY_DEFINED flag in shared memory) and full_page_writes on behalf of all processes, so a change of these settings did not take effect until such a checkpoint had finished, which can take minutes. If synchronous replication is enabled during that window, commits are acknowledged without waiting for the standby, and a failover in the window loses them. If it is disabled because the standby is gone, all writing sessions keep waiting until the checkpoint ends. Process a pending reload on every call instead, except during a shutdown or end-of-recovery checkpoint. Those are the checkpoints CreateCheckPoint() treats as shutdown checkpoints, and UpdateFullPageWrites() must not run in the middle of them. During a shutdown checkpoint it writes XLOG_FPW_CHANGE between the REDO point and the checkpoint record, which ends in "PANIC: concurrent write-ahead log activity while database system is shutting down". During an end-of-recovery checkpoint RecoveryInProgress() is still true, so it changes Insert->fullPageWrites without WAL-logging it, and the record is never written afterwards. In both cases the reload is processed after the checkpoint, as before. Config reloads are still not processed while the checkpoint is fsyncing files in ProcessSyncRequests(). Author: Ants Aasma Co-authored-by: Aleksandr Korchak Reported-by: Jeremy Schneider Discussion: https://postgr.es/m/CANwKhkMTkckNSoz0kUYFvaMDA_6g2uuABcvhoowu64e9e+op=A@mail.gmail.com Backpatch-through: 18 --- src/backend/postmaster/checkpointer.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/backend/postmaster/checkpointer.c b/src/backend/postmaster/checkpointer.c index 087120d..9993c15 100644 --- a/src/backend/postmaster/checkpointer.c +++ b/src/backend/postmaster/checkpointer.c @@ -805,6 +805,24 @@ CheckpointWriteDelay(int flags, double progress) if (!AmCheckpointerProcess()) return; + /* + * Apply configuration changes promptly, even during a fast checkpoint or + * one that is behind schedule, so that e.g. a change of + * synchronous_standby_names takes effect without waiting for the + * checkpoint to finish. But not during a shutdown or end-of-recovery + * checkpoint: UpdateFullPageWrites() would either write WAL between the + * REDO point and the shutdown checkpoint record, or, while recovery is + * still in progress, change full_page_writes without WAL-logging it. + */ + if (ConfigReloadPending && + !(flags & (CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_END_OF_RECOVERY))) + { + ConfigReloadPending = false; + ProcessConfigFile(PGC_SIGHUP); + /* update shmem copies of config variables */ + UpdateSharedMemoryConfig(); + } + /* * Perform the usual duties and take a nap, unless we're behind schedule, * in which case we just try to catch up as quickly as possible. @@ -815,14 +833,6 @@ CheckpointWriteDelay(int flags, double progress) !FastCheckpointRequested() && IsCheckpointOnSchedule(progress)) { - if (ConfigReloadPending) - { - ConfigReloadPending = false; - ProcessConfigFile(PGC_SIGHUP); - /* update shmem copies of config variables */ - UpdateSharedMemoryConfig(); - } - AbsorbSyncRequests(); absorb_counter = WRITES_PER_ABSORB; base-commit: 67ad2443f78e4a7ddbefe270aa6bcd06925453d1 -- 2.55.0