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

From Mihail Nikalayeu
Subject Re-read conindid under the referenced table's lock in the RI fast path
Date
Msg-id CADzfLwVZ2wi3hQxC=8FA5YC_nco2JWhkOzZ-JV7UxYYvTMKwGw@mail.gmail.com
Whole thread
Responses Re: [Bug]Assertion failure in LATERAL GRAPH_TABLE with multi-label pattern
Re: Re-read conindid under the referenced table's lock in the RI fast path
List 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

pgsql-hackers by date:

Previous
From: Shinya Kato
Date:
Subject: Add TOAST statistics columns to pg_stat_all_tables
Next
From: Matthias van de Meent
Date:
Subject: Re: let ALTER TABLE DROP COLUMN drop whole-row referenced object