agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Etsuro Fujita <efujita@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: postgres_fdw: Inherit the local transaction's access/deferrable
Date: Sun, 05 Apr 2026 09:57:14 +0000
Message-ID: <E1w9KED-0033oP-3C@gemulon.postgresql.org> (raw)

postgres_fdw: Inherit the local transaction's access/deferrable modes.

READ ONLY transactions should prevent modifications to foreign data as
well as local data, but postgres_fdw transactions declared as READ ONLY
that reference foreign tables mapped to a remote view executing volatile
functions would modify data on remote servers, as it would open remote
transactions in READ WRITE mode.

Similarly, DEFERRABLE transactions should not abort due to a
serialization failure even when accessing foreign data, but postgres_fdw
transactions declared as DEFERRABLE would abort due to that failure in a
remote server, as it would open remote transactions in NOT DEFERRABLE
mode.

To fix, modify postgres_fdw to open remote transactions in the same
access/deferrable modes as the local transaction.  This commit also
modifies it to open remote subtransactions in the same access mode as
the local subtransaction.

This commit changes the behavior of READ ONLY/DEFERRABLE transactions
using postgres_fdw; in particular, it doesn't allow the READ ONLY
transactions to modify data on remote servers anymore, so such
transactions should be redeclared as READ WRITE or rewritten using other
tools like dblink.  The release notes should note this as an
incompatibility.

These issues exist since the introduction of postgres_fdw, but to avoid
the incompatibility in the back branches, fix them in master only.

Author: Etsuro Fujita <etsuro.fujita@gmail.com>
Reviewed-by: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Fujii Masao <masao.fujii@gmail.com>
Discussion: https://postgr.es/m/CAPmGK16n_hcUUWuOdmeUS%2Bw4Q6dZvTEDHb%3DOP%3D5JBzo-M3QmpQ%40mail.gmail.com
Discussion: https://postgr.es/m/E1uLe9X-000zsY-2g%40gemulon.postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/de28140ded8d4ba00faf905ec3530ffeb8a34a53

Modified Files
--------------
contrib/postgres_fdw/connection.c              | 124 ++++++++++++++++++++--
contrib/postgres_fdw/expected/postgres_fdw.out | 136 +++++++++++++++++++++++++
contrib/postgres_fdw/sql/postgres_fdw.sql      |  80 +++++++++++++++
doc/src/sgml/postgres-fdw.sgml                 |  17 ++++
src/backend/access/transam/xact.c              |  28 +++++
src/include/access/xact.h                      |   1 +
6 files changed, 378 insertions(+), 8 deletions(-)



view thread (13+ messages)

Message-ID: <E1w9KED-0033oP-3C@gemulon.postgresql.org>
Permalink:  ../E1w9KED-0033oP-3C@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1w9KED-0033oP-3C@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 using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: efujita@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: postgres_fdw: Inherit the local transaction's access/deferrable
  In-Reply-To: <E1w9KED-0033oP-3C@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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox