Re: Re-read conindid under the referenced table's lock in the RI fast path - Mailing list pgsql-hackers

From Amit Langote
Subject Re: Re-read conindid under the referenced table's lock in the RI fast path
Date
Msg-id CA+HiwqGtxb-nfd-7kQvddO-Yva=d-ewvwEMYBRWEwiTBoXWgng@mail.gmail.com
Whole thread
In response to Re-read conindid under the referenced table's lock in the RI fast path  (Mihail Nikalayeu <mihailnikalayeu@gmail.com>)
Responses RE: Proposal: Conflict log history table for Logical Replication
List pgsql-hackers
Hi Mihail,

On Wed, Aug 5, 2026 at 10:56 PM Mihail Nikalayeu
<mihailnikalayeu@gmail.com> wrote:
>
> Hello, everyone!
>
> As was asked in [0] I have created a separate thread for [1].
> Also, I realized that [1] and [2] is the same issue (sorry, I lost a
> bit in them all).
>
> Short quote from commit message:
>
> > The RI fast path looks up the constraint, takes RowShareLock on the
> > referenced table, and opens the index conindid names.  Reading conindid
> > before that lock is not safe.  REINDEX CONCURRENTLY repoints the
> > constraint at a new index and then drops the old one, and it waits only
> > for backends holding a lock on the referenced table; a backend that has
> > read the constraint but not yet taken that lock is not one of them.  It
> > then opens an index that is already gone, and the write fails with
> > "could not open relation with OID"
>
> Main patch\reproducer is v1-0001, nocfbox-X series also provide a
> reproducer for the data corruption (though VACUUM is also involved).

Thanks. Attached is v2 of the patch posted here. I adjusted the commit
message and comments, kept you credited as Author, and replaced the
Opus co-author trailer with a disclosure sentence, which I can remove
if you so prefer.  I have noticed only one such disclosure in the
commit log so far.

I dropped the subtransaction permutation from the test suite because
the pending subtransaction-batching patch [1] will duplicate the
batched case. I briefly considered using ALTER TABLE validation to
retain per-row coverage, but since it already holds the
referenced-table lock, it cannot exercise the race the test case was
meant to manifest.

I will push this tomorrow.

[1] https://postgr.es/m/CA+HiwqGHa3tc6MZFSLyLrvwySdrmpkb1TqkH2jGd3HtKGGZ6cQ@mail.gmail.com

--
Thanks, Amit Langote

Attachment

pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: [PATCH] ternary reloption type
Next
From: Amit Kapila
Date:
Subject: Re: Logical replication row filter loses unchanged toasted columns