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

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Konstantin Knizhnik <knizhnik(at)garret(dot)ru>
Cc: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org, Rui Zhao <zhaorui126(at)gmail(dot)com>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Konstantin Knizhnik <konstantin(dot)knizhnik(at)databricks(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>
Subject: Re: BUG #19519: REPACK can fail due to missing chunk for toast value
Date: 2026-12-04 22:02:26
Message-ID: CA+TgmoausNiYNoJrrg8iHXzwHxdUBb1gMFuqPgLdneP2ttFXGg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Thu, Dec 3, 2026 at 6:38 AM Konstantin Knizhnik <knizhnik(at)garret(dot)ru> wrote:
> I agree, and v12, attached, does that. I also checked that nothing else
> in our backend can make chunks disappear: a TOAST fetch could in
> principle mark index entries as killed, so that later fetches skip
> them, but SnapshotToast ignores xmax, so every chunk tuple is visible
> and heap_hot_search_buffer() clears all_dead before it ever looks at
> whether the tuple is dead to everybody.

Relying on that feels fragile. It feels unlikely that someone would
ever manage to successfully change the semantics of SnapshotToast, but
if they did try to do that, they probably wouldn't notice the effect
on this.

> The changes from v11:
>
> - pruneheap.c gets heap_page_prune_opt_disable(relid), which makes
> heap_page_prune_opt() leave that one relation alone in this backend.
> heapam_relation_copy_for_cluster() calls it for the old TOAST
> relation before the scan, unless it is REPACK CONCURRENTLY, and turns
> it off again after end_heap_rewrite(), which writes out the stashed
> update-chain members. The setting also records the local transaction
> ID, so if the rewrite fails, pruning comes back with the next
> transaction without needing PG_TRY; until then, our backend just
> doesn't prune that relation, which is harmless.

I feel like AtEO(Sub)Xact callback would be the normal way to handle
error cleanup here.

--
Robert Haas
Databricks

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Matthias van de Meent 2026-12-04 22:20:18 Re: BUG #19519: REPACK can fail due to missing chunk for toast value
Previous Message Tom Lane 2026-12-04 21:15:34 Re: BUG #19926: Incorrect join selectivity for <> with NULLs (related to BUG #17545)