| From: | Amit Langote <amitlan(at)postgresql(dot)org> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Refuse RI fast-path row locks in read-only transactions |
| Date: | 2026-10-08 03:05:56 |
| Message-ID: | E1xEeSC-00000000lR1-1Z2o@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Refuse RI fast-path row locks in read-only transactions
The SPI path checks a foreign key with SELECT ... FOR KEY SHARE, which
ExecCheckXactReadOnly() refuses in a read-only transaction unless the
referenced table is temporary. The fast path locks the referenced row
without that check, so for example a deferred check that fires at
COMMIT after SET TRANSACTION READ ONLY succeeded, having locked a row
in a read-only transaction, where the SPI path fails with "cannot
execute SELECT FOR KEY SHARE in a read-only transaction".
Fix the fast path to refuse it the same way so the behavior matches
with checks going through SPI.
Discussion: https://postgr.es/m/CA+HiwqG79XK1oObdZ2AwT660CeJ6s3Mn4LrFPCme-k4L2rF_ag@mail.gmail.com
Backpatch-through: 19
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/c993d9f7c8d4bcada0d5c0bd6ea32416d956fc8f
Modified Files
--------------
src/backend/utils/adt/ri_triggers.c | 10 ++++++++++
src/test/regress/expected/foreign_key.out | 31 +++++++++++++++++++++++++++++++
src/test/regress/sql/foreign_key.sql | 21 +++++++++++++++++++++
3 files changed, 62 insertions(+)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Paquier | 2026-10-08 03:12:59 | pgsql: Fix WAL segment fd leaks with the WAL reading facility (xlogread |
| Previous Message | Amit Langote | 2026-10-08 03:05:42 | pgsql: Refuse RI fast-path row locks in read-only transactions |