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

From: Mihail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Amit Langote <amitlangote09(at)gmail(dot)com>
Subject: Re-read conindid under the referenced table's lock in the RI fast path
Date: 2026-08-05 13:55:52
Message-ID: CADzfLwVZ2wi3hQxC=8FA5YC_nco2JWhkOzZ-JV7UxYYvTMKwGw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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).

Best regards,
Mikhail.

[0]: https://www.postgresql.org/message-id/flat/CA%2BHiwqGXcHnrYD1BoXRwNat3QdtbsYZEZrexnPET_QGtMY%3DTZQ%40mail.gmail.com#7f2abf87c94a7cab580ca706173eef24
[1]: https://www.postgresql.org/message-id/flat/CADzfLwUJiVuv69uwuF5z4TrMhNkVwQUXW03q%2BuVNwmYFLtjEhw%40mail.gmail.com#c24c93342bc3e8dda8e8b1a20006f652
[2]: https://www.postgresql.org/message-id/flat/CADzfLwXj_9rz3XGSBVzJ%3DHdWXt6VMp8h2tAC1e_49yDBESUg-A%40mail.gmail.com#df01faff9903abe706dfa15e0789e78d

Attachment Content-Type Size
v1-0001-Re-read-the-FK-constraint-after-locking-the-refer.patch text/x-patch 17.4 KB
nocfbot-X-0002-Reproducer-RI-fast-path-accepts-a-row-whose-refer.patch text/x-patch 10.3 KB
nocfbot-X-0003-Re-read-conindid-under-the-referenced-table-s-loc.patch text/x-patch 3.5 KB
nocfbot-X-0001-Reproducer-RI-fast-path-opens-an-index-a-concurre.patch text/x-patch 9.2 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2026-08-05 14:23:49 Re: [PATCH] Remove unused scram_client_key_len and scram_server_key_len fields
Previous Message Shinya Kato 2026-08-05 13:27:19 Add TOAST statistics columns to pg_stat_all_tables