Re: VACUUM FULL or CREATE INDEX fails with error: missing chunk number 0 for toast value XXX

From: Тестова Екатерина <e(dot)testova(at)postgrespro(dot)ru>
To: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: VACUUM FULL or CREATE INDEX fails with error: missing chunk number 0 for toast value XXX
Date: 2026-07-08 07:34:16
Message-ID: 1783496056.499330176@fmail1.qdit
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


Matthias, thank you for the review and suggestions.
 
On Mon, Jul 06, 2026 at 05:44:50PM, Matthias van de Meent wrote:
> I think this is insufficient; heap on-access pruning and btree's aggressive index tuple removal (when the page would split) will > still cause some cleanup of data that could still be considered RECENTLY_DEAD by a possible concurrent maintenance > session (CREATE INDEX, REINDEX, VACUUM FULL, ...).
 
That's a good point. I agree that the bug is not limited to removing toast tuples only during VACUUM.
 
> We can reduce the likelyhood of this issue by regularly updating the OldestXmin used for HeapTupleSatisfiesVacuum() with > more recent GetOldestNonRemovableTransactionId(heapRelation) in e.g. heapam_index_build_range_scan
 
At the same time, getting the current OldestXmin more often will definitely not protect (and it won't particularly reduce the likelihood of) against the situation that I have cited. After all, there is an overestimation of definitely_needed in the vacuum interval.
 
> I suspect the only possible approach here is to be extra careful when detoasting attributes of RECENTLY_DEAD tuples, and > just skip RECENTLY_DEAD tuples if they are missing any parts of their externally toasted attributes.
 
I've also been thinking about the approach of handling missing TOAST data without stopping the index scan. However, I have concerns about this approach.
 
The "missing chunk number" error can indicate actual data corruption, not just a race between heap and TOAST cleanup. We risk masking genuine storage corruption that should be surfaced to the user.
 
I will try to implement patch with careful handling the error of missing data from the visibility race between toast and the main table error in the near future. Based on your experience, can you tell me what I should pay attention to first of all when implementing?
 
Best regards,
Ekaterina Testova, Postgres Professional

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Тестова Екатерина 2026-07-08 07:43:47 Re: VACUUM FULL or CREATE INDEX fails with error: missing chunk number 0 for toast value XXX
Previous Message Heikki Linnakangas 2026-07-08 07:25:27 Re: pgsql: Cleanup comments/docs around the new shmem request callbacks