incremental backup issue

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

incremental backup issue

От:
Fabrice Chapuis <fabrice636861@gmail.com>
Дата:
Hi,

I use Postgres 17.7 and I have configured incremental backup 

wal_summary_keep_time=10d
show wal_summary_keep_time=on

On the standby, this message is written every 10 seconds by the walsummarizer process.

2026-02-17 11:40:22.548 CET [544677]: [297-1] user=,db=,client=,application= ERROR:  could not read WAL from timeline 6 at 698/460000A0: invalid record length at 698/460000A0: expected at least 24, got 0
2026-02-17 11:40:32.559 CET [544677]: [298-1] user=,db=,client=,application= ERROR:  could not read WAL from timeline 6 at 698/460000A0: invalid record length at 698/460000A0: expected at least 24, got 0

postgres  544677  544615  0 10:50 ?        00:00:00 postgres: dev_ge: walsummarizer

Last summary files are:

-rw-------. 1 postgres postgres  1808 Feb  5 18:00 00000007000006998F2205F0000006998F2FCAA8.summary
-rw-------. 1 postgres postgres  1158 Feb  5 18:30 00000007000006998F2FCAA8000006998F328C48.summary
-rw-------. 1 postgres postgres   448 Feb  5 19:00 00000007000006998F328C48000006998F3419C0.summary
-rw-------. 1 postgres postgres   566 Feb  5 19:30 00000007000006998F3419C0000006998F35D2C8.summary
-rw-------. 1 postgres postgres   616 Feb  5 20:00 00000007000006998F35D2C8000006998F379C60.summary
-rw-------. 1 postgres postgres  1108 Feb  5 20:30 00000007000006998F379C60000006998F3A88C8.summary
-rw-------. 1 postgres postgres   330 Feb  5 20:43 00000007000006998F3A88C80000069990000028.summary
-rw-------. 1 postgres postgres    32 Feb  5 20:43 00000007000006999000002800000699900000A0.summary
-rw-------. 1 postgres postgres    32 Feb  5 20:43 0000000800000699900000A000000699900000D8.summary

summary file of the timeline 6

-rw-------. 1 postgres postgres   780 Jan  8 20:10 0000000600000698452AB9680000069846000028.summary
-rw-------. 1 postgres postgres    32 Jan  8 20:10 00000006000006984600002800000698460000A0.summary

pg_waldump 000000060000069800000046
rmgr: XLOG        len (rec/tot):    114/   114, tx:          0, lsn: 698/46000028, prev 698/452D6AA8, desc: CHECKPOINT_SHUTDOWN redo 698/46000028; tli 6; prev tli 6; fpw true; wal_level logical; xid 0:212216474; oid 6953284; multi 86737; offset 217538; oldest xid 16464388 in DB 18769; oldest multi 1 in DB 17257; oldest/newest commit timestamp xid: 167966575/212216473; oldest running xid 0; shutdown
pg_waldump: error: error in WAL record at 698/46000028: invalid record length at 698/460000A0: expected at least 24, got 0

On the primary summary process works fine

-rw-------. 1 postgres postgres   2340 Feb 17 10:05 000000090000069A7F9595980000069A7F9B2D08.summary
-rw-------. 1 postgres postgres   1568 Feb 17 10:35 000000090000069A7F9B2D080000069A7F9EF6C8.summary
-rw-------. 1 postgres postgres   5300 Feb 17 11:05 000000090000069A7F9EF6C80000069A7FA47288.summary
-rw-------. 1 postgres postgres    642 Feb 17 11:35 000000090000069A7FA472880000069A7FA6B820.summary

no lag between primary and secondary

Recovery on the standby is active and on time
postgres  544620  544615  0 10:50 ?        00:00:00 postgres: dev_ge: startup recovering 000000090000069A00000080
postgres  544675  544615  0 10:50 ?        00:00:00 postgres: dev_ge: walreceiver streaming 69A/800D0808

history files:

cat 00000007.history
1       5F4/BB000C68    no recovery target specified

2       618/9C0000A0    no recovery target specified

3       619/E70000A0    no recovery target specified

4       669/96FFFFD0    no recovery target specified

5       693/CC0000A0    no recovery target specified

6       698/460000A0    no recovery target specified

cat 00000008.history
1       5F4/BB000C68    no recovery target specified

2       618/9C0000A0    no recovery target specified

3       619/E70000A0    no recovery target specified

4       669/96FFFFD0    no recovery target specified

5       693/CC0000A0    no recovery target specified

6       698/460000A0    no recovery target specified

7       699/900000A0    no recovery target specified

cat 00000009.history
1       5F4/BB000C68    no recovery target specified

2       618/9C0000A0    no recovery target specified

3       619/E70000A0    no recovery target specified

4       669/96FFFFD0    no recovery target specified

5       693/CC0000A0    no recovery target specified

6       698/460000A0    no recovery target specified

7       699/900000A0    no recovery target specified

8       699/910000A0    no recovery target specified

In the code: 
walsummarizer.c
/*
* Main loop: read xlog records one by one.
*/
while (1)
{
int block_id;
char   *errormsg;
XLogRecord *record;
uint8 rmid;

ProcessWalSummarizerInterrupts();

/* We shouldn't go backward. */
Assert(summary_start_lsn <= xlogreader->EndRecPtr);

/* Now read the next record. */
record = XLogReadRecord(xlogreader, &errormsg);
if (record == NULL)
{

xlogreader.c
XLogReadRecord --> XLogReadAhead(XLogReaderState *state, bool nonblocking) --> result = XLogDecodeNextRecord(state, nonblocking); => error
  --> XLogNextRecord
 
 
/* There may be no next page if it's too small. */
if (total_len < SizeOfXLogRecord)
{
report_invalid_record(state,
 "invalid record length at %X/%08X: expected at least %u, got %u",
 LSN_FORMAT_ARGS(RecPtr),
 (uint32) SizeOfXLogRecord, total_len);
goto err;

why walsummarizer works fine on the primary and it is stuck on the secondary?

when the  walsummarizer process was stop for a while (24h) and restarted, it resumes, but the history is lost.

 -rw-------. 1 postgres postgres   580 Feb 18 11:09 000000090000069AB9B511680000069AB9B7F260.summary
-rw-------. 1 postgres postgres  1880 Feb 18 11:09 000000090000069AB9B7F2600000069AB9BB6780.summary
-rw-------. 1 postgres postgres   530 Feb 18 11:09 000000090000069ABF2082880000069ABF23C690.summary
-rw-------. 1 postgres postgres  8582 Feb 18 11:35 000000090000069ABF23C6900000069AC01B1EB0.summary

Any clue of what happend will be very appreciated

Fabrice



Re: incremental backup issue

От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Wed, Feb 18, 2026 at 5:40 AM Fabrice Chapuis  wrote:
> why walsummarizer works fine on the primary and it is stuck on the secondary?

I don't know. It sounds like a bug, but I'm not exactly sure what the
bug is. In the situation you describe here, it seems like the standby
might have switched from timeline 6 to some newer timeline, most
likely 7, but the WAL summarizer got stuck at the end of timeline 6
instead of following the timeline change. If that were the
explanation, then this would only happen when a new primary is
promoted and a standby starts following it. It could either be the
case that this happens every single time a standby changes timelines,
or it could be that it only happens if the standby changes timelines
and some other unknown condition is also satisfied.

Alternatively, maybe there's some other triggering event altogether.

Any ideas, based on your experience so far?

-- 
Robert Haas
EDB: http://www.enterprisedb.com


Re: incremental backup issue

От:
Fabrice Chapuis <fabrice636861@gmail.com>
Дата:
I could try to reproduce the problem. I'll keep you in touch

Regards,
Fabrice

On Thu, Feb 19, 2026 at 1:14 AM Robert Haas <robertmhaas@gmail.com> wrote:
On Wed, Feb 18, 2026 at 5:40 AM Fabrice Chapuis <fabrice636861@gmail.com> wrote:
> why walsummarizer works fine on the primary and it is stuck on the secondary?

I don't know. It sounds like a bug, but I'm not exactly sure what the
bug is. In the situation you describe here, it seems like the standby
might have switched from timeline 6 to some newer timeline, most
likely 7, but the WAL summarizer got stuck at the end of timeline 6
instead of following the timeline change. If that were the
explanation, then this would only happen when a new primary is
promoted and a standby starts following it. It could either be the
case that this happens every single time a standby changes timelines,
or it could be that it only happens if the standby changes timelines
and some other unknown condition is also satisfied.

Alternatively, maybe there's some other triggering event altogether.

Any ideas, based on your experience so far?

--
Robert Haas
EDB: http://www.enterprisedb.com

Re: incremental backup issue

От:
Nick Ivanov <nick.ivanov@enterprisedb.com>
Дата:
Hello Fabrice,

I'm wondering if you had a chance to reproduce the problem. I'm seeing something similar, but not exactly, so I'm curious if this may be another manifestation of the error I get.

Thanks

Nick



On Thu, Feb 19, 2026 at 8:27 AM Fabrice Chapuis <fabrice636861@gmail.com> wrote:
I could try to reproduce the problem. I'll keep you in touch

--
Robert Haas
EDB: http://www.enterprisedb.com

I use Postgres 17.7 and I have configured incremental backup 

wal_summary_keep_time=10d
show wal_summary_keep_time=on

On the standby, this message is written every 10 seconds by the walsummarizer process.

2026-02-17 11:40:22.548 CET [544677]: [297-1] user=,db=,client=,application= ERROR:  could not read WAL from timeline 6 at 698/460000A0: invalid record length at 698/460000A0: expected at least 24, got 0
2026-02-17 11:40:32.559 CET [544677]: [298-1] user=,db=,client=,application= ERROR:  could not read WAL from timeline 6 at 698/460000A0: invalid record length at 698/460000A0: expected at least 24, got 0
--
Nick Ivanov 
Solutions Architect   

Re: incremental backup issue

От:
Thom Brown <thom@linux.com>
Дата:
On Mon, 13 Jul 2026 at 22:43, Robert Haas  wrote:
>
> On Mon, Jul 13, 2026 at 2:14 PM Thom Brown  wrote:
> > 0001 clamps read_upto to the switch point when reading a historic
> > timeline, matching the page-read callback and the documented contract.
>
> IMHO, this is a great example of why AI-generated bug reports and/or
> fixes need to be double-checked by knowledgeable humans. claude would
> have benefited from reading the comments for SummarizeWAL itself,
> which say:
>
>  * 'maximum_lsn' identifies the point beyond which we can't count on being
>  * able to read any more WAL. It should be the switch point when reading a
>  * historic timeline, or the most-recently-measured end of WAL when reading
>  * the current timeline.

Ha, yes, this is certainly a clear example of the confidence AI puts
in its own conclusions not being indicative of reliability.

> Which means that the clamping in 0001 shouldn't be necessary, because
> the caller should already have done it.
>
> But the question is: how exactly does this scenario arise in the first
> place? SummarizeWAL checks before reading each record that the record
> it's reading starts before the switch point, and then checks again
> after reading it that it ends before the switch point. So if, for
> example, you have a primary archiving files on TLI 1 and you promote a
> standby and it archives files on TLI 2, nothing will actually go
> wrong, I think. The standby trying to follow the timeline switch from
> TLI 1 to TLI 2 might read one record past the switchpoint, but then it
> will realize what's happened and sort itself out. The problem only
> occurs if trying to read one record past the switchpoint results in an
> error. In the original scenario and in claude's analysis, that seems
> to happen because the tail end of the WAL segment is all zeros... but
> how did such a file get archived in the first place?
>
> The only obvious way I can see that happening is if somebody renames
> the .partial file to remove that suffix and then causes the resulting
> file to get archived. I don't think that's a thing that you're really
> supposed to do. That's not to say I don't think we should fix this:
> WalSummarizerMain is calling SummarizeWAL with a maximum_lsn that is
> not computed in the way that SummarizeWAL says it should be computed,
> which is bad, and the result is that this code is less robust than I
> would like it to be, which is also bad. But I *think* you have to be
> doing something unusual for it to become a problem in practice, which
> might be why Fabrice had difficulty reproducing it.

So really, this doesn't sound like this is solved, not that these
changes aren't still necessary.

> I attach a patch. I don't think we need anything like the 0002 in your
> proposal from claude. The read horizon used by the WAL summarizer
> *has* to be valid; if we can't achieve that, we're doomed.

Nick, you said that you saw something "similar" (suggesting that it's
not identical), but you didn't explain what that was. Is there
potentially a separate bug that needs reporting?

Thom


Re: incremental backup issue

От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Mon, Jul 13, 2026 at 6:07 PM Thom Brown  wrote:
> Ha, yes, this is certainly a clear example of the confidence AI puts
> in its own conclusions not being indicative of reliability.

Yep. And it's an odd oversight, too, since apportioning blame between
SummarizeWAL and its caller seems to be the whole deal here, and the
comments are how you figure out whose fault it is (at least, if they
say anything useful).

> So really, this doesn't sound like this is solved, not that these
> changes aren't still necessary.

I assume it's likely that Fabrice ended up with a not-totally-valid
WAL file in the archive after some series of manual steps and couldn't
quite remember what had been done well enough to provide an exact
reproducer. That seems like a completely reasonable thing to happen to
somebody. Now it's also possible that there is some as-yet-unknown way
for this to happen without manual fudging, but unless somebody can
figure out what that is exactly, it's hard to say what we ought to do
about it.

> > I attach a patch. I don't think we need anything like the 0002 in your
> > proposal from claude. The read horizon used by the WAL summarizer
> > *has* to be valid; if we can't achieve that, we're doomed.
>
> Nick, you said that you saw something "similar" (suggesting that it's
> not identical), but you didn't explain what that was. Is there
> potentially a separate bug that needs reporting?

See the "walsummarizer can get stuck when switching timelines" thread.
That case occurs when there's a timeline switch and the file from the
old timeline doesn't make it into the archive at all. This case occurs
where there's a timeline switch and a corrupted file from the old
timeline makes it into the archive. It's possible to reproduce that
case without any manual steps; see the included test case on that
thread. As I say, I can believe that there could be a way to reproduce
this case without manual steps too, but I don't know what it is.

-- 
Robert Haas
EDB: http://www.enterprisedb.com


Re: incremental backup issue

От:
Robert Haas <robertmhaas@gmail.com>
Дата:
On Mon, Jul 13, 2026 at 5:42 PM Robert Haas  wrote:
> I attach a patch. I don't think we need anything like the 0002 in your
> proposal from claude. The read horizon used by the WAL summarizer
> *has* to be valid; if we can't achieve that, we're doomed.

I have now committed this patch and back-patched to back to v17, the
first release that contains walsummarizer.

-- 
Robert Haas
EDB: http://www.enterprisedb.com


FAQ