pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amit Langote <amitlan@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Refuse RI fast-path row locks in read-only transactions
Date: Thu, 08 Oct 2026 03:05:42 +0000
Message-ID: <E1xEeRy-00000000lPm-1bTI@gemulon.postgresql.org> (raw)

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
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2f840afbf52e869e0c0824179190a545538f07cc

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(+)



view thread (2+ messages)  latest in thread

Message-ID: <E1xEeRy-00000000lPm-1bTI@gemulon.postgresql.org>
Permalink:  ../E1xEeRy-00000000lPm-1bTI@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1xEeRy-00000000lPm-1bTI@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: amitlan@postgresql.org
  Subject: Re: pgsql: Refuse RI fast-path row locks in read-only transactions
  In-Reply-To: <E1xEeRy-00000000lPm-1bTI@gemulon.postgresql.org>
  References: <E1xEeRy-00000000lPm-1bTI@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox