Here is an updated patch set. I have implemented proper solutions for the various hacks in the previous patch set. So this patch set should now be ready for proper consideration.

The way I have organized it here is that patches 0002 through 0008 should be improvements in their own right.

The remaining two patches 0009 and 0010 are workarounds that are just necessary to satisfy -Wmissing-variable-declarations. I haven't made up my mind if I'd want to take the bison patch 0010 like this and undo it later if we move to pure parsers everywhere, or instead wait for the pure parsers to arrive before we install -Wmissing-variable-declarations for everyone.

Obviously, people might also have opinions on some details of where exactly to put the declarations etc. I have tried to follow existing patterns as much as possible, but those are also not necessarily great in all cases.
From 6f3d2c1ee18cc7e7cbc5656d21012f504ccc0c7c Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 May 2024 13:49:37 +0200
Subject: [PATCH v2 01/10] Add -Wmissing-variable-declarations to the standard
 compilation flags

This warning flag detects global variables not declared in header
files.  This is similar to what -Wmissing-prototypes does for
functions.  (More correctly, it is similar to what
-Wmissing-declarations does for functions, but -Wmissing-prototypes is
a superset of that in C.)

This flag is new in GCC 14.  Clang has supported it for a while.

Discussion: 
https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c9...@eisentraut.org

XXX many warnings to fix first
---
 configure                                 | 49 +++++++++++++++++++++++
 configure.ac                              |  9 +++++
 meson.build                               | 10 +++++
 src/Makefile.global.in                    |  1 +
 src/interfaces/ecpg/test/Makefile.regress |  2 +-
 src/interfaces/ecpg/test/meson.build      |  1 +
 src/makefiles/meson.build                 |  2 +
 src/tools/pg_bsd_indent/Makefile          |  2 +
 src/tools/pg_bsd_indent/meson.build       |  1 +
 9 files changed, 76 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 7b03db56a67..f382a08edc8 100755
--- a/configure
+++ b/configure
@@ -741,6 +741,7 @@ CXXFLAGS_SL_MODULE
 CFLAGS_SL_MODULE
 CFLAGS_VECTORIZE
 CFLAGS_UNROLL_LOOPS
+PERMIT_MISSING_VARIABLE_DECLARATIONS
 PERMIT_DECLARATION_AFTER_STATEMENT
 LLVM_BINPATH
 LLVM_CXXFLAGS
@@ -6080,6 +6081,54 @@ if test x"$pgac_cv_prog_CXX_cxxflags__Wformat_security" 
= x"yes"; then
 fi
 
 
+  # gcc 14+, clang for a while
+  # (Supported in C++ by clang but not gcc.  For consistency, omit in C++.)
+  save_CFLAGS=$CFLAGS
+
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports 
-Wmissing-variable-declarations, for CFLAGS" >&5
+$as_echo_n "checking whether ${CC} supports -Wmissing-variable-declarations, 
for CFLAGS... " >&6; }
+if ${pgac_cv_prog_CC_cflags__Wmissing_variable_declarations+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  pgac_save_CFLAGS=$CFLAGS
+pgac_save_CC=$CC
+CC=${CC}
+CFLAGS="${CFLAGS} -Wmissing-variable-declarations"
+ac_save_c_werror_flag=$ac_c_werror_flag
+ac_c_werror_flag=yes
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  pgac_cv_prog_CC_cflags__Wmissing_variable_declarations=yes
+else
+  pgac_cv_prog_CC_cflags__Wmissing_variable_declarations=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_c_werror_flag=$ac_save_c_werror_flag
+CFLAGS="$pgac_save_CFLAGS"
+CC="$pgac_save_CC"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" >&5
+$as_echo "$pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" >&6; }
+if test x"$pgac_cv_prog_CC_cflags__Wmissing_variable_declarations" = x"yes"; 
then
+  CFLAGS="${CFLAGS} -Wmissing-variable-declarations"
+fi
+
+
+  PERMIT_MISSING_VARIABLE_DECLARATIONS=
+  if test x"$save_CFLAGS" != x"$CFLAGS"; then
+    PERMIT_MISSING_VARIABLE_DECLARATIONS=-Wno-missing-variable-declarations
+  fi
+
   # Disable strict-aliasing rules; needed for gcc 3.3+
 
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CC} supports 
-fno-strict-aliasing, for CFLAGS" >&5
diff --git a/configure.ac b/configure.ac
index 63e7be38472..30352b8258b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -530,6 +530,15 @@ if test "$GCC" = yes -a "$ICC" = no; then
   # This was included in -Wall/-Wformat in older GCC versions
   PGAC_PROG_CC_CFLAGS_OPT([-Wformat-security])
   PGAC_PROG_CXX_CFLAGS_OPT([-Wformat-security])
+  # gcc 14+, clang for a while
+  # (Supported in C++ by clang but not gcc.  For consistency, omit in C++.)
+  save_CFLAGS=$CFLAGS
+  PGAC_PROG_CC_CFLAGS_OPT([-Wmissing-variable-declarations])
+  PERMIT_MISSING_VARIABLE_DECLARATIONS=
+  if test x"$save_CFLAGS" != x"$CFLAGS"; then
+    PERMIT_MISSING_VARIABLE_DECLARATIONS=-Wno-missing-variable-declarations
+  fi
+  AC_SUBST(PERMIT_MISSING_VARIABLE_DECLARATIONS)
   # Disable strict-aliasing rules; needed for gcc 3.3+
   PGAC_PROG_CC_CFLAGS_OPT([-fno-strict-aliasing])
   PGAC_PROG_CXX_CFLAGS_OPT([-fno-strict-aliasing])
diff --git a/meson.build b/meson.build
index 2767abd19e2..518560b6a83 100644
--- a/meson.build
+++ b/meson.build
@@ -1880,6 +1880,16 @@ if cc.has_argument('-Wdeclaration-after-statement')
   cflags_no_decl_after_statement += '-Wno-declaration-after-statement'
 endif
 
+# Some code is not clean for -Wmissing-variable-declarations, so we
+# make the "no" option available.  Also, while clang supports this
+# option for C++, gcc does not, so for consistency, leave it off for
+# C++.
+cflags_no_missing_var_decls = []
+if cc.has_argument('-Wmissing-variable-declarations')
+  cflags_warn += '-Wmissing-variable-declarations'
+  cflags_no_missing_var_decls += '-Wno-missing-variable-declarations'
+endif
+
 
 # The following tests want to suppress various unhelpful warnings by adding
 # -Wno-foo switches.  But gcc won't complain about unrecognized -Wno-foo
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index a00c909681e..0a0ba0719f5 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -266,6 +266,7 @@ CFLAGS_POPCNT = @CFLAGS_POPCNT@
 CFLAGS_CRC = @CFLAGS_CRC@
 CFLAGS_XSAVE = @CFLAGS_XSAVE@
 PERMIT_DECLARATION_AFTER_STATEMENT = @PERMIT_DECLARATION_AFTER_STATEMENT@
+PERMIT_MISSING_VARIABLE_DECLARATIONS = @PERMIT_MISSING_VARIABLE_DECLARATIONS@
 CXXFLAGS = @CXXFLAGS@
 
 LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
diff --git a/src/interfaces/ecpg/test/Makefile.regress 
b/src/interfaces/ecpg/test/Makefile.regress
index b0647cd2c5f..9bf0efa40b9 100644
--- a/src/interfaces/ecpg/test/Makefile.regress
+++ b/src/interfaces/ecpg/test/Makefile.regress
@@ -3,7 +3,7 @@
 
 override CPPFLAGS := -I../../include 
-I$(top_srcdir)/src/interfaces/ecpg/include \
        -I$(libpq_srcdir) $(CPPFLAGS)
-override CFLAGS += $(PTHREAD_CFLAGS)
+override CFLAGS += $(PTHREAD_CFLAGS) $(PERMIT_MISSING_VARIABLE_DECLARATIONS)
 
 LDFLAGS_INTERNAL += -L../../ecpglib -lecpg -L../../pgtypeslib -lpgtypes 
$(libpq)
 
diff --git a/src/interfaces/ecpg/test/meson.build 
b/src/interfaces/ecpg/test/meson.build
index c1e508ccc82..8fd284071f2 100644
--- a/src/interfaces/ecpg/test/meson.build
+++ b/src/interfaces/ecpg/test/meson.build
@@ -27,6 +27,7 @@ testprep_targets += pg_regress_ecpg
 
 # create .c files and executables from .pgc files
 ecpg_test_exec_kw = {
+  'c_args': cflags_no_missing_var_decls,
   'dependencies': [frontend_code, libpq],
   'include_directories': [ecpg_inc],
   'link_with': [ecpglib_so, ecpg_compat_so, ecpg_pgtypes_so],
diff --git a/src/makefiles/meson.build b/src/makefiles/meson.build
index 5618050b306..850e9275845 100644
--- a/src/makefiles/meson.build
+++ b/src/makefiles/meson.build
@@ -98,6 +98,8 @@ pgxs_kv = {
   'CXXFLAGS_SL_MODULE': ' '.join(cxxflags_mod),
   'PERMIT_DECLARATION_AFTER_STATEMENT':
     ' '.join(cflags_no_decl_after_statement),
+  'PERMIT_MISSING_VARIABLE_DECLARATIONS':
+    ' '.join(cflags_no_missing_var_decls),
 
   'CFLAGS_CRC': ' '.join(cflags_crc),
   'CFLAGS_POPCNT': ' '.join(cflags_popcnt),
diff --git a/src/tools/pg_bsd_indent/Makefile b/src/tools/pg_bsd_indent/Makefile
index d922013e40b..f721dfb0d19 100644
--- a/src/tools/pg_bsd_indent/Makefile
+++ b/src/tools/pg_bsd_indent/Makefile
@@ -25,6 +25,8 @@ OBJS = \
        parse.o \
        pr_comment.o
 
+$(OBJS): CFLAGS += $(PERMIT_MISSING_VARIABLE_DECLARATIONS)
+
 all: pg_bsd_indent
 
 pg_bsd_indent: $(OBJS) | submake-libpgport
diff --git a/src/tools/pg_bsd_indent/meson.build 
b/src/tools/pg_bsd_indent/meson.build
index 4387c47740e..87ed4292975 100644
--- a/src/tools/pg_bsd_indent/meson.build
+++ b/src/tools/pg_bsd_indent/meson.build
@@ -18,6 +18,7 @@ endif
 
 pg_bsd_indent = executable('pg_bsd_indent',
   pg_bsd_indent_sources,
+  c_args: cflags_no_missing_var_decls,
   dependencies: [frontend_code],
   include_directories: include_directories('.'),
   kwargs: default_bin_args + {

base-commit: ae482a7ec521e09bb0dbfc261da6e6170a5ac29f
-- 
2.45.2

From 663a3df13318414279f0b01794572d9f8c1202d7 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 May 2024 13:49:37 +0200
Subject: [PATCH v2 02/10] Convert some extern variables to static

These probably should have been static all along, it was only
forgotten out of sloppiness.

Discussion: 
https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c9...@eisentraut.org
---
 contrib/isn/EAN13.h                           |  4 +-
 contrib/isn/ISBN.h                            |  8 +--
 contrib/isn/ISMN.h                            |  4 +-
 contrib/isn/ISSN.h                            |  4 +-
 contrib/isn/UPC.h                             |  4 +-
 src/backend/commands/user.c                   |  4 +-
 src/backend/postmaster/launch_backend.c       |  2 +-
 src/backend/replication/logical/slotsync.c    |  2 +-
 src/backend/replication/logical/worker.c      |  2 +-
 src/backend/utils/misc/guc_tables.c           |  7 +-
 src/bin/pg_archivecleanup/pg_archivecleanup.c | 15 +++--
 src/bin/pg_basebackup/bbstreamer_file.c       |  4 +-
 src/bin/pg_basebackup/bbstreamer_gzip.c       |  4 +-
 src/bin/pg_basebackup/bbstreamer_inject.c     |  2 +-
 src/bin/pg_basebackup/bbstreamer_lz4.c        |  4 +-
 src/bin/pg_basebackup/bbstreamer_tar.c        |  6 +-
 src/bin/pg_basebackup/bbstreamer_zstd.c       |  4 +-
 src/bin/pg_basebackup/walmethods.c            |  4 +-
 src/bin/pg_checksums/pg_checksums.c           |  4 +-
 src/bin/pg_combinebackup/pg_combinebackup.c   |  2 +-
 src/bin/pg_rewind/pg_rewind.c                 | 12 ++--
 src/bin/pg_test_timing/pg_test_timing.c       |  2 +-
 src/bin/pgbench/pgbench.c                     | 67 ++++++++++---------
 src/bin/scripts/vacuumdb.c                    |  2 +-
 src/pl/plpgsql/src/pl_handler.c               |  4 +-
 src/test/isolation/isolation_main.c           |  6 +-
 .../modules/dummy_index_am/dummy_index_am.c   |  6 +-
 .../modules/libpq_pipeline/libpq_pipeline.c   |  4 +-
 .../test_json_parser_incremental.c            |  2 +-
 29 files changed, 99 insertions(+), 96 deletions(-)

diff --git a/contrib/isn/EAN13.h b/contrib/isn/EAN13.h
index 7023ebdf638..52f104e5651 100644
--- a/contrib/isn/EAN13.h
+++ b/contrib/isn/EAN13.h
@@ -11,7 +11,7 @@
  */
 
 /* where the digit set begins, and how many of them are in the table */
-const unsigned EAN13_index[10][2] = {
+static const unsigned EAN13_index[10][2] = {
        {0, 6},
        {6, 1},
        {7, 1},
@@ -23,7 +23,7 @@ const unsigned EAN13_index[10][2] = {
        {90, 17},
        {107, 12},
 };
-const char *EAN13_range[][2] = {
+static const char *EAN13_range[][2] = {
        {"000", "019"},                         /* GS1 US */
        {"020", "029"},                         /* Restricted distribution (MO 
defined) */
        {"030", "039"},                         /* GS1 US */
diff --git a/contrib/isn/ISBN.h b/contrib/isn/ISBN.h
index dbda6fb7241..30002899893 100644
--- a/contrib/isn/ISBN.h
+++ b/contrib/isn/ISBN.h
@@ -34,7 +34,7 @@
  */
 
 /* where the digit set begins, and how many of them are in the table */
-const unsigned ISBN_index[10][2] = {
+static const unsigned ISBN_index[10][2] = {
        {0, 6},
        {6, 6},
        {12, 8},
@@ -47,7 +47,7 @@ const unsigned ISBN_index[10][2] = {
        {192, 718},
 };
 
-const char *ISBN_range[][2] = {
+static const char *ISBN_range[][2] = {
        {"0-00", "0-19"},
        {"0-200", "0-699"},
        {"0-7000", "0-8499"},
@@ -967,7 +967,7 @@ const char *ISBN_range[][2] = {
  */
 
 /* where the digit set begins, and how many of them are in the table */
-const unsigned ISBN_index_new[10][2] = {
+static const unsigned ISBN_index_new[10][2] = {
        {0, 0},
        {0, 5},
        {5, 0},
@@ -980,7 +980,7 @@ const unsigned ISBN_index_new[10][2] = {
        {5, 0},
 };
 
-const char *ISBN_range_new[][2] = {
+static const char *ISBN_range_new[][2] = {
        {"10-00", "10-19"},
        {"10-200", "10-699"},
        {"10-7000", "10-8999"},
diff --git a/contrib/isn/ISMN.h b/contrib/isn/ISMN.h
index 281f2cdefcd..d8af1ed0443 100644
--- a/contrib/isn/ISMN.h
+++ b/contrib/isn/ISMN.h
@@ -30,7 +30,7 @@
  */
 
 /* where the digit set begins, and how many of them are in the table */
-const unsigned ISMN_index[10][2] = {
+static const unsigned ISMN_index[10][2] = {
        {0, 5},
        {5, 0},
        {5, 0},
@@ -42,7 +42,7 @@ const unsigned ISMN_index[10][2] = {
        {5, 0},
        {5, 0},
 };
-const char *ISMN_range[][2] = {
+static const char *ISMN_range[][2] = {
        {"0-000", "0-099"},
        {"0-1000", "0-3999"},
        {"0-40000", "0-69999"},
diff --git a/contrib/isn/ISSN.h b/contrib/isn/ISSN.h
index 585f0e26741..fe6fc7fb988 100644
--- a/contrib/isn/ISSN.h
+++ b/contrib/isn/ISSN.h
@@ -31,7 +31,7 @@
  */
 
 /* where the digit set begins, and how many of them are in the table */
-const unsigned ISSN_index[10][2] = {
+static const unsigned ISSN_index[10][2] = {
        {0, 1},
        {0, 1},
        {0, 1},
@@ -43,7 +43,7 @@ const unsigned ISSN_index[10][2] = {
        {0, 1},
        {0, 1},
 };
-const char *ISSN_range[][2] = {
+static const char *ISSN_range[][2] = {
        {"0000-000", "9999-999"},
        {NULL, NULL}
 };
diff --git a/contrib/isn/UPC.h b/contrib/isn/UPC.h
index b95473e12df..01b9f155925 100644
--- a/contrib/isn/UPC.h
+++ b/contrib/isn/UPC.h
@@ -11,7 +11,7 @@
  */
 
 /* where the digit set begins, and how many of them are in the table */
-const unsigned UPC_index[10][2] = {
+static const unsigned UPC_index[10][2] = {
        {0, 0},
        {0, 0},
        {0, 0},
@@ -23,6 +23,6 @@ const unsigned UPC_index[10][2] = {
        {0, 0},
        {0, 0},
 };
-const char *UPC_range[][2] = {
+static const char *UPC_range[][2] = {
        {NULL, NULL}
 };
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index c75cde2e8e1..104b66e4b43 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -84,8 +84,8 @@ typedef struct
 /* GUC parameters */
 int                    Password_encryption = PASSWORD_TYPE_SCRAM_SHA_256;
 char      *createrole_self_grant = "";
-bool           createrole_self_grant_enabled = false;
-GrantRoleOptions createrole_self_grant_options;
+static bool createrole_self_grant_enabled = false;
+static GrantRoleOptions createrole_self_grant_options;
 
 /* Hook to check passwords in CreateRole() and AlterRole() */
 check_password_hook_type check_password_hook = NULL;
diff --git a/src/backend/postmaster/launch_backend.c 
b/src/backend/postmaster/launch_backend.c
index bdfa238e4fe..bb1b0ac2b9c 100644
--- a/src/backend/postmaster/launch_backend.c
+++ b/src/backend/postmaster/launch_backend.c
@@ -176,7 +176,7 @@ typedef struct
        bool            shmem_attach;
 } child_process_kind;
 
-child_process_kind child_process_kinds[] = {
+static child_process_kind child_process_kinds[] = {
        [B_INVALID] = {"invalid", NULL, false},
 
        [B_BACKEND] = {"backend", BackendMain, true},
diff --git a/src/backend/replication/logical/slotsync.c 
b/src/backend/replication/logical/slotsync.c
index 56d3fb5d0e5..4737a774f77 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -103,7 +103,7 @@ typedef struct SlotSyncCtxStruct
        slock_t         mutex;
 } SlotSyncCtxStruct;
 
-SlotSyncCtxStruct *SlotSyncCtx = NULL;
+static SlotSyncCtxStruct *SlotSyncCtx = NULL;
 
 /* GUC variable */
 bool           sync_replication_slots = false;
diff --git a/src/backend/replication/logical/worker.c 
b/src/backend/replication/logical/worker.c
index b5a80fe3e84..3b285894dbe 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -275,7 +275,7 @@ typedef enum
 } TransApplyAction;
 
 /* errcontext tracker */
-ApplyErrorCallbackArg apply_error_callback_arg =
+static ApplyErrorCallbackArg apply_error_callback_arg =
 {
        .command = 0,
        .rel = NULL,
diff --git a/src/backend/utils/misc/guc_tables.c 
b/src/backend/utils/misc/guc_tables.c
index 46c258be282..a5f1cafb57b 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -517,7 +517,8 @@ bool                check_function_bodies = true;
  * This GUC exists solely for backward compatibility, check its definition for
  * details.
  */
-bool           default_with_oids = false;
+static bool default_with_oids = false;
+
 bool           current_role_is_superuser;
 
 int                    log_min_error_statement = ERROR;
@@ -555,7 +556,7 @@ int                 tcp_user_timeout;
  * This avoids breaking compatibility with clients that have never supported
  * renegotiation and therefore always try to zero it.
  */
-int                    ssl_renegotiation_limit;
+static int     ssl_renegotiation_limit;
 
 /*
  * This really belongs in pg_shmem.c, but is defined here so that it doesn't
@@ -563,7 +564,7 @@ int                 ssl_renegotiation_limit;
  */
 int                    huge_pages = HUGE_PAGES_TRY;
 int                    huge_page_size;
-int                    huge_pages_status = HUGE_PAGES_UNKNOWN;
+static int     huge_pages_status = HUGE_PAGES_UNKNOWN;
 
 /*
  * These variables are all dummies that don't do anything, except in some
diff --git a/src/bin/pg_archivecleanup/pg_archivecleanup.c 
b/src/bin/pg_archivecleanup/pg_archivecleanup.c
index 07bf356b70c..5a124385b7c 100644
--- a/src/bin/pg_archivecleanup/pg_archivecleanup.c
+++ b/src/bin/pg_archivecleanup/pg_archivecleanup.c
@@ -19,17 +19,18 @@
 #include "common/logging.h"
 #include "getopt_long.h"
 
-const char *progname;
+static const char *progname;
 
 /* Options and defaults */
-bool           dryrun = false;         /* are we performing a dry-run 
operation? */
-bool           cleanBackupHistory = false; /* remove files including backup
+static bool dryrun = false;            /* are we performing a dry-run 
operation? */
+static bool cleanBackupHistory = false; /* remove files including backup
                                                                                
 * history files */
-char      *additional_ext = NULL;      /* Extension to remove from filenames */
+static char *additional_ext = NULL; /* Extension to remove from filenames */
 
-char      *archiveLocation;    /* where to find the archive? */
-char      *restartWALFileName; /* the file from which we can restart restore */
-char           exclusiveCleanupFileName[MAXFNAMELEN];  /* the oldest file we 
want
+static char *archiveLocation;  /* where to find the archive? */
+static char *restartWALFileName;       /* the file from which we can restart
+                                                                        * 
restore */
+static char exclusiveCleanupFileName[MAXFNAMELEN];     /* the oldest file we 
want
                                                                                
                         * to remain in archive */
 
 
diff --git a/src/bin/pg_basebackup/bbstreamer_file.c 
b/src/bin/pg_basebackup/bbstreamer_file.c
index 0be39dddc97..bab6cd4a6b1 100644
--- a/src/bin/pg_basebackup/bbstreamer_file.c
+++ b/src/bin/pg_basebackup/bbstreamer_file.c
@@ -43,7 +43,7 @@ static void bbstreamer_plain_writer_content(bbstreamer 
*streamer,
 static void bbstreamer_plain_writer_finalize(bbstreamer *streamer);
 static void bbstreamer_plain_writer_free(bbstreamer *streamer);
 
-const bbstreamer_ops bbstreamer_plain_writer_ops = {
+static const bbstreamer_ops bbstreamer_plain_writer_ops = {
        .content = bbstreamer_plain_writer_content,
        .finalize = bbstreamer_plain_writer_finalize,
        .free = bbstreamer_plain_writer_free
@@ -59,7 +59,7 @@ static void extract_directory(const char *filename, mode_t 
mode);
 static void extract_link(const char *filename, const char *linktarget);
 static FILE *create_file_for_extract(const char *filename, mode_t mode);
 
-const bbstreamer_ops bbstreamer_extractor_ops = {
+static const bbstreamer_ops bbstreamer_extractor_ops = {
        .content = bbstreamer_extractor_content,
        .finalize = bbstreamer_extractor_finalize,
        .free = bbstreamer_extractor_free
diff --git a/src/bin/pg_basebackup/bbstreamer_gzip.c 
b/src/bin/pg_basebackup/bbstreamer_gzip.c
index 4659314afd2..0417fd9bc2c 100644
--- a/src/bin/pg_basebackup/bbstreamer_gzip.c
+++ b/src/bin/pg_basebackup/bbstreamer_gzip.c
@@ -45,7 +45,7 @@ static void bbstreamer_gzip_writer_finalize(bbstreamer 
*streamer);
 static void bbstreamer_gzip_writer_free(bbstreamer *streamer);
 static const char *get_gz_error(gzFile gzf);
 
-const bbstreamer_ops bbstreamer_gzip_writer_ops = {
+static const bbstreamer_ops bbstreamer_gzip_writer_ops = {
        .content = bbstreamer_gzip_writer_content,
        .finalize = bbstreamer_gzip_writer_finalize,
        .free = bbstreamer_gzip_writer_free
@@ -60,7 +60,7 @@ static void bbstreamer_gzip_decompressor_free(bbstreamer 
*streamer);
 static void *gzip_palloc(void *opaque, unsigned items, unsigned size);
 static void gzip_pfree(void *opaque, void *address);
 
-const bbstreamer_ops bbstreamer_gzip_decompressor_ops = {
+static const bbstreamer_ops bbstreamer_gzip_decompressor_ops = {
        .content = bbstreamer_gzip_decompressor_content,
        .finalize = bbstreamer_gzip_decompressor_finalize,
        .free = bbstreamer_gzip_decompressor_free
diff --git a/src/bin/pg_basebackup/bbstreamer_inject.c 
b/src/bin/pg_basebackup/bbstreamer_inject.c
index 1f598091819..2191cf47772 100644
--- a/src/bin/pg_basebackup/bbstreamer_inject.c
+++ b/src/bin/pg_basebackup/bbstreamer_inject.c
@@ -33,7 +33,7 @@ static void bbstreamer_recovery_injector_content(bbstreamer 
*streamer,
 static void bbstreamer_recovery_injector_finalize(bbstreamer *streamer);
 static void bbstreamer_recovery_injector_free(bbstreamer *streamer);
 
-const bbstreamer_ops bbstreamer_recovery_injector_ops = {
+static const bbstreamer_ops bbstreamer_recovery_injector_ops = {
        .content = bbstreamer_recovery_injector_content,
        .finalize = bbstreamer_recovery_injector_finalize,
        .free = bbstreamer_recovery_injector_free
diff --git a/src/bin/pg_basebackup/bbstreamer_lz4.c 
b/src/bin/pg_basebackup/bbstreamer_lz4.c
index eda62caeded..f5c9e68150c 100644
--- a/src/bin/pg_basebackup/bbstreamer_lz4.c
+++ b/src/bin/pg_basebackup/bbstreamer_lz4.c
@@ -42,7 +42,7 @@ static void bbstreamer_lz4_compressor_content(bbstreamer 
*streamer,
 static void bbstreamer_lz4_compressor_finalize(bbstreamer *streamer);
 static void bbstreamer_lz4_compressor_free(bbstreamer *streamer);
 
-const bbstreamer_ops bbstreamer_lz4_compressor_ops = {
+static const bbstreamer_ops bbstreamer_lz4_compressor_ops = {
        .content = bbstreamer_lz4_compressor_content,
        .finalize = bbstreamer_lz4_compressor_finalize,
        .free = bbstreamer_lz4_compressor_free
@@ -55,7 +55,7 @@ static void bbstreamer_lz4_decompressor_content(bbstreamer 
*streamer,
 static void bbstreamer_lz4_decompressor_finalize(bbstreamer *streamer);
 static void bbstreamer_lz4_decompressor_free(bbstreamer *streamer);
 
-const bbstreamer_ops bbstreamer_lz4_decompressor_ops = {
+static const bbstreamer_ops bbstreamer_lz4_decompressor_ops = {
        .content = bbstreamer_lz4_decompressor_content,
        .finalize = bbstreamer_lz4_decompressor_finalize,
        .free = bbstreamer_lz4_decompressor_free
diff --git a/src/bin/pg_basebackup/bbstreamer_tar.c 
b/src/bin/pg_basebackup/bbstreamer_tar.c
index dec71ea65b3..6df3b97f9cb 100644
--- a/src/bin/pg_basebackup/bbstreamer_tar.c
+++ b/src/bin/pg_basebackup/bbstreamer_tar.c
@@ -50,7 +50,7 @@ static void bbstreamer_tar_parser_finalize(bbstreamer 
*streamer);
 static void bbstreamer_tar_parser_free(bbstreamer *streamer);
 static bool bbstreamer_tar_header(bbstreamer_tar_parser *mystreamer);
 
-const bbstreamer_ops bbstreamer_tar_parser_ops = {
+static const bbstreamer_ops bbstreamer_tar_parser_ops = {
        .content = bbstreamer_tar_parser_content,
        .finalize = bbstreamer_tar_parser_finalize,
        .free = bbstreamer_tar_parser_free
@@ -63,7 +63,7 @@ static void bbstreamer_tar_archiver_content(bbstreamer 
*streamer,
 static void bbstreamer_tar_archiver_finalize(bbstreamer *streamer);
 static void bbstreamer_tar_archiver_free(bbstreamer *streamer);
 
-const bbstreamer_ops bbstreamer_tar_archiver_ops = {
+static const bbstreamer_ops bbstreamer_tar_archiver_ops = {
        .content = bbstreamer_tar_archiver_content,
        .finalize = bbstreamer_tar_archiver_finalize,
        .free = bbstreamer_tar_archiver_free
@@ -76,7 +76,7 @@ static void bbstreamer_tar_terminator_content(bbstreamer 
*streamer,
 static void bbstreamer_tar_terminator_finalize(bbstreamer *streamer);
 static void bbstreamer_tar_terminator_free(bbstreamer *streamer);
 
-const bbstreamer_ops bbstreamer_tar_terminator_ops = {
+static const bbstreamer_ops bbstreamer_tar_terminator_ops = {
        .content = bbstreamer_tar_terminator_content,
        .finalize = bbstreamer_tar_terminator_finalize,
        .free = bbstreamer_tar_terminator_free
diff --git a/src/bin/pg_basebackup/bbstreamer_zstd.c 
b/src/bin/pg_basebackup/bbstreamer_zstd.c
index 9e09f8f90bf..20f11d4450e 100644
--- a/src/bin/pg_basebackup/bbstreamer_zstd.c
+++ b/src/bin/pg_basebackup/bbstreamer_zstd.c
@@ -38,7 +38,7 @@ static void bbstreamer_zstd_compressor_content(bbstreamer 
*streamer,
 static void bbstreamer_zstd_compressor_finalize(bbstreamer *streamer);
 static void bbstreamer_zstd_compressor_free(bbstreamer *streamer);
 
-const bbstreamer_ops bbstreamer_zstd_compressor_ops = {
+static const bbstreamer_ops bbstreamer_zstd_compressor_ops = {
        .content = bbstreamer_zstd_compressor_content,
        .finalize = bbstreamer_zstd_compressor_finalize,
        .free = bbstreamer_zstd_compressor_free
@@ -51,7 +51,7 @@ static void bbstreamer_zstd_decompressor_content(bbstreamer 
*streamer,
 static void bbstreamer_zstd_decompressor_finalize(bbstreamer *streamer);
 static void bbstreamer_zstd_decompressor_free(bbstreamer *streamer);
 
-const bbstreamer_ops bbstreamer_zstd_decompressor_ops = {
+static const bbstreamer_ops bbstreamer_zstd_decompressor_ops = {
        .content = bbstreamer_zstd_decompressor_content,
        .finalize = bbstreamer_zstd_decompressor_finalize,
        .free = bbstreamer_zstd_decompressor_free
diff --git a/src/bin/pg_basebackup/walmethods.c 
b/src/bin/pg_basebackup/walmethods.c
index f17600de9d2..832aafd2973 100644
--- a/src/bin/pg_basebackup/walmethods.c
+++ b/src/bin/pg_basebackup/walmethods.c
@@ -55,7 +55,7 @@ static int    dir_sync(Walfile *f);
 static bool dir_finish(WalWriteMethod *wwmethod);
 static void dir_free(WalWriteMethod *wwmethod);
 
-const WalWriteMethodOps WalDirectoryMethodOps = {
+static const WalWriteMethodOps WalDirectoryMethodOps = {
        .open_for_write = dir_open_for_write,
        .close = dir_close,
        .existsfile = dir_existsfile,
@@ -676,7 +676,7 @@ static int  tar_sync(Walfile *f);
 static bool tar_finish(WalWriteMethod *wwmethod);
 static void tar_free(WalWriteMethod *wwmethod);
 
-const WalWriteMethodOps WalTarMethodOps = {
+static const WalWriteMethodOps WalTarMethodOps = {
        .open_for_write = tar_open_for_write,
        .close = tar_close,
        .existsfile = tar_existsfile,
diff --git a/src/bin/pg_checksums/pg_checksums.c 
b/src/bin/pg_checksums/pg_checksums.c
index 9e6fd435f60..b5bb0e78875 100644
--- a/src/bin/pg_checksums/pg_checksums.c
+++ b/src/bin/pg_checksums/pg_checksums.c
@@ -60,8 +60,8 @@ static const char *progname;
 /*
  * Progress status information.
  */
-int64          total_size = 0;
-int64          current_size = 0;
+static int64 total_size = 0;
+static int64 current_size = 0;
 static pg_time_t last_progress_report = 0;
 
 static void
diff --git a/src/bin/pg_combinebackup/pg_combinebackup.c 
b/src/bin/pg_combinebackup/pg_combinebackup.c
index f4a1f499536..0aabd8494eb 100644
--- a/src/bin/pg_combinebackup/pg_combinebackup.c
+++ b/src/bin/pg_combinebackup/pg_combinebackup.c
@@ -89,7 +89,7 @@ typedef struct cb_tablespace
 } cb_tablespace;
 
 /* Directories to be removed if we exit uncleanly. */
-cb_cleanup_dir *cleanup_dir_list = NULL;
+static cb_cleanup_dir *cleanup_dir_list = NULL;
 
 static void add_tablespace_mapping(cb_options *opt, char *arg);
 static StringInfo check_backup_label_files(int n_backups, char **backup_dirs);
diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c
index 8dfea05846e..0841ab4135b 100644
--- a/src/bin/pg_rewind/pg_rewind.c
+++ b/src/bin/pg_rewind/pg_rewind.c
@@ -60,21 +60,21 @@ static ControlFileData ControlFile_target;
 static ControlFileData ControlFile_source;
 static ControlFileData ControlFile_source_after;
 
-const char *progname;
+static const char *progname;
 int                    WalSegSz;
 
 /* Configuration options */
 char      *datadir_target = NULL;
-char      *datadir_source = NULL;
-char      *connstr_source = NULL;
-char      *restore_command = NULL;
-char      *config_file = NULL;
+static char *datadir_source = NULL;
+static char *connstr_source = NULL;
+static char *restore_command = NULL;
+static char *config_file = NULL;
 
 static bool debug = false;
 bool           showprogress = false;
 bool           dry_run = false;
 bool           do_sync = true;
-bool           restore_wal = false;
+static bool restore_wal = false;
 DataDirSyncMethod sync_method = DATA_DIR_SYNC_METHOD_FSYNC;
 
 /* Target history */
diff --git a/src/bin/pg_test_timing/pg_test_timing.c 
b/src/bin/pg_test_timing/pg_test_timing.c
index c29d6f87629..ce7aad4b25a 100644
--- a/src/bin/pg_test_timing/pg_test_timing.c
+++ b/src/bin/pg_test_timing/pg_test_timing.c
@@ -20,7 +20,7 @@ static uint64 test_timing(unsigned int duration);
 static void output(uint64 loop_count);
 
 /* record duration in powers of 2 microseconds */
-long long int histogram[32];
+static long long int histogram[32];
 
 int
 main(int argc, char *argv[])
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index 86ffb3c8683..e3dc6f9b190 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -170,37 +170,37 @@ typedef struct socket_set
 #define MIN_ZIPFIAN_PARAM              1.001   /* minimum parameter for 
zipfian */
 #define MAX_ZIPFIAN_PARAM              1000.0  /* maximum parameter for 
zipfian */
 
-int                    nxacts = 0;                     /* number of 
transactions per client */
-int                    duration = 0;           /* duration in seconds */
-int64          end_time = 0;           /* when to stop in micro seconds, under 
-T */
+static int     nxacts = 0;                     /* number of transactions per 
client */
+static int     duration = 0;           /* duration in seconds */
+static int64 end_time = 0;             /* when to stop in micro seconds, under 
-T */
 
 /*
  * scaling factor. for example, scale = 10 will make 1000000 tuples in
  * pgbench_accounts table.
  */
-int                    scale = 1;
+static int     scale = 1;
 
 /*
  * fillfactor. for example, fillfactor = 90 will use only 90 percent
  * space during inserts and leave 10 percent free.
  */
-int                    fillfactor = 100;
+static int     fillfactor = 100;
 
 /*
  * use unlogged tables?
  */
-bool           unlogged_tables = false;
+static bool unlogged_tables = false;
 
 /*
  * log sampling rate (1.0 = log everything, 0.0 = option not given)
  */
-double         sample_rate = 0.0;
+static double sample_rate = 0.0;
 
 /*
  * When threads are throttled to a given rate limit, this is the target delay
  * to reach that rate in usec.  0 is the default and means no throttling.
  */
-double         throttle_delay = 0;
+static double throttle_delay = 0;
 
 /*
  * Transactions which take longer than this limit (in usec) are counted as
@@ -208,13 +208,13 @@ double            throttle_delay = 0;
  * throttling is enabled, execution time slots that are more than this late
  * are skipped altogether, and counted separately.
  */
-int64          latency_limit = 0;
+static int64 latency_limit = 0;
 
 /*
  * tablespace selection
  */
-char      *tablespace = NULL;
-char      *index_tablespace = NULL;
+static char *tablespace = NULL;
+static char *index_tablespace = NULL;
 
 /*
  * Number of "pgbench_accounts" partitions.  0 is the default and means no
@@ -234,7 +234,7 @@ static partition_method_t partition_method = PART_NONE;
 static const char *const PARTITION_METHOD[] = {"none", "range", "hash"};
 
 /* random seed used to initialize base_random_sequence */
-int64          random_seed = -1;
+static int64 random_seed = -1;
 
 /*
  * end of configurable parameters
@@ -254,20 +254,20 @@ int64             random_seed = -1;
  */
 #define SCALE_32BIT_THRESHOLD 20000
 
-bool           use_log;                        /* log transaction latencies to 
a file */
-bool           use_quiet;                      /* quiet logging onto stderr */
-int                    agg_interval;           /* log aggregates instead of 
individual
+static bool use_log;                   /* log transaction latencies to a file 
*/
+static bool use_quiet;                 /* quiet logging onto stderr */
+static int     agg_interval;           /* log aggregates instead of individual
                                                                 * transactions 
*/
-bool           per_script_stats = false;       /* whether to collect stats per 
script */
-int                    progress = 0;           /* thread progress report every 
this seconds */
-bool           progress_timestamp = false; /* progress report with Unix time */
-int                    nclients = 1;           /* number of clients */
-int                    nthreads = 1;           /* number of threads */
-bool           is_connect;                     /* establish connection for 
each transaction */
-bool           report_per_command = false; /* report per-command latencies,
+static bool per_script_stats = false;  /* whether to collect stats per script 
*/
+static int     progress = 0;           /* thread progress report every this 
seconds */
+static bool progress_timestamp = false; /* progress report with Unix time */
+static int     nclients = 1;           /* number of clients */
+static int     nthreads = 1;           /* number of threads */
+static bool is_connect;                        /* establish connection for 
each transaction */
+static bool report_per_command = false; /* report per-command latencies,
                                                                                
 * retries after errors and failures
                                                                                
 * (errors without retrying) */
-int                    main_pid;                       /* main process id used 
in log filename */
+static int     main_pid;                       /* main process id used in log 
filename */
 
 /*
  * There are different types of restrictions for deciding that the current
@@ -287,21 +287,22 @@ int                       main_pid;                       
/* main process id used in log filename */
  * We cannot retry a transaction after the serialization/deadlock error if its
  * number of tries reaches this maximum; if its value is zero, it is not used.
  */
-uint32         max_tries = 1;
+static uint32 max_tries = 1;
 
-bool           failures_detailed = false;      /* whether to group failures in
+static bool failures_detailed = false; /* whether to group failures in
                                                                                
 * reports or logs by basic types */
 
-const char *pghost = NULL;
-const char *pgport = NULL;
-const char *username = NULL;
-const char *dbName = NULL;
-char      *logfile_prefix = NULL;
-const char *progname;
+static const char *pghost = NULL;
+static const char *pgport = NULL;
+static const char *username = NULL;
+static const char *dbName = NULL;
+static char *logfile_prefix = NULL;
+static const char *progname;
 
 #define WSEP '@'                               /* weight separator */
 
-volatile sig_atomic_t timer_exceeded = false;  /* flag from signal handler */
+volatile static sig_atomic_t timer_exceeded = false;   /* flag from signal
+                                                                               
                                 * handler */
 
 /*
  * We don't want to allocate variables one by one; for efficiency, add a
@@ -446,7 +447,7 @@ typedef struct StatsData
  * For displaying Unix epoch timestamps, as some time functions may have
  * another reference.
  */
-pg_time_usec_t epoch_shift;
+static pg_time_usec_t epoch_shift;
 
 /*
  * Error status for errors during script execution.
diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 7138c6e97e4..7c33e13e1ac 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -60,7 +60,7 @@ typedef enum
        OBJFILTER_SCHEMA_EXCLUDE = (1 << 4),    /* -N | --exclude-schema */
 } VacObjFilter;
 
-VacObjFilter objfilter = OBJFILTER_NONE;
+static VacObjFilter objfilter = OBJFILTER_NONE;
 
 static void vacuum_one_database(ConnParams *cparams,
                                                                
vacuumingOptions *vacopts,
diff --git a/src/pl/plpgsql/src/pl_handler.c b/src/pl/plpgsql/src/pl_handler.c
index fce459ade08..980f0961bc8 100644
--- a/src/pl/plpgsql/src/pl_handler.c
+++ b/src/pl/plpgsql/src/pl_handler.c
@@ -47,8 +47,8 @@ bool          plpgsql_print_strict_params = false;
 
 bool           plpgsql_check_asserts = true;
 
-char      *plpgsql_extra_warnings_string = NULL;
-char      *plpgsql_extra_errors_string = NULL;
+static char *plpgsql_extra_warnings_string = NULL;
+static char *plpgsql_extra_errors_string = NULL;
 int                    plpgsql_extra_warnings;
 int                    plpgsql_extra_errors;
 
diff --git a/src/test/isolation/isolation_main.c 
b/src/test/isolation/isolation_main.c
index 2a3e41d2101..8b108a31b11 100644
--- a/src/test/isolation/isolation_main.c
+++ b/src/test/isolation/isolation_main.c
@@ -15,9 +15,9 @@
 #include "lib/stringinfo.h"
 #include "pg_regress.h"
 
-char           saved_argv0[MAXPGPATH];
-char           isolation_exec[MAXPGPATH];
-bool           looked_up_isolation_exec = false;
+static char saved_argv0[MAXPGPATH];
+static char isolation_exec[MAXPGPATH];
+static bool looked_up_isolation_exec = false;
 
 #define PG_ISOLATION_VERSIONSTR "isolationtester (PostgreSQL) " PG_VERSION "\n"
 
diff --git a/src/test/modules/dummy_index_am/dummy_index_am.c 
b/src/test/modules/dummy_index_am/dummy_index_am.c
index 18185d02067..0b477116067 100644
--- a/src/test/modules/dummy_index_am/dummy_index_am.c
+++ b/src/test/modules/dummy_index_am/dummy_index_am.c
@@ -24,10 +24,10 @@
 PG_MODULE_MAGIC;
 
 /* parse table for fillRelOptions */
-relopt_parse_elt di_relopt_tab[6];
+static relopt_parse_elt di_relopt_tab[6];
 
 /* Kind of relation options for dummy index */
-relopt_kind di_relopt_kind;
+static relopt_kind di_relopt_kind;
 
 typedef enum DummyAmEnum
 {
@@ -47,7 +47,7 @@ typedef struct DummyIndexOptions
        int                     option_string_null_offset;
 }                      DummyIndexOptions;
 
-relopt_enum_elt_def dummyAmEnumValues[] =
+static relopt_enum_elt_def dummyAmEnumValues[] =
 {
        {"one", DUMMY_AM_ENUM_ONE},
        {"two", DUMMY_AM_ENUM_TWO},
diff --git a/src/test/modules/libpq_pipeline/libpq_pipeline.c 
b/src/test/modules/libpq_pipeline/libpq_pipeline.c
index ac4d26302cc..999a7f57a7e 100644
--- a/src/test/modules/libpq_pipeline/libpq_pipeline.c
+++ b/src/test/modules/libpq_pipeline/libpq_pipeline.c
@@ -31,10 +31,10 @@ static void pg_attribute_noreturn() pg_fatal_impl(int line, 
const char *fmt,...)
 static bool process_result(PGconn *conn, PGresult *res, int results,
                                                   int numsent);
 
-const char *const progname = "libpq_pipeline";
+static const char *const progname = "libpq_pipeline";
 
 /* Options and defaults */
-char      *tracefile = NULL;   /* path to PQtrace() file */
+static char *tracefile = NULL; /* path to PQtrace() file */
 
 
 #ifdef DEBUG_OUTPUT
diff --git a/src/test/modules/test_json_parser/test_json_parser_incremental.c 
b/src/test/modules/test_json_parser/test_json_parser_incremental.c
index 7cd3dcf276b..f4c442ac365 100644
--- a/src/test/modules/test_json_parser/test_json_parser_incremental.c
+++ b/src/test/modules/test_json_parser/test_json_parser_incremental.c
@@ -60,7 +60,7 @@ static JsonParseErrorType do_array_element_start(void *state, 
bool isnull);
 static JsonParseErrorType do_array_element_end(void *state, bool isnull);
 static JsonParseErrorType do_scalar(void *state, char *token, JsonTokenType 
tokentype);
 
-JsonSemAction sem = {
+static JsonSemAction sem = {
        .object_start = do_object_start,
        .object_end = do_object_end,
        .object_field_start = do_object_field_start,
-- 
2.45.2

From c02690328c9d066048ab014e3c8e3e3167a8d259 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 May 2024 13:49:37 +0200
Subject: [PATCH v2 03/10] Add missing includes

src/backend/libpq/pqcomm.c: "postmaster/postmaster.h" for Unix_socket_group, 
Unix_socket_permissions
src/backend/utils/init/globals.c: "postmaster/postmaster.h" for MyClientSocket
src/backend/utils/misc/guc_tables.c: "utils/rls.h" for row_security
src/backend/utils/sort/tuplesort.c: "utils/guc.h" for trace_sort

Discussion: 
https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c9...@eisentraut.org
---
 src/backend/libpq/pqcomm.c          | 1 +
 src/backend/utils/init/globals.c    | 1 +
 src/backend/utils/misc/guc_tables.c | 1 +
 src/backend/utils/sort/tuplesort.c  | 1 +
 4 files changed, 4 insertions(+)

diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c
index daa0696146d..896e1476b50 100644
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -76,6 +76,7 @@
 #include "libpq/libpq.h"
 #include "miscadmin.h"
 #include "port/pg_bswap.h"
+#include "postmaster/postmaster.h"
 #include "storage/ipc.h"
 #include "utils/guc_hooks.h"
 #include "utils/memutils.h"
diff --git a/src/backend/utils/init/globals.c b/src/backend/utils/init/globals.c
index cc61937eef7..927bccfbea8 100644
--- a/src/backend/utils/init/globals.c
+++ b/src/backend/utils/init/globals.c
@@ -22,6 +22,7 @@
 #include "libpq/libpq-be.h"
 #include "libpq/pqcomm.h"
 #include "miscadmin.h"
+#include "postmaster/postmaster.h"
 #include "storage/procnumber.h"
 
 
diff --git a/src/backend/utils/misc/guc_tables.c 
b/src/backend/utils/misc/guc_tables.c
index a5f1cafb57b..bdd18ed7fce 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -87,6 +87,7 @@
 #include "utils/pg_locale.h"
 #include "utils/plancache.h"
 #include "utils/ps_status.h"
+#include "utils/rls.h"
 #include "utils/xml.h"
 
 /* This value is normally passed in from the Makefile */
diff --git a/src/backend/utils/sort/tuplesort.c 
b/src/backend/utils/sort/tuplesort.c
index 7c4d6dc106b..a3921373c59 100644
--- a/src/backend/utils/sort/tuplesort.c
+++ b/src/backend/utils/sort/tuplesort.c
@@ -105,6 +105,7 @@
 #include "miscadmin.h"
 #include "pg_trace.h"
 #include "storage/shmem.h"
+#include "utils/guc.h"
 #include "utils/memutils.h"
 #include "utils/pg_rusage.h"
 #include "utils/tuplesort.h"
-- 
2.45.2

From c4409afd467abf9c560879245018f4024a41d3c8 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Sun, 16 Jun 2024 21:33:43 +0200
Subject: [PATCH v2 04/10] Improve some global variable declarations

We have in launch_backend.c:

    /*
     * The following need to be available to the save/restore_backend_variables
     * functions.  They are marked NON_EXEC_STATIC in their home modules.
     */
    extern slock_t *ShmemLock;
    extern slock_t *ProcStructLock;
    extern PGPROC *AuxiliaryProcs;
    extern PMSignalData *PMSignalState;
    extern pg_time_t first_syslogger_file_time;
    extern struct bkend *ShmemBackendArray;
    extern bool redirection_done;

That comment is not completely true: ShmemLock, ShmemBackendArray, and
redirection_done are not in fact NON_EXEC_STATIC.  ShmemLock once was,
but was then needed elsewhere.  ShmemBackendArray was static inside
postmaster.c before launch_backend.c was created.  redirection_done
was never static.

This patch moves the declaration of ShmemLock and redirection_done to
a header file.

ShmemBackendArray gets a NON_EXEC_STATIC.  This doesn't make a
difference, since it only exists if EXEC_BACKEND anyway, but it makes
it consistent.

After that, the comment is now correct.

Discussion: 
https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c9...@eisentraut.org
---
 src/backend/postmaster/launch_backend.c | 2 --
 src/backend/postmaster/postmaster.c     | 2 +-
 src/backend/postmaster/syslogger.c      | 2 --
 src/backend/storage/lmgr/lwlock.c       | 4 +---
 src/backend/utils/error/elog.c          | 2 --
 src/include/postmaster/postmaster.h     | 1 +
 src/include/storage/shmem.h             | 2 ++
 7 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/backend/postmaster/launch_backend.c 
b/src/backend/postmaster/launch_backend.c
index bb1b0ac2b9c..49e4be4b399 100644
--- a/src/backend/postmaster/launch_backend.c
+++ b/src/backend/postmaster/launch_backend.c
@@ -672,13 +672,11 @@ SubPostmasterMain(int argc, char *argv[])
  * The following need to be available to the save/restore_backend_variables
  * functions.  They are marked NON_EXEC_STATIC in their home modules.
  */
-extern slock_t *ShmemLock;
 extern slock_t *ProcStructLock;
 extern PGPROC *AuxiliaryProcs;
 extern PMSignalData *PMSignalState;
 extern pg_time_t first_syslogger_file_time;
 extern struct bkend *ShmemBackendArray;
-extern bool redirection_done;
 
 #ifndef WIN32
 #define write_inheritable_socket(dest, src, childpid) ((*(dest) = (src)), true)
diff --git a/src/backend/postmaster/postmaster.c 
b/src/backend/postmaster/postmaster.c
index bf0241aed0c..97c8332c84d 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -179,7 +179,7 @@ typedef struct bkend
 static dlist_head BackendList = DLIST_STATIC_INIT(BackendList);
 
 #ifdef EXEC_BACKEND
-Backend    *ShmemBackendArray;
+NON_EXEC_STATIC Backend *ShmemBackendArray;
 #endif
 
 BackgroundWorker *MyBgworkerEntry = NULL;
diff --git a/src/backend/postmaster/syslogger.c 
b/src/backend/postmaster/syslogger.c
index 437947dbb9d..7951599fa87 100644
--- a/src/backend/postmaster/syslogger.c
+++ b/src/backend/postmaster/syslogger.c
@@ -75,8 +75,6 @@ char     *Log_filename = NULL;
 bool           Log_truncate_on_rotation = false;
 int                    Log_file_mode = S_IRUSR | S_IWUSR;
 
-extern bool redirection_done;
-
 /*
  * Private state
  */
diff --git a/src/backend/storage/lmgr/lwlock.c 
b/src/backend/storage/lmgr/lwlock.c
index b1e388dc7c9..e765754d805 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -91,9 +91,6 @@
 #endif
 
 
-/* We use the ShmemLock spinlock to protect LWLockCounter */
-extern slock_t *ShmemLock;
-
 #define LW_FLAG_HAS_WAITERS                    ((uint32) 1 << 30)
 #define LW_FLAG_RELEASE_OK                     ((uint32) 1 << 29)
 #define LW_FLAG_LOCKED                         ((uint32) 1 << 28)
@@ -609,6 +606,7 @@ LWLockNewTrancheId(void)
        int                *LWLockCounter;
 
        LWLockCounter = (int *) ((char *) MainLWLockArray - sizeof(int));
+       /* We use the ShmemLock spinlock to protect LWLockCounter */
        SpinLockAcquire(ShmemLock);
        result = (*LWLockCounter)++;
        SpinLockRelease(ShmemLock);
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index d91a85cb2d7..e9077714211 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -95,8 +95,6 @@ ErrorContextCallback *error_context_stack = NULL;
 
 sigjmp_buf *PG_exception_stack = NULL;
 
-extern bool redirection_done;
-
 /*
  * Hook for intercepting messages before they are sent to the server log.
  * Note that the hook will not get called for messages that are suppressed
diff --git a/src/include/postmaster/postmaster.h 
b/src/include/postmaster/postmaster.h
index 89ad13b788b..9feb2e4de14 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -52,6 +52,7 @@ extern PGDLLIMPORT int postmaster_alive_fds[2];
 
 extern PGDLLIMPORT const char *progname;
 
+extern PGDLLIMPORT bool redirection_done;
 extern PGDLLIMPORT bool LoadedSSL;
 
 extern void PostmasterMain(int argc, char *argv[]) pg_attribute_noreturn();
diff --git a/src/include/storage/shmem.h b/src/include/storage/shmem.h
index 3b0cc9d3800..842989111c3 100644
--- a/src/include/storage/shmem.h
+++ b/src/include/storage/shmem.h
@@ -21,10 +21,12 @@
 #ifndef SHMEM_H
 #define SHMEM_H
 
+#include "storage/spin.h"
 #include "utils/hsearch.h"
 
 
 /* shmem.c */
+extern PGDLLIMPORT slock_t *ShmemLock;
 extern void InitShmemAccess(void *seghdr);
 extern void InitShmemAllocation(void);
 extern void *ShmemAlloc(Size size);
-- 
2.45.2

From d89312042eb76c879d699380a5e2ed0bc7956605 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Sun, 16 Jun 2024 23:52:06 +0200
Subject: [PATCH v2 05/10] Fix warnings from -Wmissing-variable-declarations
 under EXEC_BACKEND

The NON_EXEC_STATIC variables need a suitable declaration in a header
file under EXEC_BACKEND.

Also fix the inconsistent application of the volatile qualifier for
PMSignalState, which was revealed by this change.

Discussion: 
https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c9...@eisentraut.org
---
 src/backend/postmaster/launch_backend.c | 12 +-----------
 src/include/postmaster/postmaster.h     |  4 ++++
 src/include/postmaster/syslogger.h      |  4 ++++
 src/include/storage/pmsignal.h          |  4 ++++
 src/include/storage/proc.h              |  5 +++++
 5 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/src/backend/postmaster/launch_backend.c 
b/src/backend/postmaster/launch_backend.c
index 49e4be4b399..2b1515043dc 100644
--- a/src/backend/postmaster/launch_backend.c
+++ b/src/backend/postmaster/launch_backend.c
@@ -114,7 +114,7 @@ typedef struct
        PROC_HDR   *ProcGlobal;
        PGPROC     *AuxiliaryProcs;
        PGPROC     *PreparedXactProcs;
-       PMSignalData *PMSignalState;
+       volatile PMSignalData *PMSignalState;
        pid_t           PostmasterPid;
        TimestampTz PgStartTime;
        TimestampTz PgReloadTime;
@@ -668,16 +668,6 @@ SubPostmasterMain(int argc, char *argv[])
        pg_unreachable();                       /* main_fn never returns */
 }
 
-/*
- * The following need to be available to the save/restore_backend_variables
- * functions.  They are marked NON_EXEC_STATIC in their home modules.
- */
-extern slock_t *ProcStructLock;
-extern PGPROC *AuxiliaryProcs;
-extern PMSignalData *PMSignalState;
-extern pg_time_t first_syslogger_file_time;
-extern struct bkend *ShmemBackendArray;
-
 #ifndef WIN32
 #define write_inheritable_socket(dest, src, childpid) ((*(dest) = (src)), true)
 #define read_inheritable_socket(dest, src) (*(dest) = *(src))
diff --git a/src/include/postmaster/postmaster.h 
b/src/include/postmaster/postmaster.h
index 9feb2e4de14..d19e103937d 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -36,6 +36,10 @@ extern PGDLLIMPORT bool remove_temp_files_after_crash;
 extern PGDLLIMPORT bool send_abort_for_crash;
 extern PGDLLIMPORT bool send_abort_for_kill;
 
+#ifdef EXEC_BACKEND
+extern struct bkend *ShmemBackendArray;
+#endif
+
 #ifdef WIN32
 extern PGDLLIMPORT HANDLE PostmasterHandle;
 #else
diff --git a/src/include/postmaster/syslogger.h 
b/src/include/postmaster/syslogger.h
index 0f28ebcba55..b5fc239ba9c 100644
--- a/src/include/postmaster/syslogger.h
+++ b/src/include/postmaster/syslogger.h
@@ -75,6 +75,10 @@ extern PGDLLIMPORT char *Log_filename;
 extern PGDLLIMPORT bool Log_truncate_on_rotation;
 extern PGDLLIMPORT int Log_file_mode;
 
+#ifdef EXEC_BACKEND
+extern pg_time_t first_syslogger_file_time;
+#endif
+
 #ifndef WIN32
 extern PGDLLIMPORT int syslogPipe[2];
 #else
diff --git a/src/include/storage/pmsignal.h b/src/include/storage/pmsignal.h
index 029b7201093..0c9a7e32a8a 100644
--- a/src/include/storage/pmsignal.h
+++ b/src/include/storage/pmsignal.h
@@ -57,6 +57,10 @@ typedef enum
 /* PMSignalData is an opaque struct, details known only within pmsignal.c */
 typedef struct PMSignalData PMSignalData;
 
+#ifdef EXEC_BACKEND
+extern volatile PMSignalData *PMSignalState;
+#endif
+
 /*
  * prototypes for functions in pmsignal.c
  */
diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h
index 9488bf1857c..987a6e60772 100644
--- a/src/include/storage/proc.h
+++ b/src/include/storage/proc.h
@@ -454,6 +454,11 @@ extern PGDLLIMPORT int TransactionTimeout;
 extern PGDLLIMPORT int IdleSessionTimeout;
 extern PGDLLIMPORT bool log_lock_waits;
 
+#ifdef EXEC_BACKEND
+extern slock_t *ProcStructLock;
+extern PGPROC *AuxiliaryProcs;
+#endif
+
 
 /*
  * Function Prototypes
-- 
2.45.2

From 4462a4ea03f9e8bcad99589fb27eb766f077d034 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Sun, 16 Jun 2024 21:44:33 +0200
Subject: [PATCH v2 06/10] Get rid of a global variable

bootstrap_data_checksum_version can just as easily be passed to where
it is used via function arguments.

Discussion: 
https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c9...@eisentraut.org
---
 src/backend/access/transam/xlog.c | 12 +++++-------
 src/backend/bootstrap/bootstrap.c |  5 ++---
 src/include/access/xlog.h         |  2 +-
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/src/backend/access/transam/xlog.c 
b/src/backend/access/transam/xlog.c
index 330e058c5f2..c3925b944d5 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -105,8 +105,6 @@
 #include "utils/timestamp.h"
 #include "utils/varlena.h"
 
-extern uint32 bootstrap_data_checksum_version;
-
 /* timeline ID to be used when bootstrapping */
 #define BootstrapTimeLineID            1
 
@@ -683,7 +681,7 @@ static void ValidateXLOGDirectoryStructure(void);
 static void CleanupBackupHistory(void);
 static void UpdateMinRecoveryPoint(XLogRecPtr lsn, bool force);
 static bool PerformRecoveryXLogAction(void);
-static void InitControlFile(uint64 sysidentifier);
+static void InitControlFile(uint64 sysidentifier, uint32 
data_checksum_version);
 static void WriteControlFile(void);
 static void ReadControlFile(void);
 static void UpdateControlFile(void);
@@ -4190,7 +4188,7 @@ CleanupBackupHistory(void)
  */
 
 static void
-InitControlFile(uint64 sysidentifier)
+InitControlFile(uint64 sysidentifier, uint32 data_checksum_version)
 {
        char            mock_auth_nonce[MOCK_AUTH_NONCE_LEN];
 
@@ -4221,7 +4219,7 @@ InitControlFile(uint64 sysidentifier)
        ControlFile->wal_level = wal_level;
        ControlFile->wal_log_hints = wal_log_hints;
        ControlFile->track_commit_timestamp = track_commit_timestamp;
-       ControlFile->data_checksum_version = bootstrap_data_checksum_version;
+       ControlFile->data_checksum_version = data_checksum_version;
 }
 
 static void
@@ -4997,7 +4995,7 @@ XLOGShmemInit(void)
  * and the initial XLOG segment.
  */
 void
-BootStrapXLOG(void)
+BootStrapXLOG(uint32 data_checksum_version)
 {
        CheckPoint      checkPoint;
        char       *buffer;
@@ -5138,7 +5136,7 @@ BootStrapXLOG(void)
        openLogFile = -1;
 
        /* Now create pg_control */
-       InitControlFile(sysidentifier);
+       InitControlFile(sysidentifier, data_checksum_version);
        ControlFile->time = checkPoint.time;
        ControlFile->checkPoint = checkPoint.redo;
        ControlFile->checkPointCopy = checkPoint;
diff --git a/src/backend/bootstrap/bootstrap.c 
b/src/backend/bootstrap/bootstrap.c
index 986f6f1d9ca..7637581a184 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -41,8 +41,6 @@
 #include "utils/rel.h"
 #include "utils/relmapper.h"
 
-uint32         bootstrap_data_checksum_version = 0;    /* No checksum */
-
 
 static void CheckerModeMain(void);
 static void bootstrap_signals(void);
@@ -202,6 +200,7 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)
        char       *progname = argv[0];
        int                     flag;
        char       *userDoption = NULL;
+       uint32          bootstrap_data_checksum_version = 0;    /* No checksum 
*/
 
        Assert(!IsUnderPostmaster);
 
@@ -332,7 +331,7 @@ BootstrapModeMain(int argc, char *argv[], bool check_only)
        BaseInit();
 
        bootstrap_signals();
-       BootStrapXLOG();
+       BootStrapXLOG(bootstrap_data_checksum_version);
 
        /*
         * To ensure that src/common/link-canary.c is linked into the backend, 
we
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 1a1f11a943f..c40fd56b291 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -231,7 +231,7 @@ extern bool DataChecksumsEnabled(void);
 extern XLogRecPtr GetFakeLSNForUnloggedRel(void);
 extern Size XLOGShmemSize(void);
 extern void XLOGShmemInit(void);
-extern void BootStrapXLOG(void);
+extern void BootStrapXLOG(uint32 data_checksum_version);
 extern void InitializeWalConsistencyChecking(void);
 extern void LocalProcessControlFile(bool reset);
 extern WalLevel GetActiveWalLevelOnStandby(void);
-- 
2.45.2

From fd602ed3766af43f3cc4128a34f5d68b6d413f5f Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Mon, 17 Jun 2024 09:29:24 +0200
Subject: [PATCH v2 07/10] Fix -Wmissing-variable-declarations warnings for GUC
 variables

Add extern declarations in appropriate header files for global
variables related to GUC.

In many cases, this was handled quite inconsistently before, with some
GUC variables from the same module declared in a header file and some
not.

Discussion: 
https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c9...@eisentraut.org
---
 src/backend/commands/variable.c     |  1 -
 src/backend/utils/error/elog.c      |  2 --
 src/backend/utils/misc/guc.c        |  3 ---
 src/backend/utils/misc/guc_tables.c | 24 +++++++-----------------
 src/include/access/syncscan.h       |  5 +++++
 src/include/access/xlog.h           |  2 ++
 src/include/access/xlogutils.h      |  3 +++
 src/include/commands/tablespace.h   |  2 ++
 src/include/storage/bufpage.h       |  3 +++
 src/include/tcop/backend_startup.h  |  3 +++
 src/include/tcop/tcopprot.h         |  1 +
 src/include/utils/guc.h             | 25 +++++++++++++++++++++++++
 12 files changed, 51 insertions(+), 23 deletions(-)

diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index 9345131711e..f44d942aa4d 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -901,7 +901,6 @@ assign_session_authorization(const char *newval, void 
*extra)
  * a translation of "none" to InvalidOid.  Otherwise this is much like
  * SET SESSION AUTHORIZATION.
  */
-extern char *role_string;              /* in guc_tables.c */
 
 bool
 check_role(char **newval, void **extra, GucSource source)
diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c
index e9077714211..b73fd933249 100644
--- a/src/backend/utils/error/elog.c
+++ b/src/backend/utils/error/elog.c
@@ -136,8 +136,6 @@ static void write_syslog(int level, const char *line);
 #endif
 
 #ifdef WIN32
-extern char *event_source;
-
 static void write_eventlog(int level, const char *line, int len);
 #endif
 
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 547cecde240..99f079d95c2 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -82,9 +82,6 @@ char     *GUC_check_errmsg_string;
 char      *GUC_check_errdetail_string;
 char      *GUC_check_errhint_string;
 
-/* Kluge: for speed, we examine this GUC variable's value directly */
-extern bool in_hot_standby_guc;
-
 
 /*
  * Unit conversion tables.
diff --git a/src/backend/utils/misc/guc_tables.c 
b/src/backend/utils/misc/guc_tables.c
index bdd18ed7fce..93767bf7a0c 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -34,6 +34,7 @@
 #include "access/xlog_internal.h"
 #include "access/xlogprefetcher.h"
 #include "access/xlogrecovery.h"
+#include "access/xlogutils.h"
 #include "archive/archive_module.h"
 #include "catalog/namespace.h"
 #include "catalog/storage.h"
@@ -71,10 +72,12 @@
 #include "replication/slotsync.h"
 #include "replication/syncrep.h"
 #include "storage/bufmgr.h"
+#include "storage/bufpage.h"
 #include "storage/large_object.h"
 #include "storage/pg_shmem.h"
 #include "storage/predicate.h"
 #include "storage/standby.h"
+#include "tcop/backend_startup.h"
 #include "tcop/tcopprot.h"
 #include "tsearch/ts_cache.h"
 #include "utils/builtins.h"
@@ -90,28 +93,15 @@
 #include "utils/rls.h"
 #include "utils/xml.h"
 
+#ifdef TRACE_SYNCSCAN
+#include "access/syncscan.h"
+#endif
+
 /* This value is normally passed in from the Makefile */
 #ifndef PG_KRB_SRVTAB
 #define PG_KRB_SRVTAB ""
 #endif
 
-/* XXX these should appear in other modules' header files */
-extern bool Log_disconnections;
-extern bool Trace_connection_negotiation;
-extern int     CommitDelay;
-extern int     CommitSiblings;
-extern char *default_tablespace;
-extern char *temp_tablespaces;
-extern bool ignore_checksum_failure;
-extern bool ignore_invalid_pages;
-
-#ifdef TRACE_SYNCSCAN
-extern bool trace_syncscan;
-#endif
-#ifdef DEBUG_BOUNDED_SORT
-extern bool optimize_bounded_sort;
-#endif
-
 /*
  * Options for enum values defined in this module.
  *
diff --git a/src/include/access/syncscan.h b/src/include/access/syncscan.h
index 00b6c0dfc63..e6ee91fc08a 100644
--- a/src/include/access/syncscan.h
+++ b/src/include/access/syncscan.h
@@ -17,6 +17,11 @@
 #include "storage/block.h"
 #include "utils/relcache.h"
 
+/* GUC variables */
+#ifdef TRACE_SYNCSCAN
+extern PGDLLIMPORT bool trace_syncscan;
+#endif
+
 extern void ss_report_location(Relation rel, BlockNumber location);
 extern BlockNumber ss_get_location(Relation rel, BlockNumber relnblocks);
 extern void SyncScanShmemInit(void);
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index c40fd56b291..365a18a08bb 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -52,6 +52,8 @@ extern PGDLLIMPORT bool wal_recycle;
 extern PGDLLIMPORT bool *wal_consistency_checking;
 extern PGDLLIMPORT char *wal_consistency_checking_string;
 extern PGDLLIMPORT bool log_checkpoints;
+extern PGDLLIMPORT int CommitDelay;
+extern PGDLLIMPORT int CommitSiblings;
 extern PGDLLIMPORT bool track_wal_io_timing;
 extern PGDLLIMPORT int wal_decode_buffer_size;
 
diff --git a/src/include/access/xlogutils.h b/src/include/access/xlogutils.h
index e24613e8f81..20950ce0336 100644
--- a/src/include/access/xlogutils.h
+++ b/src/include/access/xlogutils.h
@@ -14,6 +14,9 @@
 #include "access/xlogreader.h"
 #include "storage/bufmgr.h"
 
+/* GUC variable */
+extern PGDLLIMPORT bool ignore_invalid_pages;
+
 /*
  * Prior to 8.4, all activity during recovery was carried out by the startup
  * process. This local variable continues to be used in many parts of the
diff --git a/src/include/commands/tablespace.h 
b/src/include/commands/tablespace.h
index b6cec632db9..6ab2402896d 100644
--- a/src/include/commands/tablespace.h
+++ b/src/include/commands/tablespace.h
@@ -19,6 +19,8 @@
 #include "lib/stringinfo.h"
 #include "nodes/parsenodes.h"
 
+extern PGDLLIMPORT char *default_tablespace;
+extern PGDLLIMPORT char *temp_tablespaces;
 extern PGDLLIMPORT bool allow_in_place_tablespaces;
 
 /* XLOG stuff */
diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h
index d0df02d39c5..df91e80ecee 100644
--- a/src/include/storage/bufpage.h
+++ b/src/include/storage/bufpage.h
@@ -19,6 +19,9 @@
 #include "storage/item.h"
 #include "storage/off.h"
 
+/* GUC variable */
+extern PGDLLIMPORT bool ignore_checksum_failure;
+
 /*
  * A postgres disk page is an abstraction layered on top of a postgres
  * disk block (which is simply a unit of i/o, see block.h).
diff --git a/src/include/tcop/backend_startup.h 
b/src/include/tcop/backend_startup.h
index 16a68c77584..993b013afdd 100644
--- a/src/include/tcop/backend_startup.h
+++ b/src/include/tcop/backend_startup.h
@@ -14,6 +14,9 @@
 #ifndef BACKEND_STARTUP_H
 #define BACKEND_STARTUP_H
 
+/* GUCs */
+extern PGDLLIMPORT bool Trace_connection_negotiation;
+
 /*
  * CAC_state is passed from postmaster to the backend process, to indicate
  * whether the connection should be accepted, or if the process should just
diff --git a/src/include/tcop/tcopprot.h b/src/include/tcop/tcopprot.h
index 643ce9cffab..147a294950e 100644
--- a/src/include/tcop/tcopprot.h
+++ b/src/include/tcop/tcopprot.h
@@ -40,6 +40,7 @@ typedef enum
        LOGSTMT_ALL,                            /* log all statements */
 } LogStmtLevel;
 
+extern PGDLLIMPORT bool Log_disconnections;
 extern PGDLLIMPORT int log_statement;
 
 extern List *pg_parse_query(const char *query_string);
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index ff506bf48d9..cd2cee3dfe0 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -250,6 +250,7 @@ extern PGDLLIMPORT bool log_planner_stats;
 extern PGDLLIMPORT bool log_executor_stats;
 extern PGDLLIMPORT bool log_statement_stats;
 extern PGDLLIMPORT bool log_btree_build_stats;
+extern PGDLLIMPORT char *event_source;
 
 extern PGDLLIMPORT bool check_function_bodies;
 extern PGDLLIMPORT bool current_role_is_superuser;
@@ -285,10 +286,34 @@ extern PGDLLIMPORT int tcp_keepalives_interval;
 extern PGDLLIMPORT int tcp_keepalives_count;
 extern PGDLLIMPORT int tcp_user_timeout;
 
+extern PGDLLIMPORT char *role_string;
+extern PGDLLIMPORT bool in_hot_standby_guc;
+
 #ifdef TRACE_SORT
 extern PGDLLIMPORT bool trace_sort;
 #endif
 
+#ifdef DEBUG_BOUNDED_SORT
+extern PGDLLIMPORT bool optimize_bounded_sort;
+#endif
+
+/*
+ * Declarations for options for enum values
+ *
+ * For most parameters, these are defined statically inside guc_tables.c.  But
+ * for some parameters, the definitions require symbols that are not easily
+ * available inside guc_tables.c, so they are instead defined in their home
+ * modules.  For those, we keep the extern declarations here.  (An alternative
+ * would be to put the extern declarations in the modules' header files, but
+ * that would then require including the definition of struct
+ * config_enum_entry into those header files.)
+ */
+extern const struct config_enum_entry archive_mode_options[];
+extern const struct config_enum_entry dynamic_shared_memory_options[];
+extern const struct config_enum_entry recovery_target_action_options[];
+extern const struct config_enum_entry wal_level_options[];
+extern const struct config_enum_entry wal_sync_method_options[];
+
 /*
  * Functions exported by guc.c
  */
-- 
2.45.2

From 2a26790808f26a29dc69443b4b0735d1f981c43a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Mon, 17 Jun 2024 09:29:53 +0200
Subject: [PATCH v2 08/10] Remove useless extern keywords

An extern keyword on a function definition (not declaration) is
useless and not the normal style.

Discussion: 
https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c9...@eisentraut.org
---
 src/backend/backup/basebackup_incremental.c | 4 ++--
 src/backend/storage/file/fd.c               | 2 +-
 src/bin/pg_basebackup/bbstreamer_inject.c   | 2 +-
 src/bin/pg_basebackup/bbstreamer_tar.c      | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/backend/backup/basebackup_incremental.c 
b/src/backend/backup/basebackup_incremental.c
index b6cfeb6926a..cf2e9eb02cf 100644
--- a/src/backend/backup/basebackup_incremental.c
+++ b/src/backend/backup/basebackup_incremental.c
@@ -944,7 +944,7 @@ GetFileBackupMethod(IncrementalBackupInfo *ib, const char 
*path,
  * number of blocks. The header is rounded to a multiple of BLCKSZ, but
  * only if the file will store some block data.
  */
-extern size_t
+size_t
 GetIncrementalHeaderSize(unsigned num_blocks_required)
 {
        size_t          result;
@@ -972,7 +972,7 @@ GetIncrementalHeaderSize(unsigned num_blocks_required)
 /*
  * Compute the size for an incremental file containing a given number of 
blocks.
  */
-extern size_t
+size_t
 GetIncrementalFileSize(unsigned num_blocks_required)
 {
        size_t          result;
diff --git a/src/backend/storage/file/fd.c b/src/backend/storage/file/fd.c
index a7c05b0a6fd..3944321ff37 100644
--- a/src/backend/storage/file/fd.c
+++ b/src/backend/storage/file/fd.c
@@ -4020,7 +4020,7 @@ check_debug_io_direct(char **newval, void **extra, 
GucSource source)
        return result;
 }
 
-extern void
+void
 assign_debug_io_direct(const char *newval, void *extra)
 {
        int                *flags = (int *) extra;
diff --git a/src/bin/pg_basebackup/bbstreamer_inject.c 
b/src/bin/pg_basebackup/bbstreamer_inject.c
index 2191cf47772..194026b56e9 100644
--- a/src/bin/pg_basebackup/bbstreamer_inject.c
+++ b/src/bin/pg_basebackup/bbstreamer_inject.c
@@ -61,7 +61,7 @@ static const bbstreamer_ops bbstreamer_recovery_injector_ops 
= {
  * zero-length standby.signal file, dropping any file with that name from
  * the archive.
  */
-extern bbstreamer *
+bbstreamer *
 bbstreamer_recovery_injector_new(bbstreamer *next,
                                                                 bool 
is_recovery_guc_supported,
                                                                 PQExpBuffer 
recoveryconfcontents)
diff --git a/src/bin/pg_basebackup/bbstreamer_tar.c 
b/src/bin/pg_basebackup/bbstreamer_tar.c
index 6df3b97f9cb..9137d17ddc1 100644
--- a/src/bin/pg_basebackup/bbstreamer_tar.c
+++ b/src/bin/pg_basebackup/bbstreamer_tar.c
@@ -89,7 +89,7 @@ static const bbstreamer_ops bbstreamer_tar_terminator_ops = {
  * specified by 'next' will receive a series of typed chunks, as per the
  * conventions described in bbstreamer.h.
  */
-extern bbstreamer *
+bbstreamer *
 bbstreamer_tar_parser_new(bbstreamer *next)
 {
        bbstreamer_tar_parser *streamer;
@@ -352,7 +352,7 @@ bbstreamer_tar_parser_free(bbstreamer *streamer)
  * chunks (i.e. not BBSTREAMER_UNKNOWN). See also the comments for
  * bbstreamer_tar_parser_content.
  */
-extern bbstreamer *
+bbstreamer *
 bbstreamer_tar_archiver_new(bbstreamer *next)
 {
        bbstreamer_tar_archiver *streamer;
-- 
2.45.2

From f99c8712ff3dc2156c3e437cfa14f1f1a7f09079 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 May 2024 13:49:37 +0200
Subject: [PATCH v2 09/10] Fix -Wmissing-variable-declarations warnings for
 float.c special case

Discussion: 
https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c9...@eisentraut.org
---
 src/backend/utils/adt/float.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index cbbb8aecafc..bf047ee1b4c 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -56,6 +56,11 @@ static float8 cot_45 = 0;
  * compiler to know that, else it might try to precompute expressions
  * involving them.  See comments for init_degree_constants().
  */
+extern float8 degree_c_thirty;
+extern float8 degree_c_forty_five;
+extern float8 degree_c_sixty;
+extern float8 degree_c_one_half;
+extern float8 degree_c_one;
 float8         degree_c_thirty = 30.0;
 float8         degree_c_forty_five = 45.0;
 float8         degree_c_sixty = 60.0;
-- 
2.45.2

From 649e8086df1f175e843b26cad41a698c8c074c09 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 May 2024 13:49:37 +0200
Subject: [PATCH v2 10/10] Fix -Wmissing-variable-declarations warnings in
 bison code

Add extern declarations for global variables produced by bison.

Discussion: 
https://www.postgresql.org/message-id/flat/e0a62134-83da-4ba4-8cdb-ceb0111c9...@eisentraut.org

TODO: Consider converting all these to pure parsers.  (See also 91e71929ba3.)
---
 contrib/cube/cubeparse.y                | 3 +++
 contrib/seg/segparse.y                  | 3 +++
 src/backend/bootstrap/bootparse.y       | 4 ++++
 src/backend/replication/repl_gram.y     | 4 ++++
 src/backend/replication/syncrep_gram.y  | 3 +++
 src/interfaces/ecpg/preproc/ecpg.header | 3 +++
 src/pl/plpgsql/src/pl_gram.y            | 3 +++
 src/test/isolation/specparse.y          | 2 ++
 8 files changed, 25 insertions(+)

diff --git a/contrib/cube/cubeparse.y b/contrib/cube/cubeparse.y
index b39fbe63e6b..2338687f2c5 100644
--- a/contrib/cube/cubeparse.y
+++ b/contrib/cube/cubeparse.y
@@ -11,6 +11,9 @@
 #include "utils/float.h"
 #include "varatt.h"
 
+extern int cube_yychar;
+extern int cube_yynerrs;
+
 /* All grammar constructs return strings */
 #define YYSTYPE char *
 
diff --git a/contrib/seg/segparse.y b/contrib/seg/segparse.y
index bf759dbbd84..1c74449733a 100644
--- a/contrib/seg/segparse.y
+++ b/contrib/seg/segparse.y
@@ -13,6 +13,9 @@
 
 #include "segdata.h"
 
+extern int seg_yychar;
+extern int seg_yynerrs;
+
 /*
  * Bison doesn't allocate anything that needs to live across parser calls,
  * so we can easily have it use palloc instead of malloc.  This prevents
diff --git a/src/backend/bootstrap/bootparse.y 
b/src/backend/bootstrap/bootparse.y
index 3c9c1da0216..51b00755f98 100644
--- a/src/backend/bootstrap/bootparse.y
+++ b/src/backend/bootstrap/bootparse.y
@@ -33,6 +33,10 @@
 #include "utils/memutils.h"
 
 
+extern int boot_yychar;
+extern int boot_yynerrs;
+
+
 /*
  * Bison doesn't allocate anything that needs to live across parser calls,
  * so we can easily have it use palloc instead of malloc.  This prevents
diff --git a/src/backend/replication/repl_gram.y 
b/src/backend/replication/repl_gram.y
index 53780bbf297..29e4a92feda 100644
--- a/src/backend/replication/repl_gram.y
+++ b/src/backend/replication/repl_gram.y
@@ -23,6 +23,10 @@
 #include "replication/walsender_private.h"
 
 
+extern int replication_yychar;
+extern int replication_yynerrs;
+
+
 /* Result of the parsing is returned here */
 Node *replication_parse_result;
 
diff --git a/src/backend/replication/syncrep_gram.y 
b/src/backend/replication/syncrep_gram.y
index a14f63b6582..11f0f46df74 100644
--- a/src/backend/replication/syncrep_gram.y
+++ b/src/backend/replication/syncrep_gram.y
@@ -24,6 +24,9 @@ char     *syncrep_parse_error_msg;
 static SyncRepConfigData *create_syncrep_config(const char *num_sync,
                                        List *members, uint8 syncrep_method);
 
+extern int syncrep_yychar;
+extern int syncrep_yynerrs;
+
 /*
  * Bison doesn't allocate anything that needs to live across parser calls,
  * so we can easily have it use palloc instead of malloc.  This prevents
diff --git a/src/interfaces/ecpg/preproc/ecpg.header 
b/src/interfaces/ecpg/preproc/ecpg.header
index 59502894256..42a683152f8 100644
--- a/src/interfaces/ecpg/preproc/ecpg.header
+++ b/src/interfaces/ecpg/preproc/ecpg.header
@@ -8,6 +8,9 @@
 #include "ecpg_config.h"
 #include <unistd.h>
 
+extern int base_yychar;
+extern int base_yynerrs;
+
 /* Location tracking support --- simpler than bison's default */
 #define YYLLOC_DEFAULT(Current, Rhs, N) \
        do { \
diff --git a/src/pl/plpgsql/src/pl_gram.y b/src/pl/plpgsql/src/pl_gram.y
index a29d2dfacdd..2c45ccb8a2d 100644
--- a/src/pl/plpgsql/src/pl_gram.y
+++ b/src/pl/plpgsql/src/pl_gram.y
@@ -27,6 +27,9 @@
 #include "plpgsql.h"
 
 
+extern int plpgsql_yychar;
+extern int plpgsql_yynerrs;
+
 /* Location tracking support --- simpler than bison's default */
 #define YYLLOC_DEFAULT(Current, Rhs, N) \
        do { \
diff --git a/src/test/isolation/specparse.y b/src/test/isolation/specparse.y
index 0e8b166a53e..a7cac5b9ea7 100644
--- a/src/test/isolation/specparse.y
+++ b/src/test/isolation/specparse.y
@@ -14,6 +14,8 @@
 
 #include "isolationtester.h"
 
+extern int spec_yychar;
+extern int spec_yynerrs;
 
 TestSpec               parseresult;                    /* result of parsing is 
left here */
 
-- 
2.45.2

Reply via email to