diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index f22d0a07987..2fc1f9bbe8b 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -2315,6 +2315,7 @@ CopyFrom(CopyState cstate) HeapTuple *bufferedTuples = NULL; /* initialize to silence warning */ Size bufferedTuplesSize = 0; int firstBufferedLineNo = 0; + ListCell *l; Assert(cstate->rel); @@ -2773,6 +2774,15 @@ CopyFrom(CopyState cstate) ExecDropSingleTupleTableSlot(cstate->partition_tuple_slot); } + /* Close any trigger target relations */ + foreach(l, estate->es_trig_target_relations) + { + resultRelInfo = (ResultRelInfo *) lfirst(l); + /* Close indices and then the relation itself */ + ExecCloseIndices(resultRelInfo); + heap_close(resultRelInfo->ri_RelationDesc, NoLock); + } + FreeExecutorState(estate); /*