From ecb22df8fa9484efbda3223393a2513112c14615 Mon Sep 17 00:00:00 2001
From: Hari Babu <kommi.haribabu@gmail.com>
Date: Sun, 10 Feb 2019 16:10:14 +1100
Subject: [PATCH] Avoid counting parallel worker transactions stats

The transactions that are started and committed by the parallel
workers should not be considered as actual transactions that are
committed. Currently this counter gets incremented only by the
outer transactions and internal operations like autovacuum and
etc.
---
 src/backend/postmaster/pgstat.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index 81c6499251..6c72bfd986 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -36,6 +36,7 @@
 
 #include "access/heapam.h"
 #include "access/htup_details.h"
+#include "access/parallel.h"
 #include "access/transam.h"
 #include "access/twophase_rmgr.h"
 #include "access/xact.h"
@@ -2057,14 +2058,18 @@ AtEOXact_PgStat(bool isCommit)
 {
 	PgStat_SubXactStatus *xact_state;
 
-	/*
-	 * Count transaction commit or abort.  (We use counters, not just bools,
-	 * in case the reporting message isn't sent right away.)
-	 */
-	if (isCommit)
-		pgStatXactCommit++;
-	else
-		pgStatXactRollback++;
+	/* Don't count parallel worker transactions into stats */
+	if (!IsParallelWorker())
+	{
+		/*
+		 * Count transaction commit or abort.  (We use counters, not just bools,
+		 * in case the reporting message isn't sent right away.)
+		 */
+		if (isCommit)
+			pgStatXactCommit++;
+		else
+			pgStatXactRollback++;
+	}
 
 	/*
 	 * Transfer transactional insert/update counts into the base tabstat
-- 
2.20.1.windows.1

