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, Rui Zhao <zhaorui126(at)gmail(dot)com>, Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, Robert Haas <robertmhaas(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-02 23:40:38
Message-ID: CAN4CZFOvDuswBRfxxEBC6z0kasHE1tK-NVj9suT7TZc8P5G1CA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

+ * Our AccessExclusiveLock on the TOAST relation keeps VACUUM and
+ * other backends out of it, but our own TOAST fetches prune its
+ * pages too, and the horizon they use can still advance up to
+ * stable_xmin. So if any of the tuple's TOAST data was deleted
+ * before stable_xmin, it is inlined now, as it could be gone by
+ * the time the tuple is written out.

Isn't this a common case?

-- session 1
CREATE TABLE t (id int, data text);
ALTER TABLE t ALTER COLUMN data SET STORAGE EXTERNAL;
INSERT INTO t SELECT g, repeat('x', 100000) FROM generate_series(1, 2000) g;
-- session 2
BEGIN ISOLATION LEVEL REPEATABLE READ; SELECT 1;
-- session 1
UPDATE t SET data = repeat('y', 100000);
VACUUM FULL t;

This peaks at 250MB, already 640MB with 6000 rows, and so on.

Do we need the inlining at all?

We hold an AccessExclusiveLock on the old TOAST relation, taken before
OldestXmin is computed. During the rewrite only heap_page_prune_opt()
in our backend can remove chunks. Couldn't
heapam_relation_copy_for_cluster() disable on access pruning for that
one relation while it runs? The file is dropped at the end anyway.
Then the check during the scan is enough, and stable_xmin and the
second pass can go away.

In response to

Browse pgsql-bugs by date

  From Date Subject
Previous Message Jeff Davis 2026-12-02 22:55:51 Re: Regex fails to capture group consisting of empty string in non-greedy case