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 1vywXL-000YjS-0h for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Mar 2026 18:38:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vywXH-0099lF-1K for pgsql-hackers@arkaria.postgresql.org; Sat, 07 Mar 2026 18:37:59 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vywXG-0099l7-2Y for pgsql-hackers@lists.postgresql.org; Sat, 07 Mar 2026 18:37:59 +0000 Received: from mail-dy1-x1334.google.com ([2607:f8b0:4864:20::1334]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1vywXF-0000000123K-0Q18 for pgsql-hackers@lists.postgresql.org; Sat, 07 Mar 2026 18:37:58 +0000 Received: by mail-dy1-x1334.google.com with SMTP id 5a478bee46e88-2b6b0500e06so12651672eec.1 for ; Sat, 07 Mar 2026 10:37:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1772908676; cv=none; d=google.com; s=arc-20240605; b=fC4FTC7BYDcBmqnnNKdw3qS9Xr3YRRpQzjSxFSTfQl14pjnop0tQPz105+8rn2Zx6b Ox+JyI9VypYRa8A7SRMglSqWxA+BP2Sm3cihdv7iy8OHbB0CYlY4SILxbEdAMyWFsPV9 DMEi9ToHogn21C+M1Yb+X4/Pow+1unKERUDupIZT+83auXhc4lRbhT/4Qzh/thtv6Vuf RejYTEajfnDjuyyECOuOgzs8CQ7BXRGtW0FjfH20NV8liMkASt1cvmoCvEbZGFEtPwSG B8++QvEiN33BRZpOIH6LWit3MHVSR7bqKh15r/YGKiulonqxkVmFUcGpkFCYSrNJo3Yf qpgg== 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=5oyOQBApusVPa4d44RLT+QgbmxtyGXBJ0tcr7g0+miU=; fh=1M5gLIcRnymsdhtJdbXtQKMeee1KoZYlKEJfe8lkkNw=; b=flDV9mTe4c7xQVfcMf3VvEEamV9VQ0YGZZd88kRUV2dhgg9ujbdCQAw7OuFiKxJcbJ HcO88ilPRRyXrfTv2Ej37PL7j3Gp1uRNgAROd2QX/zIhgewezTaE7+7qRYI+cOm5EySD rkeAs9yU0rVTdffpWfRj2aNV85YZ7rs7JSTXWQHH8gAOsKBLPJABIGZVv8CLF1S3b7zX bm5DBx6K/2RupPSMAV3SwytWAcRyHc6RDDW/SmdASp4mRPGNwCmvP3+0A4c4xFihC9Nw milNPm+vcdnTnc8KpSPJ7nuOZXxPJuaxqtP7V5bgWKqMRcutz9wD8X6J2txgQTWi7fnZ 9p6A==; 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=1772908676; x=1773513476; 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=5oyOQBApusVPa4d44RLT+QgbmxtyGXBJ0tcr7g0+miU=; b=fd2PuGnfYubgFzcFkpvZZerNNW5zkfr/AaTAOP6LrT4jSVMw+sSBc7avW3tObInLdT 0g5QvhuD90gU8shCWg+d4iiKH+pHKfzpU24j5wPzof3WHz0/kakiV3U2D2TD+kwzJ6RT SxuWhzTlAs7ZbWLzJ3Od5+EzbO7zxA4Vh/LrDucQ7xU3cYEH7a+3LzGb7k1qJgkskuVL 0loIj0h1zTWLtaxUGNJTPgAXoIn1/y3ugr+fYkmIQiKyrwydvbDLoUWKx4O72mjvKhuo nUURRTQXgmdb+D2KOvNDQtZJTs021v4AuT5Mr3XueTlvrcpUOhrdwGFxk6V3cjS+TpN0 9gLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772908676; x=1773513476; 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=5oyOQBApusVPa4d44RLT+QgbmxtyGXBJ0tcr7g0+miU=; b=w6BzMe/u0vj/Llk/0qikAZrMVCW5NtGeEDslvKIDoyQepsGhfo73ZL2SlC3c2OlZua 84kFuO9+qtz5+TLv0p6+jjSc30lSuBbCWGvAu3HIhxQ8KAs/Qb8w8QoBjHgPgoyOi8LT /HKwBrRkn6WCOq7ciNf/G2ama+K/F84A2VilFiPyrchC1h71wlBcDEjh0vsqDMma25BB qn34u37nCRzfnjqiKGXNBWGDSoVAzyKhqjx0Dq2e9+7s7cUiT3HKY0XCkZlb3on1TLXZ EwHBqBZJuRUgcISu9xfbwRbEW7ISJbxLOi3ATBxxIPFqO+fJ/tLa9kn2AkNfQRBBC5C8 f6uQ== X-Forwarded-Encrypted: i=1; AJvYcCWzFr4kkTwrR3Z727tQwOm1pTtdpoPBpRsxDgyvDYpSXFMwzK0whS3UNQTtXDLXy0OnvzcNWlMddkr/Izks@lists.postgresql.org X-Gm-Message-State: AOJu0Yzmzd6hDOhusEh5fSZ55TOEOTisk35FuBQURrwLTv72zTamQBaG RvOrGRH4K+00yUz/qdJWsuHDMbT9DdyqiwnBKu0LU0JS8nPxcfIH01He+VUsQ95w9ffxE8lmsYn Ii1u/vF6nmPGgUpL7+96T+KzcxOWN5iI= X-Gm-Gg: ATEYQzwVvsxG/L+AeC4vcWuuUGpAT6UA/okce55PtbXJC1RRScrww0ZjC+akbdvS9PQ UwC4d5rwxnlNuKAb32ZBkt9gD1usQ0oLnBDXW1dwN7cXhIbrcOgC8N9HHttnKUOtoMfHTmUKbby jPP+hbtdc8FOd6w4c8SrQVNrhDHKH883M8ssrTl4MKpFiOwUdxSJRkGOt6tUkaRMC+hnCPvjpFa qsi873tQmIdbZJ0vU03wjNiMU8kHF3U4qXvhAHnQNqL3bmkm7EhmXxxTXl79VIZqfIMVOQi86j5 Xr72Fupu06y/WAI8K8rkg8zT+C7+V/VheUXP2nmlS5skv4477yAGy5xd5SKRA5RYBFlq6tuvA2p USwryUbDsy0Xtq+RdlNFF5wxRTRzh+0uZ6SUKlLQC X-Received: by 2002:a05:7300:ed03:b0:2be:2842:e116 with SMTP id 5a478bee46e88-2be4e03d15cmr1997273eec.22.1772908676055; Sat, 07 Mar 2026 10:37:56 -0800 (PST) MIME-Version: 1.0 References: <3660951.1741016970@sss.pgh.pa.us> In-Reply-To: From: Etsuro Fujita Date: Sun, 8 Mar 2026 03:37:44 +0900 X-Gm-Features: AaiRm50I-APYfzhhLpHWI9VbldLklUf9u7JuIUs6So0pHdBc96gYd7cpjo4_p1E 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: Fujii Masao Cc: Ashutosh Bapat , 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 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 transac= tion > starting in read-write mode while the corresponding local transaction on > the standby is read-only). > > On the other hand, this change would force any remote transaction initiat= ed by > a standby transaction to start in read-only mode, completely preventing i= t from > modifying data. Because transactions on a standby always start as read-on= ly, > the remote transaction would also always be read-only under this proposal= , > 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. Anyway, I would like to know what other people think. Best regards, Etsuro Fujita