diff --git a/configure b/configure
index ed1ff0a..79a0dea 100755
--- a/configure
+++ b/configure
@@ -702,6 +702,7 @@ EGREP
 GREP
 with_zlib
 with_system_tzdata
+with_libnuma
 with_libxslt
 with_libxml
 XML2_CONFIG
@@ -831,6 +832,7 @@ with_uuid
 with_ossp_uuid
 with_libxml
 with_libxslt
+with_libnuma
 with_system_tzdata
 with_zlib
 with_gnu_ld
@@ -1518,6 +1520,7 @@ Optional Packages:
   --with-ossp-uuid        obsolete spelling of --with-uuid=ossp
   --with-libxml           build with XML support
   --with-libxslt          use XSLT support when building contrib/xml2
+  --with-libnuma          use libnuma for NUMA support
   --with-system-tzdata=DIR
                           use system time zone data in DIR
   --without-zlib          do not use Zlib
@@ -5822,6 +5825,39 @@ fi
 
 
 
+
+#
+# NUMA library
+#
+
+
+
+# Check whether --with-libnuma was given.
+if test "${with_libnuma+set}" = set; then :
+  withval=$with_libnuma;
+  case $withval in
+    yes)
+      $as_echo "#define USE_LIBNUMA 1 Define to 1 to use NUMA features, like interleaved shared memory. (--with-libnuma)" >>confdefs.h
+
+      ;;
+    no)
+      :
+      ;;
+    *)
+      as_fn_error $? "no argument expected for --with-libnuma option" "$LINENO" 5
+      ;;
+  esac
+
+else
+  with_libnuma=no
+
+fi
+
+
+
+
+
+
 #
 # tzdata
 #
@@ -8781,6 +8817,56 @@ fi
 
 fi
 
+if test "$with_libnuma" = yes ; then
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for numa_set_localalloc in -lnuma" >&5
+$as_echo_n "checking for numa_set_localalloc in -lnuma... " >&6; }
+if ${ac_cv_lib_numa_numa_set_localalloc+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_check_lib_save_LIBS=$LIBS
+LIBS="-lnuma  $LIBS"
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char numa_set_localalloc ();
+int
+main ()
+{
+return numa_set_localalloc ();
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_lib_numa_numa_set_localalloc=yes
+else
+  ac_cv_lib_numa_numa_set_localalloc=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+LIBS=$ac_check_lib_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_numa_numa_set_localalloc" >&5
+$as_echo "$ac_cv_lib_numa_numa_set_localalloc" >&6; }
+if test "x$ac_cv_lib_numa_numa_set_localalloc" = xyes; then :
+  cat >>confdefs.h <<_ACEOF
+#define HAVE_LIBNUMA 1
+_ACEOF
+
+  LIBS="-lnuma $LIBS"
+
+else
+  as_fn_error $? "library 'numa' is required for NUMA support" "$LINENO" 5
+fi
+
+fi
+
 # for contrib/sepgsql
 if test "$with_selinux" = yes; then
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for security_compute_create_name in -lselinux" >&5
@@ -9466,6 +9552,17 @@ fi
 
 fi
 
+if test "$with_libnuma" = yes ; then
+  ac_fn_c_check_header_mongrel "$LINENO" "numa.h" "ac_cv_header_numa_h" "$ac_includes_default"
+if test "x$ac_cv_header_numa_h" = xyes; then :
+
+else
+  as_fn_error $? "header file <numa.h> is required for NUMA support" "$LINENO" 5
+fi
+
+
+fi
+
 if test "$with_ldap" = yes ; then
   if test "$PORTNAME" != "win32"; then
      for ac_header in ldap.h
diff --git a/configure.in b/configure.in
index 80df1d7..fb06737 100644
--- a/configure.in
+++ b/configure.in
@@ -761,6 +761,16 @@ PGAC_ARG_BOOL(with, libxslt, no, [use XSLT support when building contrib/xml2],
 
 AC_SUBST(with_libxslt)
 
+
+#
+# NUMA library
+#
+PGAC_ARG_BOOL(with, libnuma, no, [use libnuma for NUMA support],
+              [AC_DEFINE([USE_LIBNUMA], 1 [Define to 1 to use NUMA features, like interleaved shared memory. (--with-libnuma)])])
+
+AC_SUBST(with_libnuma)
+
+
 #
 # tzdata
 #
@@ -969,6 +979,10 @@ if test "$with_libxslt" = yes ; then
   AC_CHECK_LIB(xslt, xsltCleanupGlobals, [], [AC_MSG_ERROR([library 'xslt' is required for XSLT support])])
 fi
 
+if test "$with_libnuma" = yes ; then
+  AC_CHECK_LIB(numa, numa_set_localalloc, [], [AC_MSG_ERROR([library 'numa' is required for NUMA support])])
+fi
+
 # for contrib/sepgsql
 if test "$with_selinux" = yes; then
   AC_CHECK_LIB(selinux, security_compute_create_name, [],
@@ -1097,6 +1111,10 @@ if test "$with_libxslt" = yes ; then
   AC_CHECK_HEADER(libxslt/xslt.h, [], [AC_MSG_ERROR([header file <libxslt/xslt.h> is required for XSLT support])])
 fi
 
+if test "$with_libnuma" = yes ; then
+  AC_CHECK_HEADER(numa.h, [], [AC_MSG_ERROR([header file <numa.h> is required for NUMA support])])
+fi
+
 if test "$with_ldap" = yes ; then
   if test "$PORTNAME" != "win32"; then
      AC_CHECK_HEADERS(ldap.h, [],
diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c
index 7430757..6d6cd10 100644
--- a/src/backend/port/sysv_shmem.c
+++ b/src/backend/port/sysv_shmem.c
@@ -27,6 +27,9 @@
 #ifdef HAVE_SYS_SHM_H
 #include <sys/shm.h>
 #endif
+#ifdef USE_LIBNUMA
+#include <numa.h>
+#endif
 
 #include "miscadmin.h"
 #include "portability/mem.h"
@@ -536,6 +539,24 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port,
 		 */
 	}
 
+#ifdef USE_LIBNUMA
+	/*
+	 * If this is not a private segment and we are using libnuma, make the
+	 * large memory segment interleaved.
+	 */
+	if (!makePrivate && numa_available())
+	{
+		void   *start;
+
+		if (AnonymousShmem == NULL)
+			start = memAddress;
+		else
+			start = AnonymousShmem;
+
+		numa_interleave_memory(start, size, numa_all_nodes_ptr);
+	}
+#endif
+
 	/*
 	 * OK, we created a new segment.  Mark it as created by this process. The
 	 * order of assignments here is critical so that another Postgres process
