| From: | Tomas Vondra <tomas(at)vondra(dot)me> |
|---|---|
| To: | Rui Zhao <zhaorui126(at)gmail(dot)com> |
| Cc: | Daniel Gustafsson <daniel(at)yesql(dot)se>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com>, Ewan Young <kdbase(dot)hack(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Re: allow spread checkpoints when changing checksums online |
| Date: | 2026-11-23 16:14:25 |
| Message-ID: | 2884ed82-aa83-4fe1-a170-e9e7af989adb@vondra.me |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
Here's a v6, merely rebased on current master, with no changes on top of
v5 posted back in July.
But while looking at it with fresh eyes (and based on an AI review), I
do have a bunch of questions / possible issues.
1) Should we still stick to "fast = true" default?
One of the reasons why the patch adopted the "fast = true" default was
that it was consistent with the behavior committed in REL_19_STABLE. But
that's no longer true after the revert, so maybe we should reconsider
that. I actually think most people will want to pace this in order to
not disrupt user queries, so "fast = false" seems better to me.
Of course, as pointed out in [1], we can't just change the default and
be done with it. We'd need to change also the default cost/delay values,
so that the reads/writes are paced too (even though an immediate
checkpoint is probably much more disruptive, but who knows).
I suppose we could adopt the autovacuum defaults. That was the model for
these values anyway. In fact, maybe we could default to -1 and make it
mean "use autovacuum parameters". We're calling the Vacuum stuff anyway,
but maybe we should keep the limits separate.
The AI review also found three issues - I think all of them are real and
valid, although probably not blockers. Some are preexisting, and the
spread checkpoints just increase the window.
2) A canceled enable can undo its retry.
In datachecksum_state.c, the launcher is marked as stopped before
launcher_exit() rolls back the transition. A second launcher may start
in between these two points, enabling checksums (spread checkpoints make
this pre-existing race much longer, but it's not new).
When this happens, the old launcher sets the state to off. Then the
retry logs data checksums are enabled, but SHOW data_checksums returns
off. Because that transition was undone by the old launcher exit.
The timing is quite finicky, and this is a simplified explanation.
Maybe this is OK. It just means that conflicting requests may end up
with an arbitrary (correct) outcome.
3) A repeated request can be ignored before the next checkpoint.
The launcher reads a copy of fast that the worker refreshes between
relations. Changing true to false while the last database's worker waits
for a temporary table still produces checkpoint starting: fast force
wait. But "disable" has no worker: changing false to true (to use spread
checkpoints) during its first checkpoint leaves the second checkpoint
spread too.
So maybe the right solution would be to read the currently requested
mode (with the proper locking) when issuing each new checkpoint?
That means it would not be checked in DataChecksumsWorkerMain() when
recalculating VacuumUpdateCosts(). So we would not recalculate the
worker's vacuum buffer strategy when only fast changes, which seems like
a good thing? In fact, the worker is not requesting checkpoints, so why
should it be responsible for propagating the flag?
Of course, I don't expect people to alternate between fast and spread
checkpoints very often. But I can imagine someone initiating enabling
checksums, with throttled writes, and then realizing the checkpoints are
still going to be fast=true. If I simply cancel the enable, I don't want
it to still do a fast checkpoint at the end. I want even the cancel to
be with a spread checkpoint. Or even better, I'd like to just update the
flag in shared memory, and let the current enable continue.
4) Fast server shutdown waits for spread rollback checkpoints.
In v6 all the places requesting checkpoints honor the fast_checkpoint
flags. Which however applies to launcher_exit() too. That means that a
fast server shutdown may wait for a spread checkpoint during rollback.
The postmaster won't be able to request its own shutdown checkpoint
until the launcher exits.
It'd be better to use fast rollback checkpoints when the server is
shutting down, but how would we know in launcher_exit()? I'm not quite
sure if we can whether launcher_exit() is called during rollback or
shutdown, or what. I'm a bit confused about the abort_requested flag,
but even that may be insufficient ...
In fact, I wonder if the launcher should be responsible for triggering
the checkpoints at all. As mentioned, if launcher_exit starts a spread
checkpoint, the postmaster can't do anything but wait. So maybe this
could be delegated to some other process?
regards
[1]
https://www.postgresql.org/message-id/7985b839-8c0c-4194-bbf8-ee07ae5ef13b%40vondra.me
--
Tomas Vondra
| Attachment | Content-Type | Size |
|---|---|---|
| v6-0001-Mention-checkpoints-in-online-data-checksums-docs.patch | text/x-patch | 1.6 KB |
| v6-0002-Allow-using-spread-checkpoints-when-enabling-disa.patch | text/x-patch | 19.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Matheus Alcantara | 2026-11-23 16:20:24 | Re: [PATCH v1] Fix for Bug#19724 - ALTER TYPE ... ALTER ATTRIBUTE triggers internal error for base type of domain with check |
| Previous Message | Ayoub Kazar | 2026-11-23 15:47:06 | Re: [PROPOSAL] Expand OR clauses in joins to UNION ALL paths |