Options to control remote transactions’ access/deferrable modes in postgres_fdw - Mailing list pgsql-hackers

From Etsuro Fujita
Subject Options to control remote transactions’ access/deferrable modes in postgres_fdw
Date
Msg-id CAPmGK16n_hcUUWuOdmeUS+w4Q6dZvTEDHb=OP=5JBzo-M3QmpQ@mail.gmail.com
Whole thread Raw
Responses Re: Options to control remote transactions’ access/deferrable modes in postgres_fdw
Re: Options to control remote transactions’ access/deferrable modes in postgres_fdw
List pgsql-hackers
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)

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.

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.

Attached is a small patch for these options.  I will add this to the
March commitfest as it is still open.

Best regards,
Etsuro Fujita

Attachment

pgsql-hackers by date:

Previous
From: Alex Friedman
Date:
Subject: Re: Doc: clarify possibility of ephemeral discrepancies between state and wait_event in pg_stat_activity
Next
From: Alexander Korotkov
Date:
Subject: Re: Get rid of WALBufMappingLock