diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 33975687b3..3f992b8d92 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -291,10 +291,7 @@ _SPI_commit(bool chain) { ErrorData *edata; - /* Save error info in caller's context */ MemoryContextSwitchTo(oldcontext); - edata = CopyErrorData(); - FlushErrorState(); /* * Abort the failed transaction. If this fails too, we'll just @@ -302,6 +299,10 @@ _SPI_commit(bool chain) */ AbortCurrentTransaction(); + /* Save error info in caller's context */ + edata = CopyErrorData(); + FlushErrorState(); + /* ... and start a new one */ StartTransactionCommand(); if (chain) @@ -383,10 +384,7 @@ _SPI_rollback(bool chain) { ErrorData *edata; - /* Save error info in caller's context */ MemoryContextSwitchTo(oldcontext); - edata = CopyErrorData(); - FlushErrorState(); /* * Try again to abort the failed transaction. If this fails too, @@ -395,6 +393,10 @@ _SPI_rollback(bool chain) */ AbortCurrentTransaction(); + /* Save error info in caller's context */ + edata = CopyErrorData(); + FlushErrorState(); + /* ... and start a new one */ StartTransactionCommand(); if (chain) diff --git a/src/backend/replication/logical/reorderbuffer.c b/src/backend/replication/logical/reorderbuffer.c index 12edc5772a..f9cf599026 100644 --- a/src/backend/replication/logical/reorderbuffer.c +++ b/src/backend/replication/logical/reorderbuffer.c @@ -2565,7 +2565,7 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, PG_CATCH(); { MemoryContext ecxt = MemoryContextSwitchTo(ccxt); - ErrorData *errdata = CopyErrorData(); + ErrorData *errdata; /* TODO: Encapsulate cleanup from the PG_TRY and PG_CATCH blocks */ if (iterstate) @@ -2579,6 +2579,8 @@ ReorderBufferProcessTXN(ReorderBuffer *rb, ReorderBufferTXN *txn, */ AbortCurrentTransaction(); + errdata = CopyErrorData(); + /* make sure there's no cache pollution */ ReorderBufferExecuteInvalidations(txn->ninvalidations, txn->invalidations);