| From: | Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com> |
|---|---|
| To: | Antonin Houska <ah(at)cybertec(dot)at> |
| Cc: | Manu <manuelreyesbravo(at)gmail(dot)com>, shihao zhong <zhong950419(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: REPACK enhancements |
| Date: | 2026-12-06 16:50:00 |
| Message-ID: | CADzfLwVouMApaZzGLBNh+L6S=Dqc-2_6Ar-MbHDkOOosRFm24Q@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi!
On Mon, Nov 30, 2026 at 8:48 PM Antonin Houska <ah(at)cybertec(dot)at> wrote:
> Is the concern that, after the xmin (I suppose you mean MyProc->xmin) being
> invalid for a while, the next snapshot can have its xmin older than the VACUUM
> xmin horizon?
It's an additional safety net: never let xmin become invalid (and do
so multiple times) during the same command, always ensure the backend
owns these snapshot it uses for reads\writes.
Claude found this issue during an AI-assisted review. How it happens:
* backend ask for changes and next snapshot
* worker creates new snapshot and advances slot's xmin to it
* backend is applying data <----- old snapshot is still used but no
more protected
* backend switching to new snapshot
Check the attached reproducer (it is based on UPDATE->INSERT
conversion and TOAST).
One more thing seems to be wrong: current patch uses SNAPSHOT_NEW_HEAP
during final catch-up phase... So, in that case some user-defined code
(predicates and expressions in indexes) may be called with such
snapshot type and access other tables (also changing hint-bits with
rules correct only for repacked-only tables).
> I'm not sure REPACK has such a problem: 1) the heap tuples we copy already
> have the expression values computed, 2) indexes are built in separate
> transactions and CommitTransaction() should complain about an existing active
> snapshot anyway.
Theoretically, it could also be some user-defined opclass....
And maybe one day REPACK CONCURRENTLY may become an engine for
concurrent DDL - so, it may be helpful to think about how it relates
to its possible future form.
> Is it a problem if, after getting the ERROR, the user adjusts the isolation
> level and runs REPACK again?
Another option here is to change the isolation level for the session
during REPACK execution.
This practice is already present for background processes that
override system defaults.
> Yes, it's probably possible to modify the tuplestore / tuplesort as you
> suggest, but I think it'd be trickier than using the auxiliary table.
The same structure may be needed for the CIC/RIC case for unique
indexes... I need to think about it a bit...
BWT, what is about to add [0] (deadlock related) into series?
Mikhail.
| Attachment | Content-Type | Size |
|---|---|---|
| nocfbot-v05-repack-toast-horizon-repro.patch | application/octet-stream | 8.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dean Rasheed | 2026-12-06 17:01:36 | Regression tests that test JIT |
| Previous Message | Yura Sokolov | 2026-12-06 16:39:08 | Another pgbench refactoring. |