From e094b148ee490e2ba61245a99852af7488b7ef11 Mon Sep 17 00:00:00 2001
From: kirk <k.jamison@jp.fujitsu.com>
Date: Tue, 19 Mar 2019 07:26:49 +0000

Author: Hari Babu <kommi.haribabu@gmail.com>
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 committed transactions.
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 2fbfadd..3ca5ca1 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/tableam.h"
 #include "access/transam.h"
 #include "access/twophase_rmgr.h"
@@ -2093,14 +2094,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
-- 
1.8.3.1

