Re: BUG #19519: REPACK can fail due to missing chunk for toast value

From: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>
To: Konstantin Knizhnik <knizhnik(at)garret(dot)ru>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Konstantin Knizhnik <konstantin(dot)knizhnik(at)databricks(dot)com>, Rui Zhao <zhaorui126(at)gmail(dot)com>, Michael Paquier <michael(at)paquier(dot)xyz>, Andrey Borodin <x4mmm(at)yandex-team(dot)ru>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Srinath Reddy Sadipiralla <srinath2133(at)gmail(dot)com>, Imran Zaheer <imran(dot)zhir(at)gmail(dot)com>, Alexander Lakhin <exclusion(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: BUG #19519: REPACK can fail due to missing chunk for toast value
Date: 2026-12-01 16:48:04
Message-ID: CAEze2WjKdoZWbOFx5HC12KVgPmYkKgSz3rzJTtHMf=MZxs27YA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, 1 Dec 2026 at 16:05, Konstantin Knizhnik <knizhnik(at)garret(dot)ru> wrote:
>
> - Rewrite (CLUSTER, VACUUM FULL, REPACK): as you said, we hold
> AccessExclusiveLock on the TOAST relation, so nothing can disappear
> once the rewrite has started.

How sure are you about that? On-access pruning happens
(opportunistically) for every heap page accessed, and if the
GlobalVisHorizons for that toast table change at any point while we're
still accessing it, then we might still prune away tuples in the toast
table next time we try to access that tuple.

See heapam_index_heap_fetch(); it calls into heap_page_prune_opt()
whenever the heap page holding the tuple corresponding to the index's
result is first loaded into memory.

The only valid xmin horizon we can rely on here is one that's
protected by our own PROC entry's xmin; every other xmin might
disappear and cause the GlobalVisHorizons to change, and prune away
old toast tuples. And even that xmin is not necessarily correct,
because visibility horizons for a relation we're accessing could have
been higher than our xmin.

> The TOAST data of a RECENTLY_DEAD tuple
> is checked at scan time, and if it is gone, the tuple is treated as
> dead and passed to rewrite_heap_dead_tuple(), as for any other dead
> tuple. That also takes care of update chains stashed in
> rewriteheap.c, with no extra bookkeeping. The sort path no longer
> inlines anything into the tuplesort.

That's causing a regression from earlier versions of this patch, as
those toast tuples may still be removed concurrently. See above for
why.

-Matthias

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kirill Reshke 2026-12-01 16:57:09 Re: JIT inlining: "tupdesc reference ... is not owned by resource owner Portal" (inlined code uses a cloned tupdesc_resowner_desc)
Previous Message Tom Lane 2026-12-01 16:42:59 Re: btree_gist: <-> fails on same-sign infinite intervals