From fcf10d1741a236012c0bab327f535fc5277071d9 Mon Sep 17 00:00:00 2001
From: Amul Sul <sulamul@gmail.com>
Date: Sat, 7 Jan 2017 18:51:51 +0530
Subject: [PATCH 1/2] Changes to Peter Eisentraut's bgsession v2 patch

---
 src/backend/tcop/bgsession.c | 17 ++---------------
 src/include/tcop/bgsession.h | 17 ++++++++++++++---
 2 files changed, 16 insertions(+), 18 deletions(-)

diff --git a/src/backend/tcop/bgsession.c b/src/backend/tcop/bgsession.c
index 486819b..510e740 100644
--- a/src/backend/tcop/bgsession.c
+++ b/src/backend/tcop/bgsession.c
@@ -60,14 +60,11 @@
 #include "nodes/pg_list.h"
 #include "pgstat.h"
 #include "postmaster/bgworker.h"
-#include "storage/dsm.h"
-#include "storage/shm_mq.h"
 #include "storage/shm_toc.h"
 #include "tcop/bgsession.h"
 #include "tcop/tcopprot.h"
 #include "utils/lsyscache.h"
 #include "utils/memutils.h"
-#include "utils/resowner.h"
 
 /* Table-of-contents constants for our dynamic shared memory segment. */
 #define BGSESSION_MAGIC					0x50674267
@@ -89,16 +86,6 @@ typedef struct background_session_fixed_data
 	int sec_context;
 } background_session_fixed_data;
 
-struct BackgroundSession
-{
-	ResourceOwner resowner;
-	dsm_segment *seg;
-	BackgroundWorkerHandle *worker_handle;
-	shm_mq_handle *command_qh;
-	shm_mq_handle *response_qh;
-	int		transaction_status;
-};
-
 struct BackgroundSessionPreparedStatement
 {
 	BackgroundSession *session;
@@ -121,7 +108,6 @@ BackgroundSessionStart(void)
 {
 	ResourceOwner oldowner;
 	BackgroundWorker worker;
-	pid_t		pid;
 	BackgroundSession *session;
 	shm_toc_estimator e;
 	Size		segsize;
@@ -209,7 +195,8 @@ BackgroundSessionStart(void)
 	shm_mq_set_handle(session->command_qh, session->worker_handle);
 	shm_mq_set_handle(session->response_qh, session->worker_handle);
 
-	bgwstatus = WaitForBackgroundWorkerStartup(session->worker_handle, &pid);
+	bgwstatus = WaitForBackgroundWorkerStartup(session->worker_handle,
+											   &session->pid);
 	if (bgwstatus != BGWH_STARTED)
 		ereport(ERROR,
 				(errcode(ERRCODE_INSUFFICIENT_RESOURCES),
diff --git a/src/include/tcop/bgsession.h b/src/include/tcop/bgsession.h
index 71415a6..008fa28 100644
--- a/src/include/tcop/bgsession.h
+++ b/src/include/tcop/bgsession.h
@@ -3,13 +3,24 @@
 
 #include "access/tupdesc.h"
 #include "nodes/pg_list.h"
-
-struct BackgroundSession;
-typedef struct BackgroundSession BackgroundSession;
+#include "storage/dsm.h"
+#include "storage/shm_mq.h"
+#include "utils/resowner.h"
 
 struct BackgroundSessionPreparedStatement;
 typedef struct BackgroundSessionPreparedStatement BackgroundSessionPreparedStatement;
 
+typedef struct BackgroundSession
+{
+	pid_t pid;
+	ResourceOwner resowner;
+	dsm_segment *seg;
+	BackgroundWorkerHandle *worker_handle;
+	shm_mq_handle *command_qh;
+	shm_mq_handle *response_qh;
+	int		transaction_status;
+} BackgroundSession;
+
 typedef struct BackgroundSessionResult
 {
 	TupleDesc	tupdesc;
-- 
2.6.2

