Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vzRaq-0010if-39 for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2026 03:47:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vzRao-00DQCm-0T for pgsql-hackers@arkaria.postgresql.org; Mon, 09 Mar 2026 03:47:42 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vzRan-00DQCd-2e for pgsql-hackers@lists.postgresql.org; Mon, 09 Mar 2026 03:47:42 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vzRal-00000001jT8-353T for pgsql-hackers@lists.postgresql.org; Mon, 09 Mar 2026 03:47:41 +0000 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-439b790af67so4488681f8f.0 for ; Sun, 08 Mar 2026 20:47:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773028054; cv=none; d=google.com; s=arc-20240605; b=eM9kwYuoEiRgAzDWpVEJFphe5cglegv3GDHA5r0i1Jm+mgh23ukXpXbr1/KfItlPaW +TPcu6yFPL6h74/cWfinbV9IlckeTlSHXUkgDpiLdEHWo0WLJJyx4uvAujyor/l3Yyg1 7j7i3cd3xNb8TVj+/43esgU0lYFJweW55BWXvfRivrSJ5wd1xuGtfrzoDjZ1khpc7gTg UfFF+F9o4BxS8rdQGuWu2wDBrUwagdnLApWaBeoQ5sFWEDdliI4nYiIS5e7RMt3pcHTv CFTwKsMb95ky9Ha+L9CpghPA1J7qnKozbMmAyZMIZXhgr/EJApwc9khpD4ySYUGJPiXJ AXJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=NbRbzHc9jfBICSSumsLpqLtpatsbv1n5YC5ulMNQUYo=; fh=mOGLAU2C85vXwdZvVBVMdl2PXB48zH9pIsq5tgqloLY=; b=N+3Ef41mb9VcdbXVXm7gScDIEHPzUWlEq7GPvU+6Yvl1HBbxFQqbTdrMV8kVpCWxiA MGItj135ZXTovrTLdfwfFZOFIzPfej7AvwbsWEApZmc1H/cXytf4GT9b3esI6CNjLhMZ KQRX/PMWNxPPesbeRst1x9yjoP7T5aaqe07whRrQUnFIEZeIWugRDYjUNX7eEyrIzeYX 91lUnpDIq0l1K7uY01DK5CcOf5/GN5ySmxzmOuCJDy7G9EbmQ820Llps8ZlULxORqitG 19gcJjzbQ+xq6UT8E/aSabG08hT7zoyvtw4331iWtYQAlE7/wrwoQByeH3DyF+6ggVNi m1gA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773028054; x=1773632854; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=NbRbzHc9jfBICSSumsLpqLtpatsbv1n5YC5ulMNQUYo=; b=HRP+ux+a9RAFP0p851oEyTtN9cRcKepaZQvMRAe2lpbKq7fzQLTm115m8j2HDCSN31 Mj8NOsqb0Wj8r0hzuvKrWC2tNWWtvsqlXvOzF+M3dPPeq6Y3UbLw6P1oUJcgupaHZBt4 n9PMWhwGWueUMSZHUtDJFj+7dYi7TOcpgW/lCcAdRSHjncZjlb68zDUeagTRc78/eru/ NzYbRAL4216cX1ZfekLEPPJ7zkAHZ0ZeX9ej03N0ZesDbAqgjg7sw2sIz2aIi9G0j24Q El0WtPJWiwME426r+G24jl23kwU6nD71C3l3xtvttdymJFE1oQfPV0aHIGtipDQHS8iX mFoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773028054; x=1773632854; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=NbRbzHc9jfBICSSumsLpqLtpatsbv1n5YC5ulMNQUYo=; b=qI58+h4++UpU8DIAghhk3dAJZ1qSC9lvOCWfY553ZXdJXsYagx+Akj4HUFUjSKSlHs tro9JKaeWtNbK+uJGtYBLbSflkxkzmMlbRk3lywkCvk8GlWNh6RyXv0c0POct0Be4Icm Suuzv289rjX/BeEK3/9hBcm+oPyKtqZb3oGn1mYU6m3SC+R8wSWzbgWuX/OKO+Z6MuVo iX2QrocopRz+ho3pPBSPraCNPpiD3Z0mXq1KG8EcX39CwdYxm9ZRxSr/U5tNlSnRo6vd N/lrs20gLzAO+E1gb915/7DKYeGVRThcfxMYrmiLi7VyRKXgcG8W26PLifoguogjS5il mRyw== X-Forwarded-Encrypted: i=1; AJvYcCXSld+5tRfumUvb0CkCMvsbnKxd/kd9riEpSFHnxCA8H3ZTf4S2K4041skFK+b6S3t5tkUXEEHFHubzLypT@lists.postgresql.org X-Gm-Message-State: AOJu0YyOAuRCUdehNhLCXIF/lLyUUoCpIVeE82CLLPTMF11zKcVnEL8I 5jZQMM+E51cbY8MkxsUuOIio4B+5rq45yEcp73AhvRlmMKKpx0ZC3YxRo0SA9bOzMI+7eKl/m/w 1zBDVDmpERmeOMkH2xRl/o3OE56YGIGQ= X-Gm-Gg: ATEYQzw07EC6hfAjTLtoGd4sev4VX0kjX/FhVItwiFt2zRBoHabdrpUpDKBRe28LUmT k/qebqtwJseRzmg1GJVgoPOjP4WFk/uopYpXV4OzxPr4mkZNShHJsPA/Tp8mdQ87VvixhlzIizR 5cq+T5MT1/ayC5HGOOYy9AVw3D7apn8vCmL4H/RTz2Y/IzW/cYaTzasyfBtEKHrZUXwH6RxRSL5 NH0l86h/OYpFVUtqZDO86ODpoEZ+gHx+PK6sdftZtO8UyWRmURUYXMThLpcWzJSrGemAKpGKP1+ Zp5Jq+gJ0qKK5anObJ6Z0tILJ4/kbkA9fb0gwJbHYgJq45BqXH+4 X-Received: by 2002:a05:6000:178b:b0:439:c8b3:a3e9 with SMTP id ffacd0b85a97d-439cfd65977mr24583376f8f.14.1773028053915; Sun, 08 Mar 2026 20:47:33 -0700 (PDT) MIME-Version: 1.0 References: <3660951.1741016970@sss.pgh.pa.us> In-Reply-To: From: Ashutosh Bapat Date: Mon, 9 Mar 2026 09:17:21 +0530 X-Gm-Features: AaiRm52x_eMnM1IxH-n7C8llSqXMFgwhZArN1eoULcQoylURMlEFDfBRu469Aqk Message-ID: Subject: =?UTF-8?Q?Re=3A_Options_to_control_remote_transactions=E2=80=99_access?= =?UTF-8?Q?=2Fdeferrable_modes_in_postgres=5Ffdw?= To: Etsuro Fujita Cc: Fujii Masao , Tom Lane , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sun, Mar 8, 2026 at 12:07=E2=80=AFAM Etsuro Fujita wrote: > > On Thu, Mar 5, 2026 at 12:11=E2=80=AFPM Fujii Masao wrote: > > I haven't yet realized the benefit from this change since I haven't > > encountered issues caused by the current behavior (i.e., a remote trans= action > > starting in read-write mode while the corresponding local transaction o= n > > the standby is read-only). > > > > On the other hand, this change would force any remote transaction initi= ated by > > a standby transaction to start in read-only mode, completely preventing= it from > > modifying data. Because transactions on a standby always start as read-= only, > > the remote transaction would also always be read-only under this propos= al, > > with no way to make it read-write. > > > > I'm concerned that this could break certain use cases without providing > > a clear benefit. > > Thanks for the comments! > > The benefit is to make read-only transactions using postgres_fdw > ensure read-only access. We discussed this in a Postgres developer > meetup held at Yokohama in Japan last Friday. Let me explain again. > Here is an example I used in that meetup to show the current behavior > of such transactions: > > create server loopback > foreign data wrapper postgres_fdw > options (dbname 'postgres'); > create user mapping for current_user > server loopback; > create table loct (f1 int, f2 text); > create foreign table ft (f1 int, f2 text) > server loopback > options (table_name 'loct'); > insert into ft values (1, 'foo'); > insert into ft values (2, 'bar'); > > They disallow INSERT/UPDATE/DELETE, which is good: > > start transaction read only; > insert into ft values (3, 'baz'); > ERROR: cannot execute INSERT in a read-only transaction > > start transaction read only; > update ft set f2 =3D 'xyzzy'; > ERROR: cannot execute UPDATE in a read-only transaction > > start transaction read only; > delete from ft; > ERROR: cannot execute DELETE in a read-only transaction > > But if referencing foreign tables mapped to a remote view executing > functions that modify data at the remote side, they can modify the > data, which would be surprising: > > create function locf() returns setof loct language sql as > 'update public.loct set f2 =3D f2 || f2 returning *'; > create view locv as select t.* from locf() t; > create foreign table fv (f1 int, f2 text) > server loopback > options (table_name 'locv'); > > start transaction read only; > select * from fv; > f1 | f2 > ----+-------- > 1 | foofoo > 2 | barbar > (2 rows) > > The root cause of this is that postgres_fdw opens a remote transaction > in read-write mode even if the local transaction is read-only, so the > patch I proposed addresses this by inheriting the read-only property > from the local transaction. > > I didn't think of the use cases where postgres_fdw is used on a > standby server, so I overlooked the breakage you mentioned above, but > I got a lot of positive feedback from many participants regarding > ensuring read-only access by that change. So I strongly believe the > patch is the right way to go. I think it's unfortunate that it causes > the breakage, though. I might be missing something, but I think a > solution for such a use case is to use other DB integration tool like > dblink. If the primary doesn't allow modifying data in the foreign table in a read-only transaction, a standby shouldn't do that either. The users who are expecting a read-only transaction to protect against any writes to the foreign data on primary will also expect so on the standby. If users want to use standby's ability to modify foreign data for the sake of load balancing, that's a reasonable ask. However, we need to figure out whether it's common enough to support. That information is not readily available. I doubt that it's a common usecase. If this fix breaks such applications, we will come to know its spread. And such applications can use dblink. Alternately we can add the option which I and Tom didn't like [1]. But I feel we should do that only if there are complaints. It's going to be painful to those users who experience application breakage. To ease that pain we should highlight this as a compatibility break change in the beta release notes, giving users a chance to complain during beta cycle so that we can fix it by GA. If others know that the current behaviour has a widespread consumption, and they can provide backing data, adding the option right away is better. [1] postgr.es/m/CAExHW5vOH-=3D1KhaL8S4xVVzSozvrbmbBVg97p0obwEW3sD57Cw@mail.= gmail.com --=20 Best Wishes, Ashutosh Bapat