Hi Esturo, Le 05/11/2019 à 10:35, Etsuro Fujita a écrit : > Hi Gilles, > > On Sat, Nov 2, 2019 at 1:29 AM Gilles Darold <gil...@darold.net> wrote: >> As per the following code, t1 is a remote table through postgres_fdw: >> test=# BEGIN; >> BEGIN >> test=# SELECT * FROM t1; >> ... >> >> test=# PREPARE TRANSACTION 'gxid1'; >> ERROR: cannot prepare a transaction that modified remote tables >> I have attached a patch to the documentation that adds remote tables to the >> list of objects where any operation prevent using a prepared transaction, >> currently it is just notified "operations involving temporary tables or the >> session's temporary namespace". > I'm not sure that's a good idea because file_fdw works well for > PREPARE TRANSACTION! How about adding a note about that to the > section of Transaction Management in the postgres_fdw documentation > like the attached?
You are right, read only FDW can be used. A second point in favor of your remark is that this is the responsibility of the FDW implementation to throw an error when used with a prepared transaction and I see that this is not the case for all FDW. I have attached a single patch that include Etsuro Fujita's patch on postgres_fdw documentation and mine on postgres_fdw error message with the precision that it comes from postgres_fdw. The modification about prepared transaction in PostgreSQL documentation has been removed. -- Gilles Darold
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c index 7cd69cc709..077eaf46ee 100644 --- a/contrib/postgres_fdw/connection.c +++ b/contrib/postgres_fdw/connection.c @@ -725,7 +725,7 @@ pgfdw_xact_callback(XactEvent event, void *arg) */ ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), - errmsg("cannot prepare a transaction that modified remote tables"))); + errmsg("cannot prepare a transaction that has operated on postgres_fdw foreign tables"))); break; case XACT_EVENT_PARALLEL_COMMIT: case XACT_EVENT_COMMIT: diff --git a/doc/src/sgml/postgres-fdw.sgml b/doc/src/sgml/postgres-fdw.sgml index 634a7141ef..ed369cb54b 100644 --- a/doc/src/sgml/postgres-fdw.sgml +++ b/doc/src/sgml/postgres-fdw.sgml @@ -483,6 +483,12 @@ COMMITTED</literal> local transaction. A future <productname>PostgreSQL</productname> release might modify these rules. </para> + + <para> + Note that it is currently not supported by + <filename>postgres_fdw</filename> to prepare the remote transaction for + two-phase commit. + </para> </sect2> <sect2>