Re: pgsql: Revert online data checksum transitions

Поиск
Список
Период
Сортировка
Искать

Re: pgsql: Revert online data checksum transitions

От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Wed, Sep 16, 2026 at 6:06 PM Daniel Gustafsson
 wrote:
>
> Revert online data checksum transitions

It's unfortunate that this feature had to be reverted...
Anyway, thanks for all your hard work on it!!


After the revert, the buildfarm member longfin reported the test failure [1],
which seems to have been caused by the revert.

According to longfin's server log, the test triggers the following
assertion failure:

    TRAP: failed Assert("(data - start) == data_size"), File:
"heaptuple.c", Line: 442, PID: 78459
    ...
    2026-09-16 06:03:57.172 EDT [77693:4] LOG:  client backend (PID
78459) was terminated by signal 6: Abort trap: 6
    2026-09-16 06:03:57.172 EDT [77693:5] DETAIL:  Failed process was
running: SELECT count(*) > 0 AS ok FROM pg_control_checkpoint();

After the revert, pg_control_checkpoint() now returns 19 columns, but its
pg_proc.dat entry still declares 20 output columns, including
data_page_checksum_version. This seems to trigger the assertion failure
in heap_form_tuple().

We should remove data_page_checksum_version from the pg_control_checkpoint
entry in pg_proc.dat and reduce proargmodes from 20 output columns to 19?

Regards,

[1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=longfin&dt=2026-09-16%2010%3A01%3A48

-- 
Fujii Masao


Re: pgsql: Revert online data checksum transitions

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 16 Sep 2026, at 13:01, Fujii Masao  wrote:
> 
> On Wed, Sep 16, 2026 at 6:06 PM Daniel Gustafsson
>  wrote:
>> 
>> Revert online data checksum transitions
> 
> It's unfortunate that this feature had to be reverted...
> Anyway, thanks for all your hard work on it!!
> 
> 
> After the revert, the buildfarm member longfin reported the test failure [1],
> which seems to have been caused by the revert.
> 
> According to longfin's server log, the test triggers the following
> assertion failure:
> 
>    TRAP: failed Assert("(data - start) == data_size"), File:
> "heaptuple.c", Line: 442, PID: 78459
>    ...
>    2026-09-16 06:03:57.172 EDT [77693:4] LOG:  client backend (PID
> 78459) was terminated by signal 6: Abort trap: 6
>    2026-09-16 06:03:57.172 EDT [77693:5] DETAIL:  Failed process was
> running: SELECT count(*) > 0 AS ok FROM pg_control_checkpoint();
> 
> After the revert, pg_control_checkpoint() now returns 19 columns, but its
> pg_proc.dat entry still declares 20 output columns, including
> data_page_checksum_version. This seems to trigger the assertion failure
> in heap_form_tuple().
> 
> We should remove data_page_checksum_version from the pg_control_checkpoint
> entry in pg_proc.dat and reduce proargmodes from 20 output columns to 19?

Ugh, I thought I had tested everything but clearly missed this one. Will fix immediately when back from lunch.

./daniel

Re: pgsql: Revert online data checksum transitions

От:
Aleksander Alekseev <aleksander@tigerdata.com>
Дата:
Hi Daniel,

> [...]
>
> > We should remove data_page_checksum_version from the pg_control_checkpoint
> > entry in pg_proc.dat and reduce proargmodes from 20 output columns to 19?
>
> Ugh, I thought I had tested everything but clearly missed this one. Will fix immediately when back from lunch.

I noticed that the revert was applied to REL_19_STABLE but not the
master branch. Just wanted to make sure that's the plan.

-- 
Best regards,
Aleksander Alekseev


Re: pgsql: Revert online data checksum transitions

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 16 Sep 2026, at 14:32, Aleksander Alekseev  wrote:

>>> We should remove data_page_checksum_version from the pg_control_checkpoint
>>> entry in pg_proc.dat and reduce proargmodes from 20 output columns to 19?
>> 
>> Ugh, I thought I had tested everything but clearly missed this one. Will fix immediately when back from lunch.
> 
> I noticed that the revert was applied to REL_19_STABLE but not the
> master branch. Just wanted to make sure that's the plan.

That's indeed the plan.  The remaining issue that a user can, under the right
set of circumstances, get a false positive page verification in an orphaned
file failure during base backup.  The warning is harmless for data integrity,
but is non-trivial for the user to resolve since we don't provide any tools for
dealing with orphaned files.  Fixing this in master will reduce churn.

--
Daniel Gustafsson



Re: pgsql: Revert online data checksum transitions

От:
Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
Дата:
Вложения:
Daniel Gustafsson  wrote:
> Ugh, I thought I had tested everything but clearly missed this one. Will fix immediately when back from lunch.

While you are at it: the revert removes RM_XLOG2_ID and its records but
leaves XLOG_PAGE_MAGIC at 0xD121 on REL_19_STABLE.  0xD121 was set on
2026-07-15 by b01c31eef9c, after the feature had added XLOG2 on
2026-04-03, and it is what 19beta3 shipped with.  So WAL written by
19beta3 and WAL written by 19.0 now carry the same magic but are not
the same format.

To check, I enabled checksums online on 19beta3 and read the WAL with
the pg_waldump of REL_19_STABLE at d8408e8d682:

  19beta3's pg_waldump -r XLOG2:
    rmgr: XLOG2 ... lsn: 0/0157F5A8 ... desc: CHECKSUMS inprogress-on
    rmgr: XLOG2 ... lsn: 0/02DC9AD8 ... desc: CHECKSUMS on

  REL_19_STABLE's pg_waldump, same segments:
    pg_waldump: error: could not find a valid record after 0/0157F5A8:
    invalid resource manager ID 22 at 0/0157F5A8

  REL_19_STABLE's pg_waldump with XLOG_PAGE_MAGIC bumped:
    pg_waldump: error: could not find a valid record after 0/0157F5A8:
    invalid magic number D121 in WAL segment 000000010000000000000001,
    LSN 0/01000000, offset 0

The server itself is not at risk, since PG_CONTROL_VERSION was bumped
and 19.0 refuses a beta3 data directory; it is only tools reading
archived beta3 WAL that cannot tell the formats apart.  But the revert
of 0d3dba38c77 on this branch (01a80f06214) bumped the magic for the
same reason, so it looks like this one should too.  Note that master is
already at 0xD122, for a different format.

The script is attached, in case it is useful.

Regards,
Manu

Re: pgsql: Revert online data checksum transitions

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 16 Sep 2026, at 14:58, Manuel Reyes Bravo  wrote:

> The server itself is not at risk, since PG_CONTROL_VERSION was bumped
> and 19.0 refuses a beta3 data directory; it is only tools reading
> archived beta3 WAL that cannot tell the formats apart.  But the revert
> of 0d3dba38c77 on this branch (01a80f06214) bumped the magic for the
> same reason, so it looks like this one should too.

Thanks for the report, will include when fixing.

--
Daniel Gustafsson



Re: pgsql: Revert online data checksum transitions

От:
Heikki Linnakangas <hlinnaka@iki.fi>
Дата:
On 16/09/2026 16:04, Daniel Gustafsson wrote:
>> On 16 Sep 2026, at 14:58, Manuel Reyes Bravo  wrote:
> 
>> The server itself is not at risk, since PG_CONTROL_VERSION was bumped
>> and 19.0 refuses a beta3 data directory; it is only tools reading
>> archived beta3 WAL that cannot tell the formats apart.  But the revert
>> of 0d3dba38c77 on this branch (01a80f06214) bumped the magic for the
>> same reason, so it looks like this one should too.
> 
> Thanks for the report, will include when fixing.

Also, the ControlFile->data_checksum_version_init is now never set.

- Heikki



Re: pgsql: Revert online data checksum transitions

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Daniel Gustafsson  writes:
>> On 16 Sep 2026, at 13:01, Fujii Masao  wrote:
>> After the revert, the buildfarm member longfin reported the test failure [1],
>> which seems to have been caused by the revert.
>> ...
>> After the revert, pg_control_checkpoint() now returns 19 columns, but its
>> pg_proc.dat entry still declares 20 output columns, including
>> data_page_checksum_version. This seems to trigger the assertion failure
>> in heap_form_tuple().

> Ugh, I thought I had tested everything but clearly missed this one. Will fix immediately when back from lunch.

It seems quite odd to me that only a couple of BF animals are showing
this failure.  Do we understand why that should be?  I can poke into
it on longfin's host if that would help.

			regards, tom lane


Re: pgsql: Revert online data checksum transitions

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 16 Sep 2026, at 17:49, Tom Lane  wrote:

> I can poke into it on longfin's host if that would help.

That would be great, thanks.

--
Daniel Gustafsson



Re: pgsql: Revert online data checksum transitions

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 16 Sep 2026, at 16:08, Heikki Linnakangas  wrote:
> 
> On 16/09/2026 16:04, Daniel Gustafsson wrote:
>>> On 16 Sep 2026, at 14:58, Manuel Reyes Bravo  wrote:
>>> The server itself is not at risk, since PG_CONTROL_VERSION was bumped
>>> and 19.0 refuses a beta3 data directory; it is only tools reading
>>> archived beta3 WAL that cannot tell the formats apart.  But the revert
>>> of 0d3dba38c77 on this branch (01a80f06214) bumped the magic for the
>>> same reason, so it looks like this one should too.
>> Thanks for the report, will include when fixing.
> 
> Also, the ControlFile->data_checksum_version_init is now never set.

This patch is as difficult to back out as it was to get in.  I've been trying
to save a few small generic checksum bugfixes from the revert but that also
made it a lot more complicated.  Will fix this one as well in the follow-up
fixup I have staged for later today.

--
Daniel Gustafsson



Re: pgsql: Revert online data checksum transitions

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
Daniel Gustafsson  writes:
>> On 16 Sep 2026, at 17:49, Tom Lane  wrote:
>> I can poke into it on longfin's host if that would help.

> That would be great, thanks.

What seems to be happening is

(1) pg_control_checkpoint()'s local values[] and nulls[] arrays
are now of length 19.

(2) But the tupdesc that get_call_result_type() builds from the
pg_proc entry still has 20 columns.

(3) Therefore, heap_form_tuple sees a wrong value for the 19th column
(which does no great damage, since it's still a pass-by-value type)
and then fetches complete garbage from values[19] and nulls[19].

Depending on the stack layout and the phase of the moon, nulls[19]
might read as zero or it might not.  Either case is fine so long as
heap_compute_data_size and heap_fill_tuple/fill_val interpret it the
same way.  However, what I'm seeing as I trace through the crash on
longfin is that nulls[19] has a value that's not either 0 or 1 (not
too surprising), and somehow heap_compute_data_size is interpreting
that as "true" while fill_val is reading it as "false".  According
to my understanding of the C standard, fill_val is in the wrong here.
I looked at the generated assembly code and could not spot exactly
what the problem is; it seems to be testing the byte value with

        .loc    0 301 7 is_stmt 1               ## heaptuple.c:301:7
        testb   %al, %al
        je      LBB3_6

which certainly looks like it ought to treat all nonzero values alike.
Anyway this seems to be a code generation quirk of certain versions of
clang.  It's probably not worth chasing further.

			regards, tom lane


Re: pgsql: Revert online data checksum transitions

От:
Jacob Champion <jacob.champion@enterprisedb.com>
Дата:
On Wed, Sep 16, 2026 at 10:14 AM Tom Lane  wrote:
> However, what I'm seeing as I trace through the crash on
> longfin is that nulls[19] has a value that's not either 0 or 1 (not
> too surprising), and somehow heap_compute_data_size is interpreting
> that as "true" while fill_val is reading it as "false".  According
> to my understanding of the C standard, fill_val is in the wrong here.

Is the _Bool representation allowed to contain anything but zero/false
or one/true? I thought that was undefined behavior. (IIRC, mixing C++
bool with our C89-era bool definition suffered from similar UB
excitement.)

--Jacob


Re: pgsql: Revert online data checksum transitions

От:
Bryan Green <dbryan.green@gmail.com>
Дата:
If we are pulling in stdbool.h and this is C11...that is undefined behavior and because it wasn't validly initialized it is an indeterminate-value read...which means for optimization that the compiler is within its right to assume it is a 0 or 1 and could test it in different ways depending on the surrounding code (nonzero test, compare to 1, etc).  

On Wed, Sep 16, 2026 at 12:34 PM Jacob Champion <jacob.champion@enterprisedb.com> wrote:
On Wed, Sep 16, 2026 at 10:14 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> However, what I'm seeing as I trace through the crash on
> longfin is that nulls[19] has a value that's not either 0 or 1 (not
> too surprising), and somehow heap_compute_data_size is interpreting
> that as "true" while fill_val is reading it as "false".  According
> to my understanding of the C standard, fill_val is in the wrong here.

Is the _Bool representation allowed to contain anything but zero/false
or one/true? I thought that was undefined behavior. (IIRC, mixing C++
bool with our C89-era bool definition suffered from similar UB
excitement.)

--Jacob


Re: pgsql: Revert online data checksum transitions

От:
Bryan Green <dbryan.green@gmail.com>
Дата:

On Wed, Sep 16, 2026 at 12:39 PM Bryan Green <dbryan.green@gmail.com> wrote:
If we are pulling in stdbool.h and this is C11...that is undefined behavior and because it wasn't validly initialized it is an indeterminate-value read...which means for optimization that the compiler is within its right to assume it is a 0 or 1 and could test it in different ways depending on the surrounding code (nonzero test, compare to 1, etc).  

On Wed, Sep 16, 2026 at 12:34 PM Jacob Champion <jacob.champion@enterprisedb.com> wrote:
On Wed, Sep 16, 2026 at 10:14 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> However, what I'm seeing as I trace through the crash on
> longfin is that nulls[19] has a value that's not either 0 or 1 (not
> too surprising), and somehow heap_compute_data_size is interpreting
> that as "true" while fill_val is reading it as "false".  According
> to my understanding of the C standard, fill_val is in the wrong here.

Is the _Bool representation allowed to contain anything but zero/false
or one/true? I thought that was undefined behavior. (IIRC, mixing C++
bool with our C89-era bool definition suffered from similar UB
excitement.)

--Jacob


Re: pgsql: Revert online data checksum transitions

От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Wed, Sep 16, 2026 at 8:08 PM Daniel Gustafsson  wrote:
> Ugh, I thought I had tested everything but clearly missed this one. Will fix immediately when back from lunch.

Here are another comments:

data_checksum_version field in xl_checkpoint_redo struct should be removed?
Otherwise, it seems to be included in WAL records unnecessarily even though
it is no longer used. No?


-       database (or on a shared object), or NULL if data checksums are
-       disabled.
-      
+       database (or on a shared object).  Detected failures are not reset if
+       the  setting changes.  Clusters
+       which are initialized without data checksums will show this as
+       0. In PostgreSQL version
+       18 and earlier, this was set to NULL for clusters
+       with data checksums disabled.
+      
+     
...
-       this database (or on a shared object), or NULL if data checksums are
-       disabled.
+       this database (or on a shared object). Last failure is reported
+       regardless of the  setting.

These updates to monitoring.sgml from commit f19c0eccae9 also should be
reverted? checksum_failures and checksum_last_failure seem to return
NULL again when data checksums are disabled, so their descriptions would
otherwise be incorrect.


checksum_enable_offline() and checksum_disable_offline() in
Cluster.pm also seem to be unused now. Should they be removed as well?

Regards,

-- 
Fujii Masao


Re: pgsql: Revert online data checksum transitions

От:
Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
Дата:
Вложения:
Fujii Masao  wrote:
> data_checksum_version field in xl_checkpoint_redo struct should be removed?
> Otherwise, it seems to be included in WAL records unnecessarily even though
> it is no longer used. No?

Agreed.  It is also never assigned now: c05d5ce1236 removed the line in
CreateCheckPoint() that set it, but the whole struct is still
registered, so the main data of each XLOG_CHECKPOINT_REDO record is 8
bytes, 4 of them unset.  Before f19c0eccae9 it was 4 bytes.  In my runs
on REL_19_STABLE at 4a9a6c5a69c the unset bytes happened to be zero.

> These updates to monitoring.sgml from commit f19c0eccae9 also should be
> reverted? checksum_failures and checksum_last_failure seem to return
> NULL again when data checksums are disabled, so their descriptions would
> otherwise be incorrect.

Yes, both pg_stat_get_db_checksum_failures() and
pg_stat_get_db_checksum_last_failure() return NULL when
DataChecksumsEnabled() is false, as they did before f19c0eccae9.

> checksum_enable_offline() and checksum_disable_offline() in
> Cluster.pm also seem to be unused now. Should they be removed as well?

They have no callers left in the tree.

To check whether anything else was left behind, I went through the 30
commits listed in c05d5ce1236 mechanically: the identifiers and the
non-trivial lines they added that are still in REL_19_STABLE and were
not there before f19c0eccae9.  Apart from what the revert keeps on
purpose (the checksum state enum, data_checksum_version_init, the
zeroing note in page verification and the rewritten docs section),
these three are the only ones left.

In case it saves Daniel some time, the attached patch does the three,
against REL_19_STABLE.  The changed parts match the text before
f19c0eccae9.  It builds without warnings, make check passes, the redo
records are back to 4 bytes of data, and the two readers of that data,
pg_waldump and the WAL summarizer (with summarize_wal on), work as
before.

I have not touched XLOG_PAGE_MAGIC.  Nothing has been released since
4a9a6c5a69c bumped it, but pg_waldump or a summarizer built before this
patch would copy 8 bytes out of a 4-byte record, so that is your call.

Regards,
Manu

Re: pgsql: Revert online data checksum transitions

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 17 Sep 2026, at 15:27, Manuel Reyes Bravo  wrote:

> In case it saves Daniel some time, the attached patch does the three,
> against REL_19_STABLE.

Thanks, I also went over the commits today so I'll compare notes before
applying to v19 later today.

--
Daniel Gustafsson



Re: pgsql: Revert online data checksum transitions

От:
Daniel Gustafsson <daniel@yesql.se>
Дата:
> On 17 Sep 2026, at 18:54, Daniel Gustafsson  wrote:
> 
> 
>> 
>>> On 17 Sep 2026, at 15:27, Manuel Reyes Bravo  wrote:
>> 
>> In case it saves Daniel some time, the attached patch does the three,
>> against REL_19_STABLE.
> 
> Thanks, I also went over the commits today so I'll compare notes before
> applying to v19 later today.

I’ve applied this now. I originally kept the Test code in place ro minimize backpatching conflict risks there but after thinking further I ended up removing it as well.

./daniel

FAQ