toast table corrupted by vacuum - missing chunk number 0 for toast value

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

toast table corrupted by vacuum - missing chunk number 0 for toast value

От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
Вложения:
Hi,

My customer reported corrupted toast tables on PostgreSQL 14.20. He uses wal archiving - so it was possible to read data from broken pages. The corrupted rows are detected by SELECT command. 

My customer prepared two instances:  before corruption, after corruption. There were more corrupted pages. All checks that I found from extensions amcheck, pg_visibility are ok on instance before corruption. Corrupted instances have problems with toast and toast tables have problems with visibility map. Index on the toast table is ok.

The corrupted toast page contains four tuples. Related main table was not updated. There was only one operation over the toast page - pruning (forced by vacuum executed by cron).

WAL: 0000000100000D6E0000008A
rmgr: Heap2       len (rec/tot):     59/    99, tx:          0, lsn: D6E/8A8A6AD0, prev D6E/8A8A6A68, desc: PRUNE latestRemovedXid 0 nredirected 0 ndead 4, blkref #0: rel 1663/4267629/16352341 blk 17880358 FPW

These vacuum doesn't reports any errors

2026-04-18 05:03:13 CEST [1688]: [46307-1] user=,db=,app=,client= LOG:  checkpoint starting: time
2026-04-18 05:03:24 CEST [3760026]: [10-1] user=postgres,db=jira_prod,app=vacuumdb,client=[local] LOG:  duration: 15037.899 ms  statement: VACUUM (VERBOSE, ANALYZE) public."AO_544E33_AUDIT_LOG_ENTRY";
2026-04-18 05:03:30 CEST [3760026]: [11-1] user=postgres,db=jira_prod,app=vacuumdb,client=[local] LOG:  duration: 5511.161 ms  statement: VACUUM (VERBOSE, ANALYZE) public.jiraaction;
2026-04-18 05:03:40 CEST [3760026]: [12-1] user=postgres,db=jira_prod,app=vacuumdb,client=[local] LOG:  duration: 10052.323 ms  statement: VACUUM (VERBOSE, ANALYZE) public."AO_C5D949_ISSUE_SLA";

After this operation, the toast page had only dead lp pointers and next select fails on reported error.

Attached some data collected before and after corruption.

Can I collect some other data?

Regards

Pavel





Re: toast table corrupted by vacuum - missing chunk number 0 for toast value

От:
Tomas Vondra <tomas@vondra.me>
Дата:


On 7/12/26 20:48, Pavel Stehule wrote:
> Hi,
> 
> My customer reported corrupted toast tables on PostgreSQL 14.20. He uses
> wal archiving - so it was possible to read data from broken pages. The
> corrupted rows are detected by SELECT command. 
> 
> My customer prepared two instances:  before corruption, after
> corruption. There were more corrupted pages. All checks that I found
> from extensions amcheck, pg_visibility are ok on instance before
> corruption. Corrupted instances have problems with toast and toast
> tables have problems with visibility map. Index on the toast table is ok.
> 
> The corrupted toast page contains four tuples. Related main table was
> not updated. There was only one operation over the toast page - pruning
> (forced by vacuum executed by cron).
> 
> WAL: 0000000100000D6E0000008A
> rmgr: Heap2       len (rec/tot):     59/    99, tx:          0, lsn:
> D6E/8A8A6AD0, prev D6E/8A8A6A68, desc: PRUNE latestRemovedXid 0
> nredirected 0 ndead 4, blkref #0: rel 1663/4267629/16352341 blk 17880358 FPW
> 
> These vacuum doesn't reports any errors
> 
> 2026-04-18 05:03:13 CEST [1688]: [46307-1] user=,db=,app=,client= LOG:
>  checkpoint starting: time
> 2026-04-18 05:03:24 CEST [3760026]: [10-1]
> user=postgres,db=jira_prod,app=vacuumdb,client=[local] LOG:  duration:
> 15037.899 ms  statement: VACUUM (VERBOSE, ANALYZE)
> public."AO_544E33_AUDIT_LOG_ENTRY";
> 2026-04-18 05:03:30 CEST [3760026]: [11-1]
> user=postgres,db=jira_prod,app=vacuumdb,client=[local] LOG:  duration:
> 5511.161 ms  statement: VACUUM (VERBOSE, ANALYZE) public.jiraaction;
> 2026-04-18 05:03:40 CEST [3760026]: [12-1]
> user=postgres,db=jira_prod,app=vacuumdb,client=[local] LOG:  duration:
> 10052.323 ms  statement: VACUUM (VERBOSE, ANALYZE)
> public."AO_C5D949_ISSUE_SLA";
> 
> After this operation, the toast page had only dead lp pointers and next
> select fails on reported error.
> 
> Attached some data collected before and after corruption.
> 
> Can I collect some other data?
> 

If you still have the backup + WAL, I'd start by doing two things:

(1) running pg_waldump on older WAL segments, to figure out when / how
was the page modified before VACUUM kicked in

(2) restoring the cluster to LSN shortly before D6E/8A8A6AD0

(3) dumping the page somehow (copying the 8K block, looking at it using
pageinspect, etc. ...)

(4) promote the instance, run a manual vacuum and see if it gets
corrupted again

If there are more corrupted pages, then do this for multiple of them,
and see if there's some similarity (e.g. all the corruption may be tied
to the same XID, or maybe it's multixacts, ...).


It'd also be good to get some additional info:

1) history of the cluster - How old is it? Did it start as PG14, or is
it an older cluster that went through pg_upgrade?

2) are there any extensions installed - especially third-party ones


regards

-- 
Tomas Vondra



Re: toast table corrupted by vacuum - missing chunk number 0 for toast value

От:
Pavel Stehule <pavel.stehule@gmail.com>
Дата:
Вложения:


pá 21. 8. 2026 v 19:13 odesílatel Tomas Vondra <tomas@vondra.me> napsal:


On 8/21/26 17:47, Pavel Stehule wrote:
> Hi
>
> pá 21. 8. 2026 v 12:31 odesílatel Andrey Borodin <x4mmm@yandex-team.ru
> <mailto:x4mmm@yandex-team.ru>> napsal:
>
>     Hi Pavel,
>
>     On Thu, Aug 20, 2026 at 9:56 PM Pavel Stehule wrote:
>     > We didn't find any way how this issue can be reproduced. We manually
>     > executed VACUUM on the database that was restored to the time close
>     > before this issue - and the data was not broken - but now, I am not
>     > sure what was the minor version that we used for this test.
>
>     I wonder whether the missing TOAST data could be a secondary symptom,
>     rather than evidence that VACUUM removed TOAST belonging to the current
>     row version.
>
>
> I have dumped pages
>
> https://www.postgresql.org/message-id/attachment/199738/
> investigation.txt <https://www.postgresql.org/message-id/
> attachment/199738/investigation.txt>
>
> xmin, xmax was same on main table, and toast table. These rows was not
> updated.
>

Thanks. Interesting. It's weird the TOAST rows have XID 2779428784 and
flags {HEAP_HASVARWIDTH,HEAP_XMIN_COMMITTED,HEAP_XMAX_INVALID}, yet the
VACUUM apparently decided all of them are dead. Judging by:

> rmgr: Heap2       len (rec/tot):     59/    99, tx:          0, lsn:
> D6E/8A8A6AD0, prev D6E/8A8A6A68, desc: PRUNE latestRemovedXid 0
> nredirected 0 ndead 4, blkref #0: rel 1663/4267629/16352341 blk
17880358 FPW

I mean, ndead=4 seems to suggest that. But how could that be with
HEAP_XMIN_COMMITTED?

I wonder if the FPW from the WAL matches what you saw as corrupted, or
if it's correct (it should, given the ndead=4). But maybe try dumping it
using pg_waldump - although, 14 doesn't have that :-(.

What happened with the XID 2779428784? Did it commit sometime right
before the vacuum, or what? Judging by the page LSN, it must have been
pretty far back.

What does the clog say about this transaction? I think it should be:
pg_xact/0A5A, page 21, byte offset 175596, bits 0-1, so

$ od -An -tx1 -j 175596 -N 1 $PGDATA/pg_xact/0A5A

Also, what does the RUNNING_XACTS right before/after vacuum say?

Unfortunately these backups was overwritten month ago

Regards

Pavel
 

--
Tomas Vondra

FAQ