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.94.2) (envelope-from ) id 1tp5Gg-000HkJ-3P for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Mar 2025 12:51:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tp5Ge-006sV8-Bc for pgsql-hackers@arkaria.postgresql.org; Mon, 03 Mar 2025 12:51:32 +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.94.2) (envelope-from ) id 1tp5Ge-006sSb-1i for pgsql-hackers@lists.postgresql.org; Mon, 03 Mar 2025 12:51:32 +0000 Received: from mail-vk1-xa2d.google.com ([2607:f8b0:4864:20::a2d]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1tp5Ga-000hny-0Q for pgsql-hackers@lists.postgresql.org; Mon, 03 Mar 2025 12:51:31 +0000 Received: by mail-vk1-xa2d.google.com with SMTP id 71dfb90a1353d-5236d34a37fso806282e0c.3 for ; Mon, 03 Mar 2025 04:51:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741006287; x=1741611087; 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=C1Fh6OThwwp2jBU0tyuaGDFMVrsxbvL02pRoMlwSsCI=; b=fV91k/dwk1G5CwjtWB9loWcAIEGa6w6Vjv2yYwyQxpJFNF4CFrJtXhAcOYCuvP1mFN Y5R3GPQ+1D9ogxgKu7iUVR8drAmOU9qhAfPB3y9QgRS2LoWVdFJ7xGkKQ4X1ypaJ+vqv ++a1A8gPMxHhpVRZ3WTds7PILmAO8Bd+4TdyERiywkJ6/z32dFzcaWPqlSYlkEQKC3e0 PV04jgfwxMTtWiHbTyJ7kcqJzh9EBBs2bu1VBa3ULFCgRNzsAoym48XR/9XFXzj8VaJX FiiVXlj19Oh6reDP+GW7zULHF3K/ZhQDMdBGBBo48IAnnXg83Aak378ehxaQMDyGovEq 0LqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741006287; x=1741611087; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C1Fh6OThwwp2jBU0tyuaGDFMVrsxbvL02pRoMlwSsCI=; b=ZS6hdy0zzOcdA7UF9vFC365k0vVTuuwFfsk1wcO5EUDGCvdDxoDNfFUj6VhX5T4sYA r0rI/hw72hGvqTm14EaGHGaL5nolCRfaU5lBT14I6apSXH/sjq+Id8SwCtxn6ToqY+64 /F7oY9LSSDv8areCEPFEwxhJ6396ZNkWu1Xm9QVLl5KwFAqnGFOzCUFYRTfebSgZwXPC EXaso7cLl5kD0BTIY3hWjeVMvirU4CPaN8kxN/Zz+3EBgzTMI378lwpdz3Z1G8CC2Lnn 9mWyD0PLjyoj9n6AZI3fxn+8XR/zlUNz5Ir/T3I7vchJglRqpaJlFtq0dvUJ96itOR5b MjdA== X-Gm-Message-State: AOJu0Ywslj48NzGzBSI/GjVcZ2DD40ablcFm8pPmF7rlXrNbJSzHe9Gz UVCS4FW4W+ezKi1noLpk7dLzU20wnQMC5ogK6De5UjmV65ODjsEHgZHariF9N8H1ivCOlg4C0a8 6JXrVqI029hsUcY7kIgNvNjZ2M1M= X-Gm-Gg: ASbGncsgUf3pcf0N69u5GejJIWABTGHvNEmBr5/USytnqQBAIMpLHBv/db5xEMfcLx/ 1nTjokCvaPLjCadK0z8FofOYwqVME1tWZCsgFC3C6YIG/qdZD1+WNTim9QRLjDoJT71N7WGqEAZ t00VWtER2H4I8fo4nvXAqRSw5EkGcg X-Google-Smtp-Source: AGHT+IGOXHUn56aCv/XqZV0ngN6H3znC9wO/t3Kltp2dD3p2vbMlp34bTiZOQ/IElmcq4HyM3XA/zWWodSQBhRnx9PQ= X-Received: by 2002:a05:6122:2897:b0:520:3987:ce0b with SMTP id 71dfb90a1353d-5235b519bf9mr8019280e0c.2.1741006287471; Mon, 03 Mar 2025 04:51:27 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Ashutosh Bapat Date: Mon, 3 Mar 2025 18:21:15 +0530 X-Gm-Features: AQ5f1JrqdVuVrNjwpJR5UvucWkWW5hilrzqZ9iDLQru4gJAvWyKkHXfxrYrgPuc 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: 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 Hi Fujita-san, On Sun, Mar 2, 2025 at 5:14=E2=80=AFPM Etsuro Fujita wrote: > > Hi, > > postgres_fdw opens remote transactions in read/write mode in a local > transaction even if the local transaction is read-only. I noticed > that this leads to surprising behavior like this: > > CREATE TABLE test (a int); > CREATE FUNCTION testfunc() RETURNS int LANGUAGE SQL AS 'INSERT INTO > public.test VALUES (1) RETURNING *'; > CREATE VIEW testview(a) AS SELECT testfunc(); > CREATE FOREIGN TABLE testft (a int) SERVER loopback OPTIONS > (table_name 'testview'); > > START TRANSACTION READ ONLY; > SELECT * FROM testft; > a > --- > 1 > (1 row) > > COMMIT; > SELECT * FROM test; > a > --- > 1 > (1 row) I am having a hard time deciding whether this is problematic behaviour or not. Maybe the way example is setup - it's querying a view on a remote database which doesn't return anything but modified data. If there is no modification happening on the foreign server it won't return any data. Thus we have no way to verify that the table changed because of a READ ONLY transaction which is not expected to change any data. Probably some other example which returns all the rows from test while modifying some of it might be better. > > The transaction is declared as READ ONLY, but the INSERT statement is > successfully executed in the remote side. > > To avoid that, I would like to propose a server option, > inherit_read_only, to open the remote transactions in read-only mode > if the local transaction is read-only. Why do we need a server option. Either we say that a local READ ONLY transaction causing modifications on the foreign server is problematic or it's expected. But what's the point in giving that choice to the user? If we deem the behaviour problematic it should be considered as a bug and we should fix it. Otherwise not fix it. > > I would also like to propose a server option, inherit_deferrable, to > open the remote transactions in deferrable mode if the local > transaction is deferrable. The documentation about deferrable is quite confusing. It says "The DEFERRABLE transaction property has no effect unless the transaction is also SERIALIZABLE and READ ONLY." But it doesn't tell what's the effect of deferrable transaction. But probably we don't need a server option here as well. --=20 Best Wishes, Ashutosh Bapat