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
PostgreSQL Database Management System
This directory contains the source code distribution of the PostgreSQL database management system.
PostgreSQL is an advanced object-relational database management system that supports an extended subset of the SQL standard, including transactions, foreign keys, subqueries, triggers, user-defined types and functions. This distribution also contains C language bindings.
Copyright and license information can be found in the file COPYRIGHT.
General documentation about this version of PostgreSQL can be found at https://www.postgresql.org/docs/19/. In particular, information about building PostgreSQL from the source code can be found at https://www.postgresql.org/docs/19/installation.html.
The latest version of this software, and related software, may be obtained at https://www.postgresql.org/download/. For more information look at our web site located at https://www.postgresql.org/.