diff --git a/src/backend/executor/execParallel.c b/src/backend/executor/execParallel.c
index 60aaa822b7e..ac22bedf0e2 100644
--- a/src/backend/executor/execParallel.c
+++ b/src/backend/executor/execParallel.c
@@ -979,9 +979,6 @@ ParallelQueryMain(dsm_segment *seg, shm_toc *toc)
 	/* Report workers' query for monitoring purposes */
 	pgstat_report_activity(STATE_RUNNING, debug_query_string);
 
-	/* Prepare to track buffer usage during query execution. */
-	InstrStartParallelQuery();
-
 	/* Attach to the dynamic shared memory area. */
 	area_space = shm_toc_lookup(toc, PARALLEL_KEY_DSA, false);
 	area = dsa_attach_in_place(area_space, seg);
@@ -993,6 +990,9 @@ ParallelQueryMain(dsm_segment *seg, shm_toc *toc)
 	queryDesc->planstate->state->es_query_dsa = area;
 	ExecParallelInitializeWorker(queryDesc->planstate, toc);
 
+	/* Prepare to track buffer usage during query execution. */
+	InstrStartParallelQuery();
+
 	/* Run the plan */
 	ExecutorRun(queryDesc, ForwardScanDirection, 0L, true);
 
diff --git a/src/backend/executor/execProcnode.c b/src/backend/executor/execProcnode.c
index 36d2914249c..a0d49ec0fba 100644
--- a/src/backend/executor/execProcnode.c
+++ b/src/backend/executor/execProcnode.c
@@ -737,6 +737,13 @@ ExecShutdownNode(PlanState *node)
 
 	planstate_tree_walker(node, ExecShutdownNode, NULL);
 
+	/*
+	 * Allow instrumentation to count stats collected during shutdown for
+	 * nodes that are executed atleast once.
+	 */
+	if (node->instrument && node->instrument->running)
+		InstrStartNode(node->instrument);
+
 	switch (nodeTag(node))
 	{
 		case T_GatherState:
@@ -755,5 +762,12 @@ ExecShutdownNode(PlanState *node)
 			break;
 	}
 
+	/*
+	 * Allow instrumentation to count stats collected during shutdown for
+	 * nodes that are executed atleast once.
+	 */
+	if (node->instrument && node->instrument->running)
+		InstrStopNode(node->instrument, 0);
+
 	return false;
 }
diff --git a/src/backend/executor/nodeGather.c b/src/backend/executor/nodeGather.c
index 597cbfaa16d..48633b965ec 100644
--- a/src/backend/executor/nodeGather.c
+++ b/src/backend/executor/nodeGather.c
@@ -327,7 +327,10 @@ gather_readnext(GatherState *gatherstate)
 			Assert(!tup);
 			--gatherstate->nreaders;
 			if (gatherstate->nreaders == 0)
+			{
+				ExecShutdownGatherWorkers(gatherstate);
 				return NULL;
+			}
 			memmove(&gatherstate->reader[gatherstate->nextreader],
 					&gatherstate->reader[gatherstate->nextreader + 1],
 					sizeof(TupleQueueReader *)
diff --git a/src/backend/executor/nodeLimit.c b/src/backend/executor/nodeLimit.c
index ac5a2ff0e60..cf1851e235f 100644
--- a/src/backend/executor/nodeLimit.c
+++ b/src/backend/executor/nodeLimit.c
@@ -134,6 +134,8 @@ ExecLimit(PlanState *pstate)
 					node->position - node->offset >= node->count)
 				{
 					node->lstate = LIMIT_WINDOWEND;
+					/* Allow nodes to release or shut down resources. */
+					(void) ExecShutdownNode(outerPlan);
 					return NULL;
 				}
 
