| From: | Aleksandr Korchak <korchakan(at)gmail(dot)com> |
|---|---|
| To: | Ants Aasma <ants(dot)aasma(at)cybertec(dot)at> |
| Cc: | Jeremy Schneider <schneider(at)ardentperf(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: sync_standbys_defined and pg_stat_replication |
| Date: | 2026-11-25 16:05:40 |
| Message-ID: | CAEBMo=D+WjSUX=PzXn0eq2Rnb=aespUVrrFvhjzduw1YWuv9nQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Wed, 8 Oct 2025 at 20:38, Ants Aasma <ants(dot)aasma(at)cybertec(dot)at> wrote:
> For the config update getting delayed the fix seems simple - just do
> the config update unconditionally. Patch attached.
Hi,
We're moving to two-node clusters (primary + one synchronous standby)
and need to know the moment commits start waiting for the standby
after synchronous_standby_names is set, which is what Jeremy asked at
the start of this thread (see also [1]). Today that moment can be
delayed by the whole duration of a fast or behind-schedule checkpoint.
I reviewed and tested v1 on master, REL_19_STABLE and REL_18_STABLE.
It removes the delay, but it also processes the reload during shutdown
and end-of-recovery checkpoints, where UpdateFullPageWrites() must not
run:
- a reload that changes full_page_writes during a shutdown checkpoint
writes XLOG_FPW_CHANGE between the REDO point and the checkpoint
record, the shutdown ends in "PANIC: concurrent write-ahead log
activity while database system is shutting down", and the next start
runs crash recovery;
- the same reload during the end-of-recovery checkpoint changes
full_page_writes while RecoveryInProgress() is still true, so
XLOG_FPW_CHANGE is never written, and a standby replaying this WAL
never advances lastFpwDisableRecPtr.
v2 is attached:
0001 v1 plus one condition: the reload is not processed during the
checkpoints that CreateCheckPoint() treats as shutdown
checkpoints,
!(flags & (CHECKPOINT_IS_SHUTDOWN | CHECKPOINT_END_OF_RECOVERY))
There the reload is processed after the checkpoint, as today.
Checking ShutdownXLOGPending instead is not enough: it is false
during the end-of-recovery checkpoint.
0002 injection point "checkpoint-write-delay" at the end of
CheckpointWriteDelay() and TAP test
recovery/062_checkpoint_config_reload.pl. It fails without 0001
(times out waiting for the checkpointer to apply the change) and
passes with it.
The nocfbot-REL_19-* and nocfbot-REL_18-* files are the same series
for those branches; REL_18 uses CHECKPOINT_IMMEDIATE and
ImmediateCheckpointRequested(). The deferral itself is much older than
18, but I only tested 18 and later.
While testing I also found a pre-existing PANIC in 18 and later when a
reload arrives after the shutdown checkpoint. It doesn't depend on
this patch and is reported separately:
https://postgr.es/m/CAEBMo=D+fQ6vAw_TOpTQyL4h_+jHo1CMEDEuMzapN79-PsnKEw@mail.gmail.com
Results
-------
master 4280abf88409, REL_19_STABLE 67ad2443f78e and REL_18_STABLE
75829f043992, cassert builds, one primary and one streaming standby
(down in these scenarios). To keep a checkpoint ~50 s in BufferSync():
66,679 dirty buffers in 2GB of shared_buffers, debug_io_direct = data,
and the data directory on a device throttled to 20 MB/s. "Effect" is
the time from pg_reload_conf() until sessions see the change.
without fix with v2 (*)
master REL_19 REL_18 master REL_19 REL_18
1a enable s_s_n during 51.2 s 57.6 s 58.6 s 31 ms 25 ms 47 ms
CHECKPOINT
commits acknowledged 424 477 487 0 0 0
without the standby
1b disable s_s_n 49.5 s 51.9 s 57.3 s 14 ms 15 ms 43 ms
during CHECKPOINT
1c enable s_s_n during 31.3 s - - 7 ms - -
a WAL checkpoint
behind schedule
commits acknowledged 247 - - 0 - -
TAP test 062 fail fail fail pass pass pass
(*) On REL_19 and REL_18 measured with the separately reported fix
applied as well; it is not on this path.
Without the fix (master, 1a) the change is applied 1 ms after
"checkpoint complete":
15:17.473 pm LOG: parameter "synchronous_standby_names" changed
to "*"
16:08.593 ckpt LOG: checkpoint complete: fast force wait: ...
write=56.168 s, sync=0.004 s, total=56.216 s
16:08.594 ckpt DEBUG: checkpointer updated shared memory
configuration values
With v2, 14 ms after pg_reload_conf() and 57 s before the checkpoint
completes:
30:00.358 pm LOG: parameter "synchronous_standby_names" changed
to "*"
30:00.360 ckpt DEBUG: checkpointer updated shared memory
configuration values
30:57.502 ckpt LOG: checkpoint complete: fast force wait: ...
v1 at shutdown (pg_ctl stop -m smart, then a reload that sets
full_page_writes = off during the shutdown checkpoint), pg_waldump:
0/29E3F588 FPW_CHANGE false
0/29E3F5A8 CHECKPOINT_SHUTDOWN redo 0/29E3F588; ... fpw true; ...
followed by the PANIC above. v1 at the end of crash recovery, same
reload during the end-of-recovery checkpoint:
0/29E391A8 CHECKPOINT_SHUTDOWN redo 0/29E391A8; ... fpw true; ...
0/29E392C8 CHECKPOINT_REDO wal_level replica; checksums on
0/29E39328 CHECKPOINT_ONLINE redo 0/29E392C8; ... fpw false; ...
With v2, as on unpatched master, the shutdown checkpoint completes
normally, and after crash recovery FPW_CHANGE false is written right
after the end-of-recovery checkpoint.
Known limitation
----------------
CheckpointWriteDelay() is not called from ProcessSyncRequests(), so
the change still waits while the checkpoint fsyncs. Without
debug_io_direct, where the checkpoint had write=0.5 s and sync=26 s,
master, v1 and v2 all applied synchronous_standby_names 21.5 s after
the reload, together with "checkpoint complete", and acknowledged
172-178 commits without the standby. v2 shrinks the window to the
fsync phase but doesn't close it. I'd leave that to a separate patch.
Regression tests, with this series and the separately reported fix
applied: on master, full meson test passed (391 ok, 0 fail); on
REL_19_STABLE and REL_18_STABLE, meson test --suite recovery passed
(59 and 54 ok). Those runs were on the commits listed above; since
then the series was only rebased (the test moved from 061 to 062), and
it applies with git am to today's heads of all three branches.
Server logs, gdb traces, pg_waldump output and the scripts for every
scenario are available if anyone wants them.
[1] https://github.com/cloudnative-pg/cloudnative-pg/issues/8790
--
Aleksandr Korchak
| Attachment | Content-Type | Size |
|---|---|---|
| nocfbot-REL_19-v2-0002-Add-test-for-config-reload-during-a-fast-checkpoi.patch | application/octet-stream | 5.2 KB |
| v2-0001-Update-checkpointer-config-even-during-fast-check.patch | application/octet-stream | 3.7 KB |
| nocfbot-REL_19-v2-0001-Update-checkpointer-config-even-during-fast-check.patch | application/octet-stream | 3.7 KB |
| nocfbot-REL_18-v2-0001-Update-checkpointer-config-even-during-immediate-.patch | application/octet-stream | 3.7 KB |
| nocfbot-REL_18-v2-0002-Add-test-for-config-reload-during-an-immediate-ch.patch | application/octet-stream | 5.2 KB |
| v2-0002-Add-test-for-config-reload-during-a-fast-checkpoi.patch | application/octet-stream | 5.2 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Eisentraut | 2026-11-25 16:22:06 | Re: Let OpenSSL auto-select DH parameters by default |
| Previous 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 |