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

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: Konstantin Knizhnik <knizhnik(at)garret(dot)ru>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org, Robert Haas <robertmhaas(at)gmail(dot)com>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Rui Zhao <zhaorui126(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-05 22:17:47
Message-ID: CAN4CZFNjs5f00DPVk31oiPGC=EiNqhQanMeE1iTX2O6g90RfYw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> I think that is worth a separate discussion, but it would not replace
> this patch.

and

> Yes. That is why I prefer it to the inlining of v10/v11, which blew up
> memory and sort spill for a common case, as Zsolt showed.

+1, I think this is a good approach for solving the specific issue of
the thread, and at least I couldn't find a better approach. With
v12/v13 the memory issues are gone, and it can be faster and write
less WAL than master depending the exact scenario.

+ * and skip the tuple if that data is gone: nobody can see the tuple
+ * anymore. The TOAST data of the other tuples that we index cannot
+ * go away, as they are live or their deleter is still running.

This is true with ShareLock, however, it can also be called with
ShareUpdateExclusiveLock, as also documented by this comment:

1329 * In cases with only ShareUpdateExclusiveLock on the table, it's
1330 * possible for some HOT tuples to appear that we didn't know about
1331 * when we first read the page. To handle that case, we re-obtain the
1332 * list of root offsets when a HOT tuple points to a root item that we
1333 * don't know about.

That's the case with BRIN summarization (anyvisible=true), which
doesn't block DML, and with that, it contradicts the above comment.

It doesn't seem to cause any issues with REPACK / directly in the
patch, but there's a preexisting VACUUM bug because of it. I'm not
saying that bug should be fixed together with this patch, but the
comment could be improved.

There's one remaining functional issue with the patch: amcheck, which
can still detect the dead entries and complain "toast value N not
found in toast table".

-- session 1
CREATE EXTENSION amcheck;
CREATE TABLE t (id int PRIMARY KEY, data text) WITH (autovacuum_enabled = off);
ALTER TABLE t ALTER data SET STORAGE EXTERNAL;
INSERT INTO t SELECT g, repeat(md5(g::text), 100) FROM generate_series(1, 20) g;
-- session 2
BEGIN;
CREATE TEMP TABLE x (x int);
-- session 1
DELETE FROM t WHERE id <= 5;
VACUUM (PROCESS_MAIN false) t;
SELECT blkno, offnum, attnum, msg FROM verify_heapam('t', check_toast := true);
-- 5 rows: "toast value N not found in toast table"

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Manu 2026-12-05 22:29:33 Re: BUG #19705: One NaN box makes a BRIN box_inclusion_ops index omit unrelated rows
Previous Message Tom Lane 2026-12-05 22:11:16 Re: BUG #19962: pg_dumpall can't produce restorable circular grants with ADMIN OPTION