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

From: Amit Langote <amitlangote09(at)gmail(dot)com>
To: Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Re-read conindid under the referenced table's lock in the RI fast path
Date: 2026-08-17 13:07:13
Message-ID: CA+HiwqGtxb-nfd-7kQvddO-Yva=d-ewvwEMYBRWEwiTBoXWgng@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Mihail,

On Wed, Aug 5, 2026 at 10:56 PM Mihail Nikalayeu
<mihailnikalayeu(at)gmail(dot)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 Content-Type Size
v2-0001-Fix-RI-fast-path-race-with-REINDEX-CONCURRENTLY.patch application/octet-stream 14.2 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zsolt Parragi 2026-08-17 13:11:17 pg_stat_database.checksum_failures misses single-page failures in backups
Previous Message Peter Eisentraut 2026-08-17 13:03:12 Re: [PATCH] ternary reloption type