From d89348976c51952293ffe35845c372ffa7e93b47 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Fri, 29 Jun 2018 13:28:39 +0200 Subject: Fix assert in nested SQL procedure call When executing CALL in PL/pgSQL, we need to set a snapshot before invoking the to-be-called procedure. Otherwise, the to-be-called procedure might end up running without a snapshot. For LANGUAGE SQL procedures, this would result in an assertion failure. (For most other languages, this is usually not a problem, because those use SPI and SPI sets snapshots in most cases.) Setting the snapshot restores the behavior of how CALL worked when it was handled as a generic SQL statement in PL/pgSQL (exec_stmt_execsql()). This change revealed another problem: In SPI_commit(), we popped the active snapshot before committing the transaction, to avoid "snapshot %p still active" errors. However, there is no particular reason why only at most one snapshot should be on the stack. So change this to pop all active snapshots instead of only one. --- src/backend/executor/spi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/backend/executor') diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c index 22dd55c3783..5756365c8f3 100644 --- a/src/backend/executor/spi.c +++ b/src/backend/executor/spi.c @@ -228,8 +228,13 @@ SPI_commit(void) _SPI_current->internal_xact = true; - if (ActiveSnapshotSet()) + /* + * Before committing, pop all active snapshots to avoid error about + * "snapshot %p still active". + */ + while (ActiveSnapshotSet()) PopActiveSnapshot(); + CommitTransactionCommand(); MemoryContextSwitchTo(oldcontext); -- cgit v1.2.3