summaryrefslogtreecommitdiff
path: root/src/backend/executor/spi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/executor/spi.c')
-rw-r--r--src/backend/executor/spi.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index fb36e762f28..6f98dd34d9e 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -246,6 +246,14 @@ SPI_commit(void)
(errcode(ERRCODE_INVALID_TRANSACTION_TERMINATION),
errmsg("cannot commit while a subtransaction is active")));
+ /*
+ * Hold any pinned portals that any PLs might be using. We have to do
+ * this before changing transaction state, since this will run
+ * user-defined code that might throw an error.
+ */
+ HoldPinnedPortals();
+
+ /* Start the actual commit */
_SPI_current->internal_xact = true;
/*
@@ -277,6 +285,15 @@ SPI_rollback(void)
(errcode(ERRCODE_INVALID_TRANSACTION_TERMINATION),
errmsg("cannot roll back while a subtransaction is active")));
+ /*
+ * Hold any pinned portals that any PLs might be using. We have to do
+ * this before changing transaction state, since this will run
+ * user-defined code that might throw an error, and in any case couldn't
+ * be run in an already-aborted transaction.
+ */
+ HoldPinnedPortals();
+
+ /* Start the actual rollback */
_SPI_current->internal_xact = true;
AbortCurrentTransaction();