When postgresql compiles source code, add configuration options in precompiled configure

Absrtact: This article mainly talks about how to add a configuration option for the auto precompiled script configure in the source code of Postgresql and find a simple example to illustrate. In the src/include/storage/proc.h header file, add an array of bytes occupied by the PGXACT structure.

 

1. First, take a look at a picture to understand configure.

Configure is a shell script, which is mainly used to compile and install the source code base and software. . / configure is the first step of source code installation. Its main function is to configure the software to be installed. For example, add parameters such as – with, – enable, – without, – disable to control compilation. Check whether the current environment meets the dependency of the software to be installed. For example, it will check whether you have CC or GCC, and whether you need CC or GCC. Generate makefile files so that you can use make and make install to compile and install programs, and finally run make clean to delete some temporary files. More automatic compilation tools https://blog.csdn.net/liguangxianbin/article/details/80116989

 

2. The principle of the optional option of configure is to define a macro definition.

3. configure.in file definition:

#
# Pgxact
#
AC_MSG_CHECKING([whether to build with PGXACT support])    //cheack 
PGAC_ARG_BOOL(with, pgxact, no,
              [build with Pgxact support],                 
              [AC_DEFINE([USE_PGXACT], 1, [Define to 1 to build with Pgxact support. (--with-pgxact)])])                                             //define
AC_MSG_RESULT([$with_pgxact])                                //set

4.configure file:

ac_user_opts = 'with_pgxact'

Add Optional Features

--with-pgxact          build with Pgxact support

Perform the configure PGXACT operation:

#
# Pgxact
#
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to build with Pxact support" >&5
$as_echo_n "checking whether to build with Pgxact support... " >&6; }



# Check whether --with-pgxact was given.
if test "${with_pgxact+set}" = set; then :
  withval=$with_pgxact;
  case $withval in
    yes)

$as_echo "#define USE_PGXACT 1" >>confdefs.h

      ;;
    no)
      :
      ;;
    *)
      as_fn_error $? "no argument expected for --with-pgxact option" "$LINENO" 5
      ;;
  esac

else
  with_pgxact=no

fi

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $with_pgxact" >&5
$as_echo "$with_pgxact" >&6; }

5. Configure PG config. H.In

/* Define to 1 to build with PGXACT support. (--with-pgxact) */
#undef USE_PGXACT

6. Configure PG config.h.win32

/* Define to build with PGXACT support. (--with-pgxact) */
/* #undef USE_PGXACT */

done

Patch download

All codes:

diff --git a/configure.in b/configure.in
index 433bba4..096f81d 100644
--- a/configure.in
+++ b/configure.in
@@ -774,6 +774,14 @@ PGAC_ARG_BOOL(with, bonjour, no,
               [AC_DEFINE([USE_BONJOUR], 1, [Define to 1 to build with Bonjour support. (--with-bonjour)])])
 AC_MSG_RESULT([$with_bonjour])
 
+#
+# Pgxact
+#
+AC_MSG_CHECKING([whether to build with PGXACT support])
+PGAC_ARG_BOOL(with, pgxact, no,
+              [build with Pgxact support],
+              [AC_DEFINE([USE_PGXACT], 1, [Define to 1 to build with Pgxact support. (--with-pgxact)])])
+AC_MSG_RESULT([$with_pgxact])
 
 #
 # OpenSSL
diff --git a/hgdevconf.sh b/hgdevconf.sh
index 3940ffa..fd7d3e6 100755
--- a/hgdevconf.sh
+++ b/hgdevconf.sh
@@ -1,12 +1,13 @@
 #!/bin/sh
 
-./configure --prefix=/opt/HighGo/db/`date '+%Y%m%d'` \
+./configure --prefix=/opt/HighGo/db/`date '+%Y%m%d'` \
 --enable-nls="zh_CN zh_TW" \
 --without-tcl \
 --without-gssapi \
 --without-pam \
 --without-bonjour \
 --with-openssl \
+--with-pgxact \
 --with-libxml --with-libxslt \
 --enable-thread-safety \
 --with-zlib \
diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c
index bfa8499..767de40 100644
--- a/src/backend/storage/lmgr/proc.c
+++ b/src/backend/storage/lmgr/proc.c
@@ -168,6 +168,13 @@ InitProcGlobal(void)
 	bool		found;
 	uint32		TotalProcs = MaxBackends + NUM_AUXILIARY_PROCS + max_prepared_xacts;
 
+#ifdef USE_PGXACT
+	/* PGXACT should be aligned to the power of 2 */
+ 	StaticAssertExpr((sizeof(PGXACT) & (sizeof(PGXACT) - 1)) == 0,
+ 					 "PGXACT is not properly aligned");
+
+#endif
+
 	/* Create the ProcGlobal shared structure */
 	ProcGlobal = (PROC_HDR *)
 		ShmemInitStruct("Proc Header", sizeof(PROC_HDR), &found);
diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
index c1afc23..1cb96e5 100644
--- a/src/include/pg_config.h.in
+++ b/src/include/pg_config.h.in
@@ -833,6 +833,9 @@
 /* Define to 1 to build with assertion checks. (--enable-cassert) */
 #undef USE_ASSERT_CHECKING
 
+/* Define to 1 to bulid with Pgxact support. (--with-pgxact) */
+#undef USE_PGXACT 
+
 /* Define to 1 to build with Bonjour support. (--with-bonjour) */
 #undef USE_BONJOUR
 
diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32
index c758d63..8f64b11 100644
--- a/src/include/pg_config.h.win32
+++ b/src/include/pg_config.h.win32
@@ -635,6 +635,9 @@
 /* Define to 1 to build with assertion checks. (--enable-cassert) */
 /* #undef USE_ASSERT_CHECKING */
 
+/* Define to 1 bulid with Pgxact support. (--with-pgxact) */
+/* #undef USE_PGXACT */
+
 /* Define to 1 to build with Bonjour support. (--with-bonjour) */
 /* #undef USE_BONJOUR */
 
diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h
index e974f4e..115e77c 100644
--- a/src/include/storage/proc.h
+++ b/src/include/storage/proc.h
@@ -203,7 +203,22 @@ extern PGDLLIMPORT struct PGXACT *MyPgXact;
  * considerably on systems with many CPU cores, by reducing the number of
  * cache lines needing to be fetched.  Thus, think very carefully before adding
  * anything else here.
+ * if USE_PGXACT exist,the members into a separate array sped up GetSnapshotData considerably on
+ * systems with many CPU cores, by reducing the number of cache lines needing
+ * to be fetched.  Also, this fields are subject of intensive writes even on
+ * read-only workloads.  Thereby, it's desirable that writes of these fields
+ * invalidate as less cache lines as possible.  From that point of view, we
+ * should prevent PGXACT from being on the boundary of cache lines.  In order
+ * to achieve that we align PGXACT to the nearest power of 2.  That gives
+ * considerable speedup on systems with many CPU cores.
  */
+#ifdef USE_PGXACT
+	 /* Calculation of padding for PGXACT.  Update this after changing of PGXACT. */
+#define PGXACTPadSize (16 - 2 * sizeof(TransactionId) \
+    		       - 2 * sizeof(uint8) - 2 * sizeof(bool))
+
+#endif
+
 typedef struct PGXACT
 {
 	TransactionId xid;			/* id of top-level transaction currently being
@@ -221,6 +236,11 @@ typedef struct PGXACT
 								 * previously called InCommit */
 
 	uint8		nxids;
+
+#ifdef USE_PGXACT
+	char		pwd[PGXACTPadSize];
+#endif
+
 } PGXACT;
 
 /*

 

Keywords: git OpenSSL PostgreSQL shell

Added by olsrey on Wed, 22 Jan 2020 17:46:30 +0200