Re: Infinite loop in XLogPageRead() on standby

From: "Maksim(dot)Melnikov" <m(dot)melnikov(at)postgrespro(dot)ru>
To: Michael Paquier <michael(at)paquier(dot)xyz>,Alexander Kukushkin <cyberdemn(at)gmail(dot)com>
Cc: Ants Aasma <ants(dot)aasma(at)cybertec(dot)at>,Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org,thomas(dot)munro(at)gmail(dot)com
Subject: Re: Infinite loop in XLogPageRead() on standby
Date: 2026-11-17 18:04:48
Message-ID: f9952837-36cd-480d-99ca-4a0a7693af8a@postgrespro.ru
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 1/20/25 04:24, Michael Paquier wrote:

> And done this as well. The buildfarm looks OK with it for the moment.
> I'll keep an eye on things, including the CF bot.
Hi Michael and Alexander!
I think I found potential instability in tap test 039_end_of_wal.pl
according to this thread activity,
please take a look at attached reproducing patch. Maybe reproducing
looks a bit tricky, but it seems
that occurrence of an error depends on the size of generated WAL. Plz
take into account that Postgres
was configured without compression:

./configure --prefix=/home/maxim/master  --enable-tap-tests
--enable-cassert --with-libxml --enable-debug CFLAGS='-O0 -Wall'
--with-icu --enable-injection-points

Patch was applied to SHA cfdd09589b9, I am not sure that reproducing can
occur on another commits, because
it depends from WAL size and I tried to adjust it to fit the problematic
values.
Then test 039_end_of_wal.pl failed

make check PROVE_TESTS=t/039_end_of_wal.pl

...

# +++ tap check in src/test/recovery +++
t/039_end_of_wal.pl .. 3/?
#   Failed test 'xl_prev bad'
#   at t/039_end_of_wal.pl line 189.
# Looks like you failed 1 test of 4.
t/039_end_of_wal.pl .. Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/4 subtests

Test Summary Report
-------------------
t/039_end_of_wal.pl (Wstat: 256 (exited 1) Tests: 4 Failed: 1)
  Failed test:  4
  Non-zero exit status: 1

In logs instead of

record with incorrect prev-link 0/DEADBEEF at

I see

invalid magic number 0000 in WAL segment 000000010000000000000002, LSN
0/2018000, offset 98304

I've investigated it and found that insert_lsn in
advance_wal_out_of_record_splitting_zone can be on the
not initialized WAL page, then if we manually in perl exec write_wal to
this LSN, operation will be succeded
but postgres can't read rec, because it placed on not initialized page
and invalid magic number will be fired.
Now we don't see this issue, but in future if generated WAL will change,
this issue can fire.
As fix I suggest to control in advance_wal_out_of_record_splitting_zone
that end_lsn of last emitted record
should be on the same page with next insert lsn. Patch was attached, it
you have some other ideas, plz share it.

Best regards,
Maksim Melnikov

Attachment Content-Type Size
reproducing.patch.nocfbot text/plain 7.2 KB
v1-0003-Fix-039_end_of_wal.pl-WAL-manual-inserts.patch text/x-patch 7.5 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Greg Burd 2026-11-17 17:54:52 Re: ZSTD TOAST compression, and an extensible compression method encoding