In [0] I had noticed that we have no automated verification that global variables are declared in header files. (For global functions, we have this through -Wmissing-prototypes.) As I mentioned there, I discovered the Clang compiler option -Wmissing-variable-declarations, which does exactly that. Clang has supported this for quite some time, and GCC 14, which was released a few days ago, now also supports it. I went and installed this option into the standard build flags and cleaned up the warnings it found, which revealed a number of interesting things.

I think these checks are important. We have been trying to mark global variables as PGDLLIMPORT consistently, but that only catches variables declared in header files. Also, a threading project would surely benefit from global variables (thread-local variables?) having consistent declarations.

Attached are patches organized by sub-topic. The most dubious stuff is in patches 0006 and 0007. A bunch of GUC-related variables are not in header files but are pulled in via ad-hoc extern declarations. I can't recognize an intentional scheme there, probably just done for convenience or copied from previous practice. These should be organized into appropriate header files.


[0]: https://www.postgresql.org/message-id/c4ac402f-9d7b-45fa-bbc1-4a5bf0a9f...@eisentraut.org
From 296a1c465de6cfea333bf7bb7950f02b3ef80b12 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 May 2024 13:49:37 +0200
Subject: [PATCH v1 1/7] 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.

XXX many warnings to fix first
---
 configure                                 | 99 +++++++++++++++++++++++
 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, 126 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 89644f2249e..70fd1de88b5 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,104 @@ if test x"$pgac_cv_prog_CXX_cxxflags__Wformat_security" 
= x"yes"; then
 fi
 
 
+  # gcc 14+, clang for a while
+  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
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether ${CXX} supports 
-Wmissing-variable-declarations, for CXXFLAGS" >&5
+$as_echo_n "checking whether ${CXX} supports -Wmissing-variable-declarations, 
for CXXFLAGS... " >&6; }
+if ${pgac_cv_prog_CXX_cxxflags__Wmissing_variable_declarations+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  pgac_save_CXXFLAGS=$CXXFLAGS
+pgac_save_CXX=$CXX
+CXX=${CXX}
+CXXFLAGS="${CXXFLAGS} -Wmissing-variable-declarations"
+ac_save_cxx_werror_flag=$ac_cxx_werror_flag
+ac_cxx_werror_flag=yes
+ac_ext=cpp
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS 
conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  pgac_cv_prog_CXX_cxxflags__Wmissing_variable_declarations=yes
+else
+  pgac_cv_prog_CXX_cxxflags__Wmissing_variable_declarations=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext 
$LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+ac_cxx_werror_flag=$ac_save_cxx_werror_flag
+CXXFLAGS="$pgac_save_CXXFLAGS"
+CXX="$pgac_save_CXX"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: 
$pgac_cv_prog_CXX_cxxflags__Wmissing_variable_declarations" >&5
+$as_echo "$pgac_cv_prog_CXX_cxxflags__Wmissing_variable_declarations" >&6; }
+if test x"$pgac_cv_prog_CXX_cxxflags__Wmissing_variable_declarations" = 
x"yes"; then
+  CXXFLAGS="${CXXFLAGS} -Wmissing-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 c7322e292cc..f644c067b66 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
+  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)
+  PGAC_PROG_CXX_CFLAGS_OPT([-Wmissing-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 1c0579d5a6b..868fdb23a72 100644
--- a/meson.build
+++ b/meson.build
@@ -1877,6 +1877,16 @@ if cc.has_argument('-Wdeclaration-after-statement')
   cflags_no_decl_after_statement += '-Wno-declaration-after-statement'
 endif
 
+# Some code does not used this option.
+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
+if llvm.found()
+  cxxflags_warn += 
cpp.get_supported_arguments(['-Wmissing-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: e305f71565e203e08e47d7094082188f5737317f
-- 
2.44.0

From 030f543e4eade4213fce348c03423b6da131e952 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 May 2024 13:49:37 +0200
Subject: [PATCH v1 2/7] Convert some extern variables to static

These probably should have been static all along, it was only
forgotten out of sloppiness.
---
 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 4e9dde1517b..ae9aab7281c 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 f1f44d41eff..c7de3fbb829 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 ea2b0577bc6..d8f7d2be131 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 8449ae78ef7..ec93094d850 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 af776b31d8f..46e765e30e0 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 928ef6b1700..8b18add5b25 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 0bc047a4af4..e11f410166e 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.44.0

From b44c2546aed54f2ae5eb7bfe70e3650394328f36 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 May 2024 13:49:37 +0200
Subject: [PATCH v1 3/7] 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
---
 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 2cee49a2085..f817a2fc898 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 d8f7d2be131..0729db4b3b6 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.44.0

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

---
 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.44.0

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

Add extern declarations for global variables produced by bison.

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.44.0

From 7a208f2e4560c1b71721e3a7fcc4be08c23ad2d1 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 May 2024 13:49:37 +0200
Subject: [PATCH v1 6/7] XXX Fix -Wmissing-variable-declarations warnings for
 GUC variables

Add extern declarations for global variables related to GUC.

XXX These should probably all be in header files.
---
 src/backend/access/rmgrdesc/xlogdesc.c    | 1 +
 src/backend/access/transam/xlog.c         | 5 +++++
 src/backend/access/transam/xlogrecovery.c | 1 +
 src/backend/access/transam/xlogutils.c    | 1 +
 src/backend/commands/tablespace.c         | 4 ++++
 src/backend/storage/ipc/dsm_impl.c        | 1 +
 src/backend/storage/page/bufpage.c        | 1 +
 src/backend/tcop/backend_startup.c        | 1 +
 src/backend/tcop/postgres.c               | 1 +
 src/backend/utils/misc/guc_tables.c       | 3 +++
 10 files changed, 19 insertions(+)

diff --git a/src/backend/access/rmgrdesc/xlogdesc.c 
b/src/backend/access/rmgrdesc/xlogdesc.c
index e455400716d..f28f1062032 100644
--- a/src/backend/access/rmgrdesc/xlogdesc.c
+++ b/src/backend/access/rmgrdesc/xlogdesc.c
@@ -24,6 +24,7 @@
 /*
  * GUC support
  */
+extern const struct config_enum_entry wal_level_options[];
 const struct config_enum_entry wal_level_options[] = {
        {"minimal", WAL_LEVEL_MINIMAL, false},
        {"replica", WAL_LEVEL_REPLICA, false},
diff --git a/src/backend/access/transam/xlog.c 
b/src/backend/access/transam/xlog.c
index c3fd9c1eaed..5ed28add809 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -110,6 +110,9 @@ extern uint32 bootstrap_data_checksum_version;
 /* timeline ID to be used when bootstrapping */
 #define BootstrapTimeLineID            1
 
+extern int CommitDelay;
+extern int CommitSiblings;
+
 /* User-settable parameters */
 int                    max_wal_size_mb = 1024; /* 1 GB */
 int                    min_wal_size_mb = 80;   /* 80 MB */
@@ -168,6 +171,7 @@ static bool check_wal_consistency_checking_deferred = false;
 /*
  * GUC support
  */
+extern const struct config_enum_entry wal_sync_method_options[];
 const struct config_enum_entry wal_sync_method_options[] = {
        {"fsync", WAL_SYNC_METHOD_FSYNC, false},
 #ifdef HAVE_FSYNC_WRITETHROUGH
@@ -188,6 +192,7 @@ const struct config_enum_entry wal_sync_method_options[] = {
  * Although only "on", "off", and "always" are documented,
  * we accept all the likely variants of "on" and "off".
  */
+extern const struct config_enum_entry archive_mode_options[];
 const struct config_enum_entry archive_mode_options[] = {
        {"always", ARCHIVE_MODE_ALWAYS, false},
        {"on", ARCHIVE_MODE_ON, false},
diff --git a/src/backend/access/transam/xlogrecovery.c 
b/src/backend/access/transam/xlogrecovery.c
index 29c5bec0847..ed884ab6637 100644
--- a/src/backend/access/transam/xlogrecovery.c
+++ b/src/backend/access/transam/xlogrecovery.c
@@ -71,6 +71,7 @@
 /*
  * GUC support
  */
+extern const struct config_enum_entry recovery_target_action_options[];
 const struct config_enum_entry recovery_target_action_options[] = {
        {"pause", RECOVERY_TARGET_ACTION_PAUSE, false},
        {"promote", RECOVERY_TARGET_ACTION_PROMOTE, false},
diff --git a/src/backend/access/transam/xlogutils.c 
b/src/backend/access/transam/xlogutils.c
index 5295b85fe07..053a25429f6 100644
--- a/src/backend/access/transam/xlogutils.c
+++ b/src/backend/access/transam/xlogutils.c
@@ -31,6 +31,7 @@
 
 
 /* GUC variable */
+extern bool    ignore_invalid_pages;
 bool           ignore_invalid_pages = false;
 
 /*
diff --git a/src/backend/commands/tablespace.c 
b/src/backend/commands/tablespace.c
index 113b4807315..37c7252e86c 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -80,6 +80,10 @@
 #include "utils/varlena.h"
 
 /* GUC variables */
+extern char *default_tablespace;
+extern char *temp_tablespaces;
+extern bool    allow_in_place_tablespaces;
+
 char      *default_tablespace = NULL;
 char      *temp_tablespaces = NULL;
 bool           allow_in_place_tablespaces = false;
diff --git a/src/backend/storage/ipc/dsm_impl.c 
b/src/backend/storage/ipc/dsm_impl.c
index 8dd669e0ce9..04945bb3e84 100644
--- a/src/backend/storage/ipc/dsm_impl.c
+++ b/src/backend/storage/ipc/dsm_impl.c
@@ -92,6 +92,7 @@ static bool dsm_impl_mmap(dsm_op op, dsm_handle handle, Size 
request_size,
 #endif
 static int     errcode_for_dynamic_shared_memory(void);
 
+extern const struct config_enum_entry dynamic_shared_memory_options[];
 const struct config_enum_entry dynamic_shared_memory_options[] = {
 #ifdef USE_DSM_POSIX
        {"posix", DSM_IMPL_POSIX, false},
diff --git a/src/backend/storage/page/bufpage.c 
b/src/backend/storage/page/bufpage.c
index be6f1f62d29..58836629a09 100644
--- a/src/backend/storage/page/bufpage.c
+++ b/src/backend/storage/page/bufpage.c
@@ -24,6 +24,7 @@
 
 
 /* GUC variable */
+extern bool ignore_checksum_failure;
 bool           ignore_checksum_failure = false;
 
 
diff --git a/src/backend/tcop/backend_startup.c 
b/src/backend/tcop/backend_startup.c
index ee73d01e16c..e032a17e7ae 100644
--- a/src/backend/tcop/backend_startup.c
+++ b/src/backend/tcop/backend_startup.c
@@ -38,6 +38,7 @@
 #include "utils/timeout.h"
 
 /* GUCs */
+extern bool            Trace_connection_negotiation;
 bool           Trace_connection_negotiation = false;
 
 static void BackendInitialize(ClientSocket *client_sock, CAC_state cac);
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 2dff28afcef..60797c9b6cd 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -90,6 +90,7 @@ const char *debug_query_string; /* client-supplied query 
string */
 CommandDest whereToSendOutput = DestDebug;
 
 /* flag for logging end of session */
+extern bool Log_disconnections;
 bool           Log_disconnections = false;
 
 int                    log_statement = LOGSTMT_NONE;
diff --git a/src/backend/utils/misc/guc_tables.c 
b/src/backend/utils/misc/guc_tables.c
index 0729db4b3b6..d8e66782976 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -509,6 +509,7 @@ bool                log_executor_stats = false;
 bool           log_statement_stats = false;    /* this is sort of all three 
above
                                                                                
         * together */
 bool           log_btree_build_stats = false;
+extern char *event_source;
 char      *event_source;
 
 bool           row_security;
@@ -618,9 +619,11 @@ static char *recovery_target_name_string;
 static char *recovery_target_lsn_string;
 
 /* should be static, but commands/variable.c needs to get at this */
+extern char *role_string;
 char      *role_string;
 
 /* should be static, but guc.c needs to get at this */
+extern bool in_hot_standby_guc;
 bool           in_hot_standby_guc;
 
 
-- 
2.44.0

From 8e924d3f2d383d119b576cb678a083eac696b6c7 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Wed, 8 May 2024 13:49:37 +0200
Subject: [PATCH v1 7/7] XXX other stuff

Any reason these are not in header files???
---
 src/backend/bootstrap/bootstrap.c   | 1 +
 src/backend/postmaster/postmaster.c | 1 +
 src/backend/storage/ipc/shmem.c     | 1 +
 3 files changed, 3 insertions(+)

diff --git a/src/backend/bootstrap/bootstrap.c 
b/src/backend/bootstrap/bootstrap.c
index 986f6f1d9ca..41029544edc 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -41,6 +41,7 @@
 #include "utils/rel.h"
 #include "utils/relmapper.h"
 
+extern uint32 bootstrap_data_checksum_version;
 uint32         bootstrap_data_checksum_version = 0;    /* No checksum */
 
 
diff --git a/src/backend/postmaster/postmaster.c 
b/src/backend/postmaster/postmaster.c
index 7f3170a8f06..8b1294082d4 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -350,6 +350,7 @@ static bool ReachedNormalRunning = false;   /* T if we've 
reached PM_RUN */
 bool           ClientAuthInProgress = false;   /* T during new-client
                                                                                
         * authentication */
 
+extern bool redirection_done;
 bool           redirection_done = false;       /* stderr redirected for 
syslogger? */
 
 /* received START_AUTOVAC_LAUNCHER signal */
diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index 6d5f0839864..a1f35e41497 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -84,6 +84,7 @@ static void *ShmemBase;                       /* start 
address of shared memory */
 
 static void *ShmemEnd;                 /* end+1 address of shared memory */
 
+extern slock_t *ShmemLock;
 slock_t    *ShmemLock;                 /* spinlock for shared memory and LWLock
                                                                 * allocation */
 
-- 
2.44.0

Reply via email to