From 16de716c12055cf7d50dcf2acad1bc929020a0c5 Mon Sep 17 00:00:00 2001 From: wofanzheng <2399541971@qq.com> Date: Fri, 27 Jun 2025 17:07:25 +0800 Subject: [PATCH] =?UTF-8?q?postgres=5Ffdw=E6=8B=93=E5=B1=95=E9=80=82?= =?UTF-8?q?=E9=85=8DXACT=5FEVENT=5FPRE=5FCOMMIT=E5=92=8CXACT=5FEVENT=5FPRE?= =?UTF-8?q?=5FPREPARE=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contrib/postgres_fdw/connection.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/contrib/postgres_fdw/connection.cpp b/contrib/postgres_fdw/connection.cpp index 0432a9d21..3c66d0428 100644 --- a/contrib/postgres_fdw/connection.cpp +++ b/contrib/postgres_fdw/connection.cpp @@ -822,9 +822,22 @@ static void pgfdw_xact_callback(XactEvent event, void *arg) elog(DEBUG3, "closing remote transaction on connection %p", entry->conn); switch (event) { - case XACT_EVENT_COMMIT: + case XACT_EVENT_PRE_COMMIT: pgfdw_xact_callback_commit(entry); break; + case XACT_EVENT_PRE_PREPARE: + /* + * We disallow any remote transactions, since it's not + * very reasonable to hold them open until the prepared + * transaction is committed. For the moment, throw error + * unconditionally; later we might allow read-only cases. + * Note that the error will cause us to come right back + * here with event == XACT_EVENT_ABORT, so we'll clean up + * the connection state at that point. + */ + elog(ERROR, "cannot PREPARE a transaction that has operated on postgres_fdw foreign tables"); + break; + case XACT_EVENT_COMMIT: case XACT_EVENT_PREPARE: /* Pre-commit should have closed the open transaction */ elog(ERROR, "missed cleaning up connection during pre-commit");