diff options
Diffstat (limited to 'src/backend/replication/logical/worker.c')
-rw-r--r-- | src/backend/replication/logical/worker.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c index 60bf7f7ee9c..452e5f3df7f 100644 --- a/src/backend/replication/logical/worker.c +++ b/src/backend/replication/logical/worker.c @@ -349,6 +349,13 @@ create_estate_for_relation(LogicalRepRelMapEntry *rel, EState *estate; RangeTblEntry *rte; + /* + * Input functions may need an active snapshot, as may AFTER triggers + * invoked during finish_estate. For safety, ensure an active snapshot + * exists throughout all our usage of the executor. + */ + PushActiveSnapshot(GetTransactionSnapshot()); + estate = CreateExecutorState(); rte = makeNode(RangeTblEntry); @@ -400,6 +407,7 @@ finish_estate(EState *estate) /* Cleanup. */ ExecResetTupleTable(estate->es_tupleTable, false); FreeExecutorState(estate); + PopActiveSnapshot(); } /* @@ -1212,9 +1220,6 @@ apply_handle_insert(StringInfo s) RelationGetDescr(rel->localrel), &TTSOpsVirtual); - /* Input functions may need an active snapshot, so get one */ - PushActiveSnapshot(GetTransactionSnapshot()); - /* Process and store remote tuple in the slot */ oldctx = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate)); slot_store_data(remoteslot, rel, &newtup); @@ -1229,8 +1234,6 @@ apply_handle_insert(StringInfo s) apply_handle_insert_internal(resultRelInfo, estate, remoteslot); - PopActiveSnapshot(); - finish_estate(estate); logicalrep_rel_close(rel, NoLock); @@ -1358,8 +1361,6 @@ apply_handle_update(StringInfo s) /* Also populate extraUpdatedCols, in case we have generated columns */ fill_extraUpdatedCols(target_rte, rel->localrel); - PushActiveSnapshot(GetTransactionSnapshot()); - /* Build the search tuple. */ oldctx = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate)); slot_store_data(remoteslot, rel, @@ -1374,8 +1375,6 @@ apply_handle_update(StringInfo s) apply_handle_update_internal(resultRelInfo, estate, remoteslot, &newtup, rel); - PopActiveSnapshot(); - finish_estate(estate); logicalrep_rel_close(rel, NoLock); @@ -1482,8 +1481,6 @@ apply_handle_delete(StringInfo s) RelationGetDescr(rel->localrel), &TTSOpsVirtual); - PushActiveSnapshot(GetTransactionSnapshot()); - /* Build the search tuple. */ oldctx = MemoryContextSwitchTo(GetPerTupleMemoryContext(estate)); slot_store_data(remoteslot, rel, &oldtup); @@ -1497,8 +1494,6 @@ apply_handle_delete(StringInfo s) apply_handle_delete_internal(resultRelInfo, estate, remoteslot, &rel->remoterel); - PopActiveSnapshot(); - finish_estate(estate); logicalrep_rel_close(rel, NoLock); @@ -1818,7 +1813,7 @@ apply_handle_truncate(StringInfo s) List *relids = NIL; List *relids_logged = NIL; ListCell *lc; - LOCKMODE lockmode = AccessExclusiveLock; + LOCKMODE lockmode = AccessExclusiveLock; if (handle_streamed_transaction(LOGICAL_REP_MSG_TRUNCATE, s)) return; |