From 1934e00ce225e92b12033e12599031b633b5a987 Mon Sep 17 00:00:00 2001
From: Robert Haas <rhaas@postgresql.org>
Date: Tue, 15 Feb 2022 08:53:25 -0500
Subject: [PATCH v2 2/2] Plaster PGDLLIMPORT declarations on header files.

---
 src/include/access/gin.h                    |  2 +-
 src/include/access/parallel.h               |  2 +-
 src/include/access/session.h                |  2 +-
 src/include/access/tableam.h                |  4 +-
 src/include/access/toast_compression.h      |  2 +-
 src/include/access/twophase_rmgr.h          |  8 +--
 src/include/access/xact.h                   | 16 +++---
 src/include/access/xlog.h                   | 54 +++++++++---------
 src/include/access/xlog_internal.h          | 10 ++--
 src/include/access/xlogrecovery.h           | 42 +++++++-------
 src/include/access/xlogutils.h              |  4 +-
 src/include/bootstrap/bootstrap.h           |  6 +-
 src/include/catalog/namespace.h             |  2 +-
 src/include/catalog/objectaddress.h         |  2 +-
 src/include/catalog/storage.h               |  2 +-
 src/include/commands/async.h                |  4 +-
 src/include/commands/tablespace.h           |  2 +-
 src/include/commands/user.h                 |  2 +-
 src/include/commands/vacuum.h               | 18 +++---
 src/include/common/file_perm.h              |  6 +-
 src/include/common/jsonapi.h                |  2 +-
 src/include/common/logging.h                |  2 +-
 src/include/common/pg_lzcompress.h          |  4 +-
 src/include/common/relpath.h                |  2 +-
 src/include/fe_utils/cancel.h               |  2 +-
 src/include/fe_utils/print.h                |  9 +--
 src/include/fe_utils/string_utils.h         |  2 +-
 src/include/fmgr.h                          |  2 +-
 src/include/jit/jit.h                       | 20 +++----
 src/include/jit/llvmjit.h                   | 44 +++++++--------
 src/include/libpq/auth.h                    |  6 +-
 src/include/libpq/libpq-be.h                |  2 +-
 src/include/libpq/libpq.h                   | 28 +++++-----
 src/include/libpq/pqcomm.h                  |  2 +-
 src/include/libpq/scram.h                   |  2 +-
 src/include/mb/pg_wchar.h                   |  6 +-
 src/include/miscadmin.h                     | 52 ++++++++---------
 src/include/nodes/readfuncs.h               |  2 +-
 src/include/optimizer/geqo.h                | 11 ++--
 src/include/optimizer/optimizer.h           |  4 +-
 src/include/optimizer/planmain.h            |  6 +-
 src/include/parser/parse_expr.h             |  2 +-
 src/include/parser/parser.h                 |  4 +-
 src/include/pg_getopt.h                     | 10 ++--
 src/include/pgstat.h                        | 22 ++++----
 src/include/pgtime.h                        |  2 +-
 src/include/port/win32_port.h               |  6 +-
 src/include/port/win32ntdll.h               |  4 +-
 src/include/postmaster/autovacuum.h         | 32 +++++------
 src/include/postmaster/bgworker_internals.h |  2 +-
 src/include/postmaster/bgwriter.h           |  8 +--
 src/include/postmaster/pgarch.h             |  2 +-
 src/include/postmaster/postmaster.h         | 34 +++++------
 src/include/postmaster/startup.h            |  2 +-
 src/include/postmaster/syslogger.h          | 14 ++---
 src/include/postmaster/walwriter.h          |  4 +-
 src/include/replication/logicallauncher.h   |  4 +-
 src/include/replication/syncrep.h           |  8 +--
 src/include/replication/walreceiver.h       |  8 +--
 src/include/replication/walsender.h         | 14 ++---
 src/include/replication/walsender_private.h |  6 +-
 src/include/replication/worker_internal.h   | 10 ++--
 src/include/storage/buf_internals.h         |  4 +-
 src/include/storage/bufmgr.h                | 20 +++----
 src/include/storage/dsm_impl.h              |  4 +-
 src/include/storage/fd.h                    |  4 +-
 src/include/storage/large_object.h          |  2 +-
 src/include/storage/lock.h                  | 14 ++---
 src/include/storage/lwlock.h                |  2 +-
 src/include/storage/pg_shmem.h              | 14 ++---
 src/include/storage/pmsignal.h              |  2 +-
 src/include/storage/predicate.h             |  6 +-
 src/include/storage/proc.h                  |  4 +-
 src/include/storage/s_lock.h                |  2 +-
 src/include/storage/sinval.h                |  4 +-
 src/include/storage/spin.h                  |  2 +-
 src/include/storage/standby.h               |  8 +--
 src/include/tcop/tcopprot.h                 |  8 +--
 src/include/tsearch/ts_cache.h              |  2 +-
 src/include/tsearch/ts_type.h               |  2 +-
 src/include/utils/array.h                   |  2 +-
 src/include/utils/builtins.h                |  2 +-
 src/include/utils/bytea.h                   |  3 +-
 src/include/utils/datetime.h                |  7 ++-
 src/include/utils/elog.h                    | 12 ++--
 src/include/utils/fmgrtab.h                 |  9 +--
 src/include/utils/guc.h                     | 62 ++++++++++-----------
 src/include/utils/guc_tables.h              |  8 +--
 src/include/utils/pg_locale.h               | 18 +++---
 src/include/utils/pgstat_internal.h         | 10 ++--
 src/include/utils/plancache.h               |  2 +-
 src/include/utils/ps_status.h               |  2 +-
 src/include/utils/queryjumble.h             |  4 +-
 src/include/utils/relcache.h                |  4 +-
 src/include/utils/rls.h                     |  2 +-
 src/include/utils/snapmgr.h                 |  2 +-
 src/include/utils/timestamp.h               |  4 +-
 src/include/utils/xml.h                     |  6 +-
 98 files changed, 433 insertions(+), 428 deletions(-)

diff --git a/src/include/access/gin.h b/src/include/access/gin.h
index e83e0acd92..aacc665fdc 100644
--- a/src/include/access/gin.h
+++ b/src/include/access/gin.h
@@ -68,7 +68,7 @@ typedef char GinTernaryValue;
 
 /* GUC parameters */
 extern PGDLLIMPORT int GinFuzzySearchLimit;
-extern int	gin_pending_list_limit;
+extern PGDLLIMPORT int gin_pending_list_limit;
 
 /* ginutil.c */
 extern void ginGetStats(Relation index, GinStatsData *stats);
diff --git a/src/include/access/parallel.h b/src/include/access/parallel.h
index 30786820f8..983841d45e 100644
--- a/src/include/access/parallel.h
+++ b/src/include/access/parallel.h
@@ -54,7 +54,7 @@ typedef struct ParallelWorkerContext
 	shm_toc    *toc;
 } ParallelWorkerContext;
 
-extern volatile bool ParallelMessagePending;
+extern PGDLLIMPORT volatile bool ParallelMessagePending;
 extern PGDLLIMPORT int ParallelWorkerNumber;
 extern PGDLLIMPORT bool InitializingParallelWorker;
 
diff --git a/src/include/access/session.h b/src/include/access/session.h
index 0ed52d4821..775888bbb0 100644
--- a/src/include/access/session.h
+++ b/src/include/access/session.h
@@ -39,6 +39,6 @@ extern void AttachSession(dsm_handle handle);
 extern void DetachSession(void);
 
 /* The current session, or NULL for none. */
-extern Session *CurrentSession;
+extern PGDLLIMPORT Session *CurrentSession;
 
 #endif							/* SESSION_H */
diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h
index bb365736b7..fe869c6c18 100644
--- a/src/include/access/tableam.h
+++ b/src/include/access/tableam.h
@@ -28,8 +28,8 @@
 #define DEFAULT_TABLE_ACCESS_METHOD	"heap"
 
 /* GUCs */
-extern char *default_table_access_method;
-extern bool synchronize_seqscans;
+extern PGDLLIMPORT char *default_table_access_method;
+extern PGDLLIMPORT bool synchronize_seqscans;
 
 
 struct BulkInsertStateData;
diff --git a/src/include/access/toast_compression.h b/src/include/access/toast_compression.h
index 9b433c7721..deb8f99da5 100644
--- a/src/include/access/toast_compression.h
+++ b/src/include/access/toast_compression.h
@@ -20,7 +20,7 @@
  * but the value is one of the char values defined below, as they appear in
  * pg_attribute.attcompression, e.g. TOAST_PGLZ_COMPRESSION.
  */
-extern int	default_toast_compression;
+extern PGDLLIMPORT int default_toast_compression;
 
 /*
  * Built-in compression method ID.  The toast compression header will store
diff --git a/src/include/access/twophase_rmgr.h b/src/include/access/twophase_rmgr.h
index 284c7539f8..96381a5e3f 100644
--- a/src/include/access/twophase_rmgr.h
+++ b/src/include/access/twophase_rmgr.h
@@ -28,10 +28,10 @@ typedef uint8 TwoPhaseRmgrId;
 #define TWOPHASE_RM_PREDICATELOCK_ID	4
 #define TWOPHASE_RM_MAX_ID			TWOPHASE_RM_PREDICATELOCK_ID
 
-extern const TwoPhaseCallback twophase_recover_callbacks[];
-extern const TwoPhaseCallback twophase_postcommit_callbacks[];
-extern const TwoPhaseCallback twophase_postabort_callbacks[];
-extern const TwoPhaseCallback twophase_standby_recover_callbacks[];
+extern PGDLLIMPORT const TwoPhaseCallback twophase_recover_callbacks[];
+extern PGDLLIMPORT const TwoPhaseCallback twophase_postcommit_callbacks[];
+extern PGDLLIMPORT const TwoPhaseCallback twophase_postabort_callbacks[];
+extern PGDLLIMPORT const TwoPhaseCallback twophase_standby_recover_callbacks[];
 
 
 extern void RegisterTwoPhaseRecord(TwoPhaseRmgrId rmid, uint16 info,
diff --git a/src/include/access/xact.h b/src/include/access/xact.h
index 062cc7e17d..0ec4bb181b 100644
--- a/src/include/access/xact.h
+++ b/src/include/access/xact.h
@@ -38,7 +38,7 @@
 #define XACT_REPEATABLE_READ	2
 #define XACT_SERIALIZABLE		3
 
-extern int	DefaultXactIsoLevel;
+extern PGDLLIMPORT int DefaultXactIsoLevel;
 extern PGDLLIMPORT int XactIsoLevel;
 
 /*
@@ -52,18 +52,18 @@ extern PGDLLIMPORT int XactIsoLevel;
 #define IsolationIsSerializable() (XactIsoLevel == XACT_SERIALIZABLE)
 
 /* Xact read-only state */
-extern bool DefaultXactReadOnly;
-extern bool XactReadOnly;
+extern PGDLLIMPORT bool DefaultXactReadOnly;
+extern PGDLLIMPORT bool XactReadOnly;
 
 /* flag for logging statements in this transaction */
-extern bool xact_is_sampled;
+extern PGDLLIMPORT bool xact_is_sampled;
 
 /*
  * Xact is deferrable -- only meaningful (currently) for read only
  * SERIALIZABLE transactions
  */
-extern bool DefaultXactDeferrable;
-extern bool XactDeferrable;
+extern PGDLLIMPORT bool DefaultXactDeferrable;
+extern PGDLLIMPORT bool XactDeferrable;
 
 typedef enum
 {
@@ -80,7 +80,7 @@ typedef enum
 #define SYNCHRONOUS_COMMIT_ON	SYNCHRONOUS_COMMIT_REMOTE_FLUSH
 
 /* Synchronous commit level */
-extern int	synchronous_commit;
+extern PGDLLIMPORT int synchronous_commit;
 
 /* used during logical streaming of a transaction */
 extern PGDLLIMPORT TransactionId CheckXidAlive;
@@ -93,7 +93,7 @@ extern PGDLLIMPORT bool bsysscan;
  * globally accessible, so can be set from anywhere in the code which requires
  * recording flags.
  */
-extern int	MyXactFlags;
+extern PGDLLIMPORT int MyXactFlags;
 
 /*
  * XACT_FLAGS_ACCESSEDTEMPNAMESPACE - set when a temporary object is accessed.
diff --git a/src/include/access/xlog.h b/src/include/access/xlog.h
index 09f6464331..05cfd3accf 100644
--- a/src/include/access/xlog.h
+++ b/src/include/access/xlog.h
@@ -24,34 +24,34 @@
 #define SYNC_METHOD_OPEN		2	/* for O_SYNC */
 #define SYNC_METHOD_FSYNC_WRITETHROUGH	3
 #define SYNC_METHOD_OPEN_DSYNC	4	/* for O_DSYNC */
-extern int	sync_method;
+extern PGDLLIMPORT int	sync_method;
 
-extern XLogRecPtr ProcLastRecPtr;
-extern XLogRecPtr XactLastRecEnd;
+extern PGDLLIMPORT XLogRecPtr ProcLastRecPtr;
+extern PGDLLIMPORT XLogRecPtr XactLastRecEnd;
 extern PGDLLIMPORT XLogRecPtr XactLastCommitEnd;
 
 /* these variables are GUC parameters related to XLOG */
-extern int	wal_segment_size;
-extern int	min_wal_size_mb;
-extern int	max_wal_size_mb;
-extern int	wal_keep_size_mb;
-extern int	max_slot_wal_keep_size_mb;
-extern int	XLOGbuffers;
-extern int	XLogArchiveTimeout;
-extern int	wal_retrieve_retry_interval;
-extern char *XLogArchiveCommand;
-extern bool EnableHotStandby;
-extern bool fullPageWrites;
-extern bool wal_log_hints;
-extern int	wal_compression;
-extern bool wal_init_zero;
-extern bool wal_recycle;
-extern bool *wal_consistency_checking;
-extern char *wal_consistency_checking_string;
-extern bool log_checkpoints;
-extern bool track_wal_io_timing;
-
-extern int	CheckPointSegments;
+extern PGDLLIMPORT int	wal_segment_size;
+extern PGDLLIMPORT int	min_wal_size_mb;
+extern PGDLLIMPORT int	max_wal_size_mb;
+extern PGDLLIMPORT int	wal_keep_size_mb;
+extern PGDLLIMPORT int	max_slot_wal_keep_size_mb;
+extern PGDLLIMPORT int	XLOGbuffers;
+extern PGDLLIMPORT int	XLogArchiveTimeout;
+extern PGDLLIMPORT int	wal_retrieve_retry_interval;
+extern PGDLLIMPORT char *XLogArchiveCommand;
+extern PGDLLIMPORT bool EnableHotStandby;
+extern PGDLLIMPORT bool fullPageWrites;
+extern PGDLLIMPORT bool wal_log_hints;
+extern PGDLLIMPORT int	wal_compression;
+extern PGDLLIMPORT bool wal_init_zero;
+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 bool track_wal_io_timing;
+
+extern PGDLLIMPORT int	CheckPointSegments;
 
 /* Archive modes */
 typedef enum ArchiveMode
@@ -60,7 +60,7 @@ typedef enum ArchiveMode
 	ARCHIVE_MODE_ON,			/* enabled while server is running normally */
 	ARCHIVE_MODE_ALWAYS			/* enabled always (even during recovery) */
 } ArchiveMode;
-extern int	XLogArchiveMode;
+extern PGDLLIMPORT int	XLogArchiveMode;
 
 /* WAL levels */
 typedef enum WalLevel
@@ -120,7 +120,7 @@ extern PGDLLIMPORT int wal_level;
 #define XLogLogicalInfoActive() (wal_level >= WAL_LEVEL_LOGICAL)
 
 #ifdef WAL_DEBUG
-extern bool XLOG_DEBUG;
+extern PGDLLIMPORT bool XLOG_DEBUG;
 #endif
 
 /*
@@ -174,7 +174,7 @@ typedef struct CheckpointStatsData
 									 * entire sync phase. */
 } CheckpointStatsData;
 
-extern CheckpointStatsData CheckpointStats;
+extern PGDLLIMPORT CheckpointStatsData CheckpointStats;
 
 /*
  * GetWALAvailability return codes
diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h
index 0e94833129..2cde27e70e 100644
--- a/src/include/access/xlog_internal.h
+++ b/src/include/access/xlog_internal.h
@@ -319,7 +319,7 @@ typedef struct RmgrData
 							  struct XLogRecordBuffer *buf);
 } RmgrData;
 
-extern const RmgrData RmgrTable[];
+extern PGDLLIMPORT const RmgrData RmgrTable[];
 
 /*
  * Exported to support xlog switching from checkpointer
@@ -333,9 +333,9 @@ extern void GetOldestRestartPoint(XLogRecPtr *oldrecptr, TimeLineID *oldtli);
  * Exported for the functions in timeline.c and xlogarchive.c.  Only valid
  * in the startup process.
  */
-extern bool ArchiveRecoveryRequested;
-extern bool InArchiveRecovery;
-extern bool StandbyMode;
-extern char *recoveryRestoreCommand;
+extern PGDLLIMPORT bool ArchiveRecoveryRequested;
+extern PGDLLIMPORT bool InArchiveRecovery;
+extern PGDLLIMPORT bool StandbyMode;
+extern PGDLLIMPORT char *recoveryRestoreCommand;
 
 #endif							/* XLOG_INTERNAL_H */
diff --git a/src/include/access/xlogrecovery.h b/src/include/access/xlogrecovery.h
index 75a0f5fe5e..0aa85d90e8 100644
--- a/src/include/access/xlogrecovery.h
+++ b/src/include/access/xlogrecovery.h
@@ -49,33 +49,33 @@ typedef enum RecoveryPauseState
 } RecoveryPauseState;
 
 /* User-settable GUC parameters */
-extern bool recoveryTargetInclusive;
-extern int	recoveryTargetAction;
-extern int	recovery_min_apply_delay;
-extern char *PrimaryConnInfo;
-extern char *PrimarySlotName;
-extern char *recoveryRestoreCommand;
-extern char *recoveryEndCommand;
-extern char *archiveCleanupCommand;
+extern PGDLLIMPORT bool recoveryTargetInclusive;
+extern PGDLLIMPORT int recoveryTargetAction;
+extern PGDLLIMPORT int recovery_min_apply_delay;
+extern PGDLLIMPORT char *PrimaryConnInfo;
+extern PGDLLIMPORT char *PrimarySlotName;
+extern PGDLLIMPORT char *recoveryRestoreCommand;
+extern PGDLLIMPORT char *recoveryEndCommand;
+extern PGDLLIMPORT char *archiveCleanupCommand;
 
 /* indirectly set via GUC system */
-extern TransactionId recoveryTargetXid;
-extern char *recovery_target_time_string;
-extern TimestampTz recoveryTargetTime;
-extern const char *recoveryTargetName;
-extern XLogRecPtr recoveryTargetLSN;
-extern RecoveryTargetType recoveryTarget;
-extern char *PromoteTriggerFile;
-extern bool wal_receiver_create_temp_slot;
-extern RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal;
-extern TimeLineID recoveryTargetTLIRequested;
-extern TimeLineID recoveryTargetTLI;
+extern PGDLLIMPORT TransactionId recoveryTargetXid;
+extern PGDLLIMPORT char *recovery_target_time_string;
+extern PGDLLIMPORT TimestampTz recoveryTargetTime;
+extern PGDLLIMPORT const char *recoveryTargetName;
+extern PGDLLIMPORT XLogRecPtr recoveryTargetLSN;
+extern PGDLLIMPORT RecoveryTargetType recoveryTarget;
+extern PGDLLIMPORT char *PromoteTriggerFile;
+extern PGDLLIMPORT bool wal_receiver_create_temp_slot;
+extern PGDLLIMPORT RecoveryTargetTimeLineGoal recoveryTargetTimeLineGoal;
+extern PGDLLIMPORT TimeLineID recoveryTargetTLIRequested;
+extern PGDLLIMPORT TimeLineID recoveryTargetTLI;
 
 /* Have we already reached a consistent database state? */
-extern bool reachedConsistency;
+extern PGDLLIMPORT bool reachedConsistency;
 
 /* Are we currently in standby mode? */
-extern bool StandbyMode;
+extern PGDLLIMPORT bool StandbyMode;
 
 extern Size XLogRecoveryShmemSize(void);
 extern void XLogRecoveryShmemInit(void);
diff --git a/src/include/access/xlogutils.h b/src/include/access/xlogutils.h
index 64708949db..00889f76de 100644
--- a/src/include/access/xlogutils.h
+++ b/src/include/access/xlogutils.h
@@ -21,7 +21,7 @@
  * potentially perform work during recovery should check RecoveryInProgress().
  * See XLogCtl notes in xlog.c.
  */
-extern bool InRecovery;
+extern PGDLLIMPORT bool InRecovery;
 
 /*
  * Like InRecovery, standbyState is only valid in the startup process.
@@ -52,7 +52,7 @@ typedef enum
 	STANDBY_SNAPSHOT_READY
 } HotStandbyState;
 
-extern HotStandbyState standbyState;
+extern PGDLLIMPORT HotStandbyState standbyState;
 
 #define InHotStandby (standbyState >= STANDBY_SNAPSHOT_PENDING)
 
diff --git a/src/include/bootstrap/bootstrap.h b/src/include/bootstrap/bootstrap.h
index 471414909f..49d4ad560f 100644
--- a/src/include/bootstrap/bootstrap.h
+++ b/src/include/bootstrap/bootstrap.h
@@ -27,9 +27,9 @@
 #define BOOTCOL_NULL_FORCE_NULL		2
 #define BOOTCOL_NULL_FORCE_NOT_NULL 3
 
-extern Relation boot_reldesc;
-extern Form_pg_attribute attrtypes[MAXATTR];
-extern int	numattr;
+extern PGDLLIMPORT Relation boot_reldesc;
+extern PGDLLIMPORT Form_pg_attribute attrtypes[MAXATTR];
+extern PGDLLIMPORT int numattr;
 
 
 extern void BootstrapModeMain(int argc, char *argv[], bool check_only) pg_attribute_noreturn();
diff --git a/src/include/catalog/namespace.h b/src/include/catalog/namespace.h
index f963d82797..1bc55c01a5 100644
--- a/src/include/catalog/namespace.h
+++ b/src/include/catalog/namespace.h
@@ -182,7 +182,7 @@ extern void AtEOSubXact_Namespace(bool isCommit, SubTransactionId mySubid,
 								  SubTransactionId parentSubid);
 
 /* stuff for search_path GUC variable */
-extern char *namespace_search_path;
+extern PGDLLIMPORT char *namespace_search_path;
 
 extern List *fetch_search_path(bool includeImplicit);
 extern int	fetch_search_path_array(Oid *sarray, int sarray_len);
diff --git a/src/include/catalog/objectaddress.h b/src/include/catalog/objectaddress.h
index 274f300054..cf4d8b3107 100644
--- a/src/include/catalog/objectaddress.h
+++ b/src/include/catalog/objectaddress.h
@@ -28,7 +28,7 @@ typedef struct ObjectAddress
 	int32		objectSubId;	/* Subitem within object (eg column), or 0 */
 } ObjectAddress;
 
-extern const ObjectAddress InvalidObjectAddress;
+extern PGDLLIMPORT const ObjectAddress InvalidObjectAddress;
 
 #define ObjectAddressSubSet(addr, class_id, object_id, object_sub_id) \
 	do { \
diff --git a/src/include/catalog/storage.h b/src/include/catalog/storage.h
index 844a023b2c..59f3404ac6 100644
--- a/src/include/catalog/storage.h
+++ b/src/include/catalog/storage.h
@@ -20,7 +20,7 @@
 #include "utils/relcache.h"
 
 /* GUC variables */
-extern int	wal_skip_threshold;
+extern PGDLLIMPORT int wal_skip_threshold;
 
 extern SMgrRelation RelationCreateStorage(RelFileNode rnode,
 										  char relpersistence,
diff --git a/src/include/commands/async.h b/src/include/commands/async.h
index ebc9271789..926af933d1 100644
--- a/src/include/commands/async.h
+++ b/src/include/commands/async.h
@@ -20,8 +20,8 @@
  */
 #define NUM_NOTIFY_BUFFERS	8
 
-extern bool Trace_notify;
-extern volatile sig_atomic_t notifyInterruptPending;
+extern PGDLLIMPORT bool Trace_notify;
+extern PGDLLIMPORT volatile sig_atomic_t notifyInterruptPending;
 
 extern Size AsyncShmemSize(void);
 extern void AsyncShmemInit(void);
diff --git a/src/include/commands/tablespace.h b/src/include/commands/tablespace.h
index 323528ebb8..24b647332d 100644
--- a/src/include/commands/tablespace.h
+++ b/src/include/commands/tablespace.h
@@ -19,7 +19,7 @@
 #include "lib/stringinfo.h"
 #include "nodes/parsenodes.h"
 
-extern bool allow_in_place_tablespaces;
+extern PGDLLIMPORT bool allow_in_place_tablespaces;
 
 /* XLOG stuff */
 #define XLOG_TBLSPC_CREATE		0x00
diff --git a/src/include/commands/user.h b/src/include/commands/user.h
index 0b7a3cd65f..d3dd8303d2 100644
--- a/src/include/commands/user.h
+++ b/src/include/commands/user.h
@@ -17,7 +17,7 @@
 #include "parser/parse_node.h"
 
 /* GUC. Is actually of type PasswordType. */
-extern int	Password_encryption;
+extern PGDLLIMPORT int Password_encryption;
 
 /* Hook to check passwords in CreateRole() and AlterRole() */
 typedef void (*check_password_hook_type) (const char *username, const char *shadow_pass, PasswordType password_type, Datum validuntil_time, bool validuntil_null);
diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h
index d64f6268f2..239e0356fa 100644
--- a/src/include/commands/vacuum.h
+++ b/src/include/commands/vacuum.h
@@ -252,17 +252,17 @@ typedef struct VacDeadItems
 
 /* GUC parameters */
 extern PGDLLIMPORT int default_statistics_target;	/* PGDLLIMPORT for PostGIS */
-extern int	vacuum_freeze_min_age;
-extern int	vacuum_freeze_table_age;
-extern int	vacuum_multixact_freeze_min_age;
-extern int	vacuum_multixact_freeze_table_age;
-extern int	vacuum_failsafe_age;
-extern int	vacuum_multixact_failsafe_age;
+extern PGDLLIMPORT int vacuum_freeze_min_age;
+extern PGDLLIMPORT int vacuum_freeze_table_age;
+extern PGDLLIMPORT int vacuum_multixact_freeze_min_age;
+extern PGDLLIMPORT int vacuum_multixact_freeze_table_age;
+extern PGDLLIMPORT int vacuum_failsafe_age;
+extern PGDLLIMPORT int vacuum_multixact_failsafe_age;
 
 /* Variables for cost-based parallel vacuum */
-extern pg_atomic_uint32 *VacuumSharedCostBalance;
-extern pg_atomic_uint32 *VacuumActiveNWorkers;
-extern int	VacuumCostBalanceLocal;
+extern PGDLLIMPORT pg_atomic_uint32 *VacuumSharedCostBalance;
+extern PGDLLIMPORT pg_atomic_uint32 *VacuumActiveNWorkers;
+extern PGDLLIMPORT int VacuumCostBalanceLocal;
 
 
 /* in commands/vacuum.c */
diff --git a/src/include/common/file_perm.h b/src/include/common/file_perm.h
index 85d32ed141..48d68ef276 100644
--- a/src/include/common/file_perm.h
+++ b/src/include/common/file_perm.h
@@ -41,11 +41,11 @@
 #define PG_FILE_MODE_GROUP			(S_IRUSR | S_IWUSR | S_IRGRP)
 
 /* Modes for creating directories and files in the data directory */
-extern int	pg_dir_create_mode;
-extern int	pg_file_create_mode;
+extern PGDLLIMPORT int pg_dir_create_mode;
+extern PGDLLIMPORT int pg_file_create_mode;
 
 /* Mode mask to pass to umask() */
-extern int	pg_mode_mask;
+extern PGDLLIMPORT int pg_mode_mask;
 
 /* Set permissions and mask based on the provided mode */
 extern void SetDataDirectoryCreatePerm(int dataDirMode);
diff --git a/src/include/common/jsonapi.h b/src/include/common/jsonapi.h
index 52cb4a9339..8d31630e5c 100644
--- a/src/include/common/jsonapi.h
+++ b/src/include/common/jsonapi.h
@@ -128,7 +128,7 @@ extern JsonParseErrorType pg_parse_json(JsonLexContext *lex,
 										JsonSemAction *sem);
 
 /* the null action object used for pure validation */
-extern JsonSemAction nullSemAction;
+extern PGDLLIMPORT JsonSemAction nullSemAction;
 
 /*
  * json_count_array_elements performs a fast secondary parse to determine the
diff --git a/src/include/common/logging.h b/src/include/common/logging.h
index 43cc79afa8..61cfdce653 100644
--- a/src/include/common/logging.h
+++ b/src/include/common/logging.h
@@ -55,7 +55,7 @@ enum pg_log_level
 	PG_LOG_OFF,
 };
 
-extern enum pg_log_level __pg_log_level;
+extern PGDLLIMPORT enum pg_log_level __pg_log_level;
 
 /*
  * Kind of a hack to be able to produce the psql output exactly as required by
diff --git a/src/include/common/pg_lzcompress.h b/src/include/common/pg_lzcompress.h
index 3e53fbe97b..2a12b33a00 100644
--- a/src/include/common/pg_lzcompress.h
+++ b/src/include/common/pg_lzcompress.h
@@ -75,8 +75,8 @@ typedef struct PGLZ_Strategy
  *									output would be larger than input.
  * ----------
  */
-extern const PGLZ_Strategy *const PGLZ_strategy_default;
-extern const PGLZ_Strategy *const PGLZ_strategy_always;
+extern PGDLLIMPORT const PGLZ_Strategy *const PGLZ_strategy_default;
+extern PGDLLIMPORT const PGLZ_Strategy *const PGLZ_strategy_always;
 
 
 /* ----------
diff --git a/src/include/common/relpath.h b/src/include/common/relpath.h
index a4b5dc853b..13849a3790 100644
--- a/src/include/common/relpath.h
+++ b/src/include/common/relpath.h
@@ -56,7 +56,7 @@ typedef enum ForkNumber
 
 #define FORKNAMECHARS	4		/* max chars for a fork name */
 
-extern const char *const forkNames[];
+extern PGDLLIMPORT const char *const forkNames[];
 
 extern ForkNumber forkname_to_number(const char *forkName);
 extern int	forkname_chars(const char *str, ForkNumber *fork);
diff --git a/src/include/fe_utils/cancel.h b/src/include/fe_utils/cancel.h
index 7005b804bc..3b84daf6eb 100644
--- a/src/include/fe_utils/cancel.h
+++ b/src/include/fe_utils/cancel.h
@@ -18,7 +18,7 @@
 
 #include "libpq-fe.h"
 
-extern volatile sig_atomic_t CancelRequested;
+extern PGDLLIMPORT volatile sig_atomic_t CancelRequested;
 
 extern void SetCancelConn(PGconn *conn);
 extern void ResetCancelConn(void);
diff --git a/src/include/fe_utils/print.h b/src/include/fe_utils/print.h
index 836b4e29a8..bb2f1bf4e6 100644
--- a/src/include/fe_utils/print.h
+++ b/src/include/fe_utils/print.h
@@ -177,11 +177,12 @@ typedef struct printQueryOpt
 } printQueryOpt;
 
 
-extern volatile sig_atomic_t cancel_pressed;
+extern PGDLLIMPORT volatile sig_atomic_t cancel_pressed;
 
-extern const printTextFormat pg_asciiformat;
-extern const printTextFormat pg_asciiformat_old;
-extern printTextFormat pg_utf8format;	/* ideally would be const, but... */
+extern PGDLLIMPORT const printTextFormat pg_asciiformat;
+extern PGDLLIMPORT const printTextFormat pg_asciiformat_old;
+extern PGDLLIMPORT printTextFormat pg_utf8format;	/* ideally would be const,
+													 * but... */
 
 
 extern void disable_sigpipe_trap(void);
diff --git a/src/include/fe_utils/string_utils.h b/src/include/fe_utils/string_utils.h
index 3c88250e6c..b9b8708dab 100644
--- a/src/include/fe_utils/string_utils.h
+++ b/src/include/fe_utils/string_utils.h
@@ -20,7 +20,7 @@
 #include "pqexpbuffer.h"
 
 /* Global variables controlling behavior of fmtId() and fmtQualifiedId() */
-extern int	quote_all_identifiers;
+extern PGDLLIMPORT int quote_all_identifiers;
 extern PQExpBuffer (*getLocalPQExpBuffer) (void);
 
 /* Functions */
diff --git a/src/include/fmgr.h b/src/include/fmgr.h
index 6560e462d6..a1cf4bd646 100644
--- a/src/include/fmgr.h
+++ b/src/include/fmgr.h
@@ -721,7 +721,7 @@ extern bool CheckFunctionValidatorAccess(Oid validatorOid, Oid functionOid);
 /*
  * Routines in dfmgr.c
  */
-extern char *Dynamic_library_path;
+extern PGDLLIMPORT char *Dynamic_library_path;
 
 extern void *load_external_function(const char *filename, const char *funcname,
 									bool signalNotFound, void **filehandle);
diff --git a/src/include/jit/jit.h b/src/include/jit/jit.h
index 707176d9ed..d194033209 100644
--- a/src/include/jit/jit.h
+++ b/src/include/jit/jit.h
@@ -79,16 +79,16 @@ struct JitProviderCallbacks
 
 
 /* GUCs */
-extern bool jit_enabled;
-extern char *jit_provider;
-extern bool jit_debugging_support;
-extern bool jit_dump_bitcode;
-extern bool jit_expressions;
-extern bool jit_profiling_support;
-extern bool jit_tuple_deforming;
-extern double jit_above_cost;
-extern double jit_inline_above_cost;
-extern double jit_optimize_above_cost;
+extern PGDLLIMPORT bool jit_enabled;
+extern PGDLLIMPORT char *jit_provider;
+extern PGDLLIMPORT bool jit_debugging_support;
+extern PGDLLIMPORT bool jit_dump_bitcode;
+extern PGDLLIMPORT bool jit_expressions;
+extern PGDLLIMPORT bool jit_profiling_support;
+extern PGDLLIMPORT bool jit_tuple_deforming;
+extern PGDLLIMPORT double jit_above_cost;
+extern PGDLLIMPORT double jit_inline_above_cost;
+extern PGDLLIMPORT double jit_optimize_above_cost;
 
 
 extern void jit_reset_after_error(void);
diff --git a/src/include/jit/llvmjit.h b/src/include/jit/llvmjit.h
index 66143afccc..4541f9a2c4 100644
--- a/src/include/jit/llvmjit.h
+++ b/src/include/jit/llvmjit.h
@@ -56,30 +56,30 @@ typedef struct LLVMJitContext
 } LLVMJitContext;
 
 /* llvm module containing information about types */
-extern LLVMModuleRef llvm_types_module;
+extern PGDLLIMPORT LLVMModuleRef llvm_types_module;
 
 /* type and struct definitions */
-extern LLVMTypeRef TypeParamBool;
-extern LLVMTypeRef TypePGFunction;
-extern LLVMTypeRef TypeSizeT;
-extern LLVMTypeRef TypeStorageBool;
-
-extern LLVMTypeRef StructNullableDatum;
-extern LLVMTypeRef StructTupleDescData;
-extern LLVMTypeRef StructHeapTupleData;
-extern LLVMTypeRef StructTupleTableSlot;
-extern LLVMTypeRef StructHeapTupleTableSlot;
-extern LLVMTypeRef StructMinimalTupleTableSlot;
-extern LLVMTypeRef StructMemoryContextData;
-extern LLVMTypeRef StructFunctionCallInfoData;
-extern LLVMTypeRef StructExprContext;
-extern LLVMTypeRef StructExprEvalStep;
-extern LLVMTypeRef StructExprState;
-extern LLVMTypeRef StructAggState;
-extern LLVMTypeRef StructAggStatePerTransData;
-extern LLVMTypeRef StructAggStatePerGroupData;
-
-extern LLVMValueRef AttributeTemplate;
+extern PGDLLIMPORT LLVMTypeRef TypeParamBool;
+extern PGDLLIMPORT LLVMTypeRef TypePGFunction;
+extern PGDLLIMPORT LLVMTypeRef TypeSizeT;
+extern PGDLLIMPORT LLVMTypeRef TypeStorageBool;
+
+extern PGDLLIMPORT LLVMTypeRef StructNullableDatum;
+extern PGDLLIMPORT LLVMTypeRef StructTupleDescData;
+extern PGDLLIMPORT LLVMTypeRef StructHeapTupleData;
+extern PGDLLIMPORT LLVMTypeRef StructTupleTableSlot;
+extern PGDLLIMPORT LLVMTypeRef StructHeapTupleTableSlot;
+extern PGDLLIMPORT LLVMTypeRef StructMinimalTupleTableSlot;
+extern PGDLLIMPORT LLVMTypeRef StructMemoryContextData;
+extern PGDLLIMPORT LLVMTypeRef StructFunctionCallInfoData;
+extern PGDLLIMPORT LLVMTypeRef StructExprContext;
+extern PGDLLIMPORT LLVMTypeRef StructExprEvalStep;
+extern PGDLLIMPORT LLVMTypeRef StructExprState;
+extern PGDLLIMPORT LLVMTypeRef StructAggState;
+extern PGDLLIMPORT LLVMTypeRef StructAggStatePerTransData;
+extern PGDLLIMPORT LLVMTypeRef StructAggStatePerGroupData;
+
+extern PGDLLIMPORT LLVMValueRef AttributeTemplate;
 
 
 extern void llvm_enter_fatal_on_oom(void);
diff --git a/src/include/libpq/auth.h b/src/include/libpq/auth.h
index 6d7ee1acb9..d3c189efe3 100644
--- a/src/include/libpq/auth.h
+++ b/src/include/libpq/auth.h
@@ -16,9 +16,9 @@
 
 #include "libpq/libpq-be.h"
 
-extern char *pg_krb_server_keyfile;
-extern bool pg_krb_caseins_users;
-extern char *pg_krb_realm;
+extern PGDLLIMPORT char *pg_krb_server_keyfile;
+extern PGDLLIMPORT bool pg_krb_caseins_users;
+extern PGDLLIMPORT char *pg_krb_realm;
 
 extern void ClientAuthentication(Port *port);
 extern void sendAuthRequest(Port *port, AuthRequest areq, const char *extradata,
diff --git a/src/include/libpq/libpq-be.h b/src/include/libpq/libpq-be.h
index dd3e5efba3..3beeaeee39 100644
--- a/src/include/libpq/libpq-be.h
+++ b/src/include/libpq/libpq-be.h
@@ -327,7 +327,7 @@ extern ssize_t be_gssapi_read(Port *port, void *ptr, size_t len);
 extern ssize_t be_gssapi_write(Port *port, void *ptr, size_t len);
 #endif							/* ENABLE_GSS */
 
-extern ProtocolVersion FrontendProtocol;
+extern PGDLLIMPORT ProtocolVersion FrontendProtocol;
 
 /* TCP keepalives configuration. These are no-ops on an AF_UNIX socket. */
 
diff --git a/src/include/libpq/libpq.h b/src/include/libpq/libpq.h
index d348a55812..2de7d9bad2 100644
--- a/src/include/libpq/libpq.h
+++ b/src/include/libpq/libpq.h
@@ -58,7 +58,7 @@ extern const PGDLLIMPORT PQcommMethods *PqCommMethods;
 /*
  * prototypes for functions in pqcomm.c
  */
-extern WaitEventSet *FeBeWaitSet;
+extern PGDLLIMPORT WaitEventSet *FeBeWaitSet;
 
 #define FeBeWaitSetSocketPos 0
 #define FeBeWaitSetLatchPos 1
@@ -87,17 +87,17 @@ extern bool pq_check_connection(void);
 /*
  * prototypes for functions in be-secure.c
  */
-extern char *ssl_library;
-extern char *ssl_cert_file;
-extern char *ssl_key_file;
-extern char *ssl_ca_file;
-extern char *ssl_crl_file;
-extern char *ssl_crl_dir;
-extern char *ssl_dh_params_file;
+extern PGDLLIMPORT char *ssl_library;
+extern PGDLLIMPORT char *ssl_cert_file;
+extern PGDLLIMPORT char *ssl_key_file;
+extern PGDLLIMPORT char *ssl_ca_file;
+extern PGDLLIMPORT char *ssl_crl_file;
+extern PGDLLIMPORT char *ssl_crl_dir;
+extern PGDLLIMPORT char *ssl_dh_params_file;
 extern PGDLLIMPORT char *ssl_passphrase_command;
 extern PGDLLIMPORT bool ssl_passphrase_command_supports_reload;
 #ifdef USE_SSL
-extern bool ssl_loaded_verify_locations;
+extern PGDLLIMPORT bool ssl_loaded_verify_locations;
 #endif
 
 extern int	secure_initialize(bool isServerStart);
@@ -118,11 +118,11 @@ extern ssize_t secure_open_gssapi(Port *port);
 #endif
 
 /* GUCs */
-extern char *SSLCipherSuites;
-extern char *SSLECDHCurve;
-extern bool SSLPreferServerCiphers;
-extern int	ssl_min_protocol_version;
-extern int	ssl_max_protocol_version;
+extern PGDLLIMPORT char *SSLCipherSuites;
+extern PGDLLIMPORT char *SSLECDHCurve;
+extern PGDLLIMPORT bool SSLPreferServerCiphers;
+extern PGDLLIMPORT int ssl_min_protocol_version;
+extern PGDLLIMPORT int ssl_max_protocol_version;
 
 enum ssl_protocol_versions
 {
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index ed26ad2256..b418283d5f 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -135,7 +135,7 @@ typedef ProtocolVersion MsgType;
 
 typedef uint32 PacketLen;
 
-extern bool Db_user_namespace;
+extern PGDLLIMPORT bool Db_user_namespace;
 
 /*
  * In protocol 3.0 and later, the startup packet length is not fixed, but
diff --git a/src/include/libpq/scram.h b/src/include/libpq/scram.h
index e60992a0d2..c51e848c24 100644
--- a/src/include/libpq/scram.h
+++ b/src/include/libpq/scram.h
@@ -18,7 +18,7 @@
 #include "libpq/sasl.h"
 
 /* SASL implementation callbacks */
-extern const pg_be_sasl_mech pg_be_scram_mech;
+extern PGDLLIMPORT const pg_be_sasl_mech pg_be_scram_mech;
 
 /* Routines to handle and check SCRAM-SHA-256 secret */
 extern char *pg_be_scram_build_secret(const char *password);
diff --git a/src/include/mb/pg_wchar.h b/src/include/mb/pg_wchar.h
index fd89bee80b..31f5b393da 100644
--- a/src/include/mb/pg_wchar.h
+++ b/src/include/mb/pg_wchar.h
@@ -359,7 +359,7 @@ typedef struct pg_enc2name
 #endif
 } pg_enc2name;
 
-extern const pg_enc2name pg_enc2name_tbl[];
+extern PGDLLIMPORT const pg_enc2name pg_enc2name_tbl[];
 
 /*
  * Encoding names for gettext
@@ -370,7 +370,7 @@ typedef struct pg_enc2gettext
 	const char *name;
 } pg_enc2gettext;
 
-extern const pg_enc2gettext pg_enc2gettext_tbl[];
+extern PGDLLIMPORT const pg_enc2gettext pg_enc2gettext_tbl[];
 
 /*
  * pg_wchar stuff
@@ -406,7 +406,7 @@ typedef struct
 	int			maxmblen;		/* max bytes for a char in this encoding */
 } pg_wchar_tbl;
 
-extern const pg_wchar_tbl pg_wchar_table[];
+extern PGDLLIMPORT const pg_wchar_tbl pg_wchar_table[];
 
 /*
  * Data structures for conversions between UTF-8 and other encodings
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index 0abc3ad540..7a8ca4a2d2 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -181,15 +181,15 @@ extern PGDLLIMPORT pg_time_t MyStartTime;
 extern PGDLLIMPORT TimestampTz MyStartTimestamp;
 extern PGDLLIMPORT struct Port *MyProcPort;
 extern PGDLLIMPORT struct Latch *MyLatch;
-extern int32 MyCancelKey;
-extern int	MyPMChildSlot;
+extern PGDLLIMPORT int32 MyCancelKey;
+extern PGDLLIMPORT int MyPMChildSlot;
 
-extern char OutputFileName[];
+extern PGDLLIMPORT char OutputFileName[];
 extern PGDLLIMPORT char my_exec_path[];
-extern char pkglib_path[];
+extern PGDLLIMPORT char pkglib_path[];
 
 #ifdef EXEC_BACKEND
-extern char postgres_exec_path[];
+extern PGDLLIMPORT char postgres_exec_path[];
 #endif
 
 /*
@@ -254,25 +254,25 @@ extern PGDLLIMPORT int IntervalStyle;
 
 #define MAXTZLEN		10		/* max TZ name len, not counting tr. null */
 
-extern bool enableFsync;
+extern PGDLLIMPORT bool enableFsync;
 extern PGDLLIMPORT bool allowSystemTableMods;
 extern PGDLLIMPORT int work_mem;
 extern PGDLLIMPORT double hash_mem_multiplier;
 extern PGDLLIMPORT int maintenance_work_mem;
 extern PGDLLIMPORT int max_parallel_maintenance_workers;
 
-extern int	VacuumCostPageHit;
-extern int	VacuumCostPageMiss;
-extern int	VacuumCostPageDirty;
-extern int	VacuumCostLimit;
-extern double VacuumCostDelay;
+extern PGDLLIMPORT int VacuumCostPageHit;
+extern PGDLLIMPORT int VacuumCostPageMiss;
+extern PGDLLIMPORT int VacuumCostPageDirty;
+extern PGDLLIMPORT int VacuumCostLimit;
+extern PGDLLIMPORT double VacuumCostDelay;
 
-extern int64 VacuumPageHit;
-extern int64 VacuumPageMiss;
-extern int64 VacuumPageDirty;
+extern PGDLLIMPORT int64 VacuumPageHit;
+extern PGDLLIMPORT int64 VacuumPageMiss;
+extern PGDLLIMPORT int64 VacuumPageDirty;
 
-extern int	VacuumCostBalance;
-extern bool VacuumCostActive;
+extern PGDLLIMPORT int VacuumCostBalance;
+extern PGDLLIMPORT bool VacuumCostActive;
 
 
 /* in tcop/postgres.c */
@@ -298,7 +298,7 @@ extern void PreventCommandIfParallelMode(const char *cmdname);
 extern void PreventCommandDuringRecovery(const char *cmdname);
 
 /* in utils/misc/guc.c */
-extern int	trace_recovery_messages;
+extern PGDLLIMPORT int trace_recovery_messages;
 extern int	trace_recovery(int trace_level);
 
 /*****************************************************************************
@@ -311,7 +311,7 @@ extern int	trace_recovery(int trace_level);
 #define SECURITY_RESTRICTED_OPERATION	0x0002
 #define SECURITY_NOFORCE_RLS			0x0004
 
-extern char *DatabasePath;
+extern PGDLLIMPORT char *DatabasePath;
 
 /* now in utils/init/miscinit.c */
 extern void InitPostmasterChild(void);
@@ -337,7 +337,7 @@ typedef enum BackendType
 	B_LOGGER,
 } BackendType;
 
-extern BackendType MyBackendType;
+extern PGDLLIMPORT BackendType MyBackendType;
 
 extern const char *GetBackendTypeDesc(BackendType backendType);
 
@@ -400,7 +400,7 @@ typedef enum ProcessingMode
 	NormalProcessing			/* normal processing */
 } ProcessingMode;
 
-extern ProcessingMode Mode;
+extern PGDLLIMPORT ProcessingMode Mode;
 
 #define IsBootstrapProcessingMode() (Mode == BootstrapProcessing)
 #define IsInitProcessingMode()		(Mode == InitProcessing)
@@ -438,7 +438,7 @@ typedef enum
 	NUM_AUXPROCTYPES			/* Must be last! */
 } AuxProcType;
 
-extern AuxProcType MyAuxProcType;
+extern PGDLLIMPORT AuxProcType MyAuxProcType;
 
 #define AmStartupProcess()			(MyAuxProcType == StartupProcess)
 #define AmBackgroundWriterProcess() (MyAuxProcType == BgWriterProcess)
@@ -456,18 +456,18 @@ extern AuxProcType MyAuxProcType;
 /* in utils/init/postinit.c */
 extern void pg_split_opts(char **argv, int *argcp, const char *optstr);
 extern void InitializeMaxBackends(void);
-extern int GetMaxBackends(void);
+extern int	GetMaxBackends(void);
 extern void SetMaxBackends(int max_backends);
 extern void InitPostgres(const char *in_dbname, Oid dboid, const char *username,
 						 Oid useroid, char *out_dbname, bool override_allow_connections);
 extern void BaseInit(void);
 
 /* in utils/init/miscinit.c */
-extern bool IgnoreSystemIndexes;
+extern PGDLLIMPORT bool IgnoreSystemIndexes;
 extern PGDLLIMPORT bool process_shared_preload_libraries_in_progress;
-extern char *session_preload_libraries_string;
-extern char *shared_preload_libraries_string;
-extern char *local_preload_libraries_string;
+extern PGDLLIMPORT char *session_preload_libraries_string;
+extern PGDLLIMPORT char *shared_preload_libraries_string;
+extern PGDLLIMPORT char *local_preload_libraries_string;
 
 extern void CreateDataDirLockFile(bool amPostmaster);
 extern void CreateSocketLockFile(const char *socketfile, bool amPostmaster,
diff --git a/src/include/nodes/readfuncs.h b/src/include/nodes/readfuncs.h
index 41794354e2..66717fd6c3 100644
--- a/src/include/nodes/readfuncs.h
+++ b/src/include/nodes/readfuncs.h
@@ -20,7 +20,7 @@
  * variable in read.c that needs to be accessible to readfuncs.c
  */
 #ifdef WRITE_READ_PARSE_PLAN_TREES
-extern bool restore_location_fields;
+extern PGDLLIMPORT bool restore_location_fields;
 #endif
 
 /*
diff --git a/src/include/optimizer/geqo.h b/src/include/optimizer/geqo.h
index 4563f200cd..d399323332 100644
--- a/src/include/optimizer/geqo.h
+++ b/src/include/optimizer/geqo.h
@@ -49,23 +49,24 @@
  *
  * If you change these, update backend/utils/misc/postgresql.conf.sample
  */
-extern int	Geqo_effort;		/* 1 .. 10, knob for adjustment of defaults */
+extern PGDLLIMPORT int Geqo_effort; /* 1 .. 10, knob for adjustment of
+									 * defaults */
 
 #define DEFAULT_GEQO_EFFORT 5
 #define MIN_GEQO_EFFORT 1
 #define MAX_GEQO_EFFORT 10
 
-extern int	Geqo_pool_size;		/* 2 .. inf, or 0 to use default */
+extern PGDLLIMPORT int Geqo_pool_size;	/* 2 .. inf, or 0 to use default */
 
-extern int	Geqo_generations;	/* 1 .. inf, or 0 to use default */
+extern PGDLLIMPORT int Geqo_generations;	/* 1 .. inf, or 0 to use default */
 
-extern double Geqo_selection_bias;
+extern PGDLLIMPORT double Geqo_selection_bias;
 
 #define DEFAULT_GEQO_SELECTION_BIAS 2.0
 #define MIN_GEQO_SELECTION_BIAS 1.5
 #define MAX_GEQO_SELECTION_BIAS 2.0
 
-extern double Geqo_seed;		/* 0 .. 1 */
+extern PGDLLIMPORT double Geqo_seed;	/* 0 .. 1 */
 
 
 /*
diff --git a/src/include/optimizer/optimizer.h b/src/include/optimizer/optimizer.h
index 2302ab6d54..d40ce2eae1 100644
--- a/src/include/optimizer/optimizer.h
+++ b/src/include/optimizer/optimizer.h
@@ -112,8 +112,8 @@ typedef enum
 }			ForceParallelMode;
 
 /* GUC parameters */
-extern int	force_parallel_mode;
-extern bool parallel_leader_participation;
+extern PGDLLIMPORT int force_parallel_mode;
+extern PGDLLIMPORT bool parallel_leader_participation;
 
 extern struct PlannedStmt *planner(Query *parse, const char *query_string,
 								   int cursorOptions,
diff --git a/src/include/optimizer/planmain.h b/src/include/optimizer/planmain.h
index 54a0d4c188..a09b3a3e83 100644
--- a/src/include/optimizer/planmain.h
+++ b/src/include/optimizer/planmain.h
@@ -19,7 +19,7 @@
 
 /* GUC parameters */
 #define DEFAULT_CURSOR_TUPLE_FRACTION 0.1
-extern double cursor_tuple_fraction;
+extern PGDLLIMPORT double cursor_tuple_fraction;
 
 /* query_planner callback to compute query_pathkeys */
 typedef void (*query_pathkeys_callback) (PlannerInfo *root, void *extra);
@@ -64,8 +64,8 @@ extern Limit *make_limit(Plan *lefttree, Node *limitOffset, Node *limitCount,
 /*
  * prototypes for plan/initsplan.c
  */
-extern int	from_collapse_limit;
-extern int	join_collapse_limit;
+extern PGDLLIMPORT int from_collapse_limit;
+extern PGDLLIMPORT int join_collapse_limit;
 
 extern void add_base_rels_to_query(PlannerInfo *root, Node *jtnode);
 extern void add_other_rels_to_query(PlannerInfo *root);
diff --git a/src/include/parser/parse_expr.h b/src/include/parser/parse_expr.h
index 308e84edda..c8e5c57b43 100644
--- a/src/include/parser/parse_expr.h
+++ b/src/include/parser/parse_expr.h
@@ -16,7 +16,7 @@
 #include "parser/parse_node.h"
 
 /* GUC parameters */
-extern bool Transform_null_equals;
+extern PGDLLIMPORT bool Transform_null_equals;
 
 extern Node *transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind);
 
diff --git a/src/include/parser/parser.h b/src/include/parser/parser.h
index 6aac0e096a..828150f01b 100644
--- a/src/include/parser/parser.h
+++ b/src/include/parser/parser.h
@@ -53,8 +53,8 @@ typedef enum
 }			BackslashQuoteType;
 
 /* GUC variables in scan.l (every one of these is a bad idea :-() */
-extern int	backslash_quote;
-extern bool escape_string_warning;
+extern PGDLLIMPORT int backslash_quote;
+extern PGDLLIMPORT bool escape_string_warning;
 extern PGDLLIMPORT bool standard_conforming_strings;
 
 
diff --git a/src/include/pg_getopt.h b/src/include/pg_getopt.h
index ec9f6e6ee3..9d91e602e6 100644
--- a/src/include/pg_getopt.h
+++ b/src/include/pg_getopt.h
@@ -33,10 +33,10 @@
  */
 #ifndef HAVE_GETOPT_H
 
-extern char *optarg;
-extern int	optind;
-extern int	opterr;
-extern int	optopt;
+extern PGDLLIMPORT char *optarg;
+extern PGDLLIMPORT int optind;
+extern PGDLLIMPORT int opterr;
+extern PGDLLIMPORT int optopt;
 
 #endif							/* HAVE_GETOPT_H */
 
@@ -45,7 +45,7 @@ extern int	optopt;
  * Cygwin, however, doesn't like this either.
  */
 #if defined(HAVE_INT_OPTRESET) && !defined(__CYGWIN__)
-extern int	optreset;
+extern PGDLLIMPORT int optreset;
 #endif
 
 /* Provide getopt() declaration if the platform doesn't have it */
diff --git a/src/include/pgstat.h b/src/include/pgstat.h
index 534d595ca0..b36511a850 100644
--- a/src/include/pgstat.h
+++ b/src/include/pgstat.h
@@ -1207,9 +1207,9 @@ extern void pgstat_send_wal(bool force);
 /* GUC parameters */
 extern PGDLLIMPORT bool pgstat_track_counts;
 extern PGDLLIMPORT int pgstat_track_functions;
-extern char *pgstat_stat_directory;
-extern char *pgstat_stat_tmpname;
-extern char *pgstat_stat_filename;
+extern PGDLLIMPORT char *pgstat_stat_directory;
+extern PGDLLIMPORT char *pgstat_stat_tmpname;
+extern PGDLLIMPORT char *pgstat_stat_filename;
 
 
 /*
@@ -1217,7 +1217,7 @@ extern char *pgstat_stat_filename;
  */
 
 /* updated directly by bgwriter and bufmgr */
-extern PgStat_MsgBgWriter PendingBgWriterStats;
+extern PGDLLIMPORT PgStat_MsgBgWriter PendingBgWriterStats;
 
 
 /*
@@ -1228,7 +1228,7 @@ extern PgStat_MsgBgWriter PendingBgWriterStats;
  * Checkpointer statistics counters are updated directly by checkpointer and
  * bufmgr.
  */
-extern PgStat_MsgCheckpointer PendingCheckpointerStats;
+extern PGDLLIMPORT PgStat_MsgCheckpointer PendingCheckpointerStats;
 
 
 /*
@@ -1236,18 +1236,18 @@ extern PgStat_MsgCheckpointer PendingCheckpointerStats;
  */
 
 /* Updated by pgstat_count_buffer_*_time macros */
-extern PgStat_Counter pgStatBlockReadTime;
-extern PgStat_Counter pgStatBlockWriteTime;
+extern PGDLLIMPORT PgStat_Counter pgStatBlockReadTime;
+extern PGDLLIMPORT PgStat_Counter pgStatBlockWriteTime;
 
 /*
  * Updated by pgstat_count_conn_*_time macros, called by
  * pgstat_report_activity().
  */
-extern PgStat_Counter pgStatActiveTime;
-extern PgStat_Counter pgStatTransactionIdleTime;
+extern PGDLLIMPORT PgStat_Counter pgStatActiveTime;
+extern PGDLLIMPORT PgStat_Counter pgStatTransactionIdleTime;
 
 /* updated by the traffic cop and in errfinish() */
-extern SessionEndType pgStatSessionEndCause;
+extern PGDLLIMPORT SessionEndType pgStatSessionEndCause;
 
 
 /*
@@ -1255,7 +1255,7 @@ extern SessionEndType pgStatSessionEndCause;
  */
 
 /* updated directly by backends and background processes */
-extern PgStat_MsgWal WalStats;
+extern PGDLLIMPORT PgStat_MsgWal WalStats;
 
 
 #endif							/* PGSTAT_H */
diff --git a/src/include/pgtime.h b/src/include/pgtime.h
index 2977b13aab..5934435978 100644
--- a/src/include/pgtime.h
+++ b/src/include/pgtime.h
@@ -78,7 +78,7 @@ extern size_t pg_strftime(char *s, size_t max, const char *format,
 /* these functions and variables are in pgtz.c */
 
 extern PGDLLIMPORT pg_tz *session_timezone;
-extern pg_tz *log_timezone;
+extern PGDLLIMPORT pg_tz *log_timezone;
 
 extern void pg_timezone_initialize(void);
 extern pg_tz *pg_tzset(const char *tzname);
diff --git a/src/include/port/win32_port.h b/src/include/port/win32_port.h
index 4bb6fc5e1e..5045ced91b 100644
--- a/src/include/port/win32_port.h
+++ b/src/include/port/win32_port.h
@@ -449,8 +449,8 @@ extern char *pgwin32_setlocale(int category, const char *locale);
 /* In backend/port/win32/signal.c */
 extern PGDLLIMPORT volatile int pg_signal_queue;
 extern PGDLLIMPORT int pg_signal_mask;
-extern HANDLE pgwin32_signal_event;
-extern HANDLE pgwin32_initial_signal_pipe;
+extern PGDLLIMPORT HANDLE pgwin32_signal_event;
+extern PGDLLIMPORT HANDLE pgwin32_initial_signal_pipe;
 
 #define UNBLOCKED_SIGNAL_QUEUE()	(pg_signal_queue & ~pg_signal_mask)
 #define PG_SIGNAL_COUNT 32
@@ -485,7 +485,7 @@ int			pgwin32_recv(SOCKET s, char *buf, int len, int flags);
 int			pgwin32_send(SOCKET s, const void *buf, int len, int flags);
 int			pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout);
 
-extern int	pgwin32_noblock;
+extern PGDLLIMPORT int pgwin32_noblock;
 
 #endif							/* FRONTEND */
 
diff --git a/src/include/port/win32ntdll.h b/src/include/port/win32ntdll.h
index 663b9754bd..291b067ea4 100644
--- a/src/include/port/win32ntdll.h
+++ b/src/include/port/win32ntdll.h
@@ -23,9 +23,9 @@
 #include <ntstatus.h>
 #include <winternl.h>
 
-typedef NTSTATUS (__stdcall *RtlGetLastNtStatus_t) (void);
+typedef NTSTATUS (__stdcall * RtlGetLastNtStatus_t) (void);
 
-extern RtlGetLastNtStatus_t pg_RtlGetLastNtStatus;
+extern PGDLLIMPORT RtlGetLastNtStatus_t pg_RtlGetLastNtStatus;
 
 extern int	initialize_ntdll(void);
 
diff --git a/src/include/postmaster/autovacuum.h b/src/include/postmaster/autovacuum.h
index 30a2b3274f..9d40fd6d54 100644
--- a/src/include/postmaster/autovacuum.h
+++ b/src/include/postmaster/autovacuum.h
@@ -27,25 +27,25 @@ typedef enum
 
 
 /* GUC variables */
-extern bool autovacuum_start_daemon;
-extern int	autovacuum_max_workers;
-extern int	autovacuum_work_mem;
-extern int	autovacuum_naptime;
-extern int	autovacuum_vac_thresh;
-extern double autovacuum_vac_scale;
-extern int	autovacuum_vac_ins_thresh;
-extern double autovacuum_vac_ins_scale;
-extern int	autovacuum_anl_thresh;
-extern double autovacuum_anl_scale;
-extern int	autovacuum_freeze_max_age;
-extern int	autovacuum_multixact_freeze_max_age;
-extern double autovacuum_vac_cost_delay;
-extern int	autovacuum_vac_cost_limit;
+extern PGDLLIMPORT bool autovacuum_start_daemon;
+extern PGDLLIMPORT int autovacuum_max_workers;
+extern PGDLLIMPORT int autovacuum_work_mem;
+extern PGDLLIMPORT int autovacuum_naptime;
+extern PGDLLIMPORT int autovacuum_vac_thresh;
+extern PGDLLIMPORT double autovacuum_vac_scale;
+extern PGDLLIMPORT int autovacuum_vac_ins_thresh;
+extern PGDLLIMPORT double autovacuum_vac_ins_scale;
+extern PGDLLIMPORT int autovacuum_anl_thresh;
+extern PGDLLIMPORT double autovacuum_anl_scale;
+extern PGDLLIMPORT int autovacuum_freeze_max_age;
+extern PGDLLIMPORT int autovacuum_multixact_freeze_max_age;
+extern PGDLLIMPORT double autovacuum_vac_cost_delay;
+extern PGDLLIMPORT int autovacuum_vac_cost_limit;
 
 /* autovacuum launcher PID, only valid when worker is shutting down */
-extern int	AutovacuumLauncherPid;
+extern PGDLLIMPORT int AutovacuumLauncherPid;
 
-extern int	Log_autovacuum_min_duration;
+extern PGDLLIMPORT int Log_autovacuum_min_duration;
 
 /* Status inquiry functions */
 extern bool AutoVacuumingActive(void);
diff --git a/src/include/postmaster/bgworker_internals.h b/src/include/postmaster/bgworker_internals.h
index 75900686fc..387683546d 100644
--- a/src/include/postmaster/bgworker_internals.h
+++ b/src/include/postmaster/bgworker_internals.h
@@ -42,7 +42,7 @@ typedef struct RegisteredBgWorker
 	slist_node	rw_lnode;		/* list link */
 } RegisteredBgWorker;
 
-extern slist_head BackgroundWorkerList;
+extern PGDLLIMPORT slist_head BackgroundWorkerList;
 
 extern Size BackgroundWorkerShmemSize(void);
 extern void BackgroundWorkerShmemInit(void);
diff --git a/src/include/postmaster/bgwriter.h b/src/include/postmaster/bgwriter.h
index 2882efd67b..2511ef451e 100644
--- a/src/include/postmaster/bgwriter.h
+++ b/src/include/postmaster/bgwriter.h
@@ -22,10 +22,10 @@
 
 
 /* GUC options */
-extern int	BgWriterDelay;
-extern int	CheckPointTimeout;
-extern int	CheckPointWarning;
-extern double CheckPointCompletionTarget;
+extern PGDLLIMPORT int BgWriterDelay;
+extern PGDLLIMPORT int CheckPointTimeout;
+extern PGDLLIMPORT int CheckPointWarning;
+extern PGDLLIMPORT double CheckPointCompletionTarget;
 
 extern void BackgroundWriterMain(void) pg_attribute_noreturn();
 extern void CheckpointerMain(void) pg_attribute_noreturn();
diff --git a/src/include/postmaster/pgarch.h b/src/include/postmaster/pgarch.h
index 9bc7593a2d..f366a159a8 100644
--- a/src/include/postmaster/pgarch.h
+++ b/src/include/postmaster/pgarch.h
@@ -36,7 +36,7 @@ extern void PgArchForceDirScan(void);
 /*
  * The value of the archive_library GUC.
  */
-extern char *XLogArchiveLibrary;
+extern PGDLLIMPORT char *XLogArchiveLibrary;
 
 /*
  * Archive module callbacks
diff --git a/src/include/postmaster/postmaster.h b/src/include/postmaster/postmaster.h
index 324a30ec1a..90e333ccd2 100644
--- a/src/include/postmaster/postmaster.h
+++ b/src/include/postmaster/postmaster.h
@@ -14,27 +14,27 @@
 #define _POSTMASTER_H
 
 /* GUC options */
-extern bool EnableSSL;
-extern int	ReservedBackends;
+extern PGDLLIMPORT bool EnableSSL;
+extern PGDLLIMPORT int ReservedBackends;
 extern PGDLLIMPORT int PostPortNumber;
-extern int	Unix_socket_permissions;
-extern char *Unix_socket_group;
-extern char *Unix_socket_directories;
-extern char *ListenAddresses;
-extern bool ClientAuthInProgress;
-extern int	PreAuthDelay;
-extern int	AuthenticationTimeout;
-extern bool Log_connections;
-extern bool log_hostname;
-extern bool enable_bonjour;
-extern char *bonjour_name;
-extern bool restart_after_crash;
-extern bool remove_temp_files_after_crash;
+extern PGDLLIMPORT int Unix_socket_permissions;
+extern PGDLLIMPORT char *Unix_socket_group;
+extern PGDLLIMPORT char *Unix_socket_directories;
+extern PGDLLIMPORT char *ListenAddresses;
+extern PGDLLIMPORT bool ClientAuthInProgress;
+extern PGDLLIMPORT int PreAuthDelay;
+extern PGDLLIMPORT int AuthenticationTimeout;
+extern PGDLLIMPORT bool Log_connections;
+extern PGDLLIMPORT bool log_hostname;
+extern PGDLLIMPORT bool enable_bonjour;
+extern PGDLLIMPORT char *bonjour_name;
+extern PGDLLIMPORT bool restart_after_crash;
+extern PGDLLIMPORT bool remove_temp_files_after_crash;
 
 #ifdef WIN32
-extern HANDLE PostmasterHandle;
+extern PGDLLIMPORT HANDLE PostmasterHandle;
 #else
-extern int	postmaster_alive_fds[2];
+extern PGDLLIMPORT int postmaster_alive_fds[2];
 
 /*
  * Constants that represent which of postmaster_alive_fds is held by
diff --git a/src/include/postmaster/startup.h b/src/include/postmaster/startup.h
index 7e39db7159..d66ec1fcb1 100644
--- a/src/include/postmaster/startup.h
+++ b/src/include/postmaster/startup.h
@@ -23,7 +23,7 @@
 			ereport(LOG, errmsg(msg, secs, (usecs / 10000),  __VA_ARGS__ )); \
 	} while(0)
 
-extern int  log_startup_progress_interval;
+extern PGDLLIMPORT int log_startup_progress_interval;
 
 extern void HandleStartupProcInterrupts(void);
 extern void StartupProcessMain(void) pg_attribute_noreturn();
diff --git a/src/include/postmaster/syslogger.h b/src/include/postmaster/syslogger.h
index 1ca326e52e..6436724f3d 100644
--- a/src/include/postmaster/syslogger.h
+++ b/src/include/postmaster/syslogger.h
@@ -67,18 +67,18 @@ typedef union
 #define PIPE_PROTO_DEST_JSONLOG	0x40
 
 /* GUC options */
-extern bool Logging_collector;
-extern int	Log_RotationAge;
-extern int	Log_RotationSize;
+extern PGDLLIMPORT bool Logging_collector;
+extern PGDLLIMPORT int Log_RotationAge;
+extern PGDLLIMPORT int Log_RotationSize;
 extern PGDLLIMPORT char *Log_directory;
 extern PGDLLIMPORT char *Log_filename;
-extern bool Log_truncate_on_rotation;
-extern int	Log_file_mode;
+extern PGDLLIMPORT bool Log_truncate_on_rotation;
+extern PGDLLIMPORT int Log_file_mode;
 
 #ifndef WIN32
-extern int	syslogPipe[2];
+extern PGDLLIMPORT int syslogPipe[2];
 #else
-extern HANDLE syslogPipe[2];
+extern PGDLLIMPORT HANDLE syslogPipe[2];
 #endif
 
 
diff --git a/src/include/postmaster/walwriter.h b/src/include/postmaster/walwriter.h
index 5a3011d9c9..ddc943657e 100644
--- a/src/include/postmaster/walwriter.h
+++ b/src/include/postmaster/walwriter.h
@@ -13,8 +13,8 @@
 #define _WALWRITER_H
 
 /* GUC options */
-extern int	WalWriterDelay;
-extern int	WalWriterFlushAfter;
+extern PGDLLIMPORT int WalWriterDelay;
+extern PGDLLIMPORT int WalWriterFlushAfter;
 
 extern void WalWriterMain(void) pg_attribute_noreturn();
 
diff --git a/src/include/replication/logicallauncher.h b/src/include/replication/logicallauncher.h
index 15596fe446..f1e2821e25 100644
--- a/src/include/replication/logicallauncher.h
+++ b/src/include/replication/logicallauncher.h
@@ -12,8 +12,8 @@
 #ifndef LOGICALLAUNCHER_H
 #define LOGICALLAUNCHER_H
 
-extern int	max_logical_replication_workers;
-extern int	max_sync_workers_per_subscription;
+extern PGDLLIMPORT int max_logical_replication_workers;
+extern PGDLLIMPORT int max_sync_workers_per_subscription;
 
 extern void ApplyLauncherRegister(void);
 extern void ApplyLauncherMain(Datum main_arg);
diff --git a/src/include/replication/syncrep.h b/src/include/replication/syncrep.h
index 27be230d77..4d7c90b9f0 100644
--- a/src/include/replication/syncrep.h
+++ b/src/include/replication/syncrep.h
@@ -72,14 +72,14 @@ typedef struct SyncRepConfigData
 	char		member_names[FLEXIBLE_ARRAY_MEMBER];
 } SyncRepConfigData;
 
-extern SyncRepConfigData *SyncRepConfig;
+extern PGDLLIMPORT SyncRepConfigData *SyncRepConfig;
 
 /* communication variables for parsing synchronous_standby_names GUC */
-extern SyncRepConfigData *syncrep_parse_result;
-extern char *syncrep_parse_error_msg;
+extern PGDLLIMPORT SyncRepConfigData *syncrep_parse_result;
+extern PGDLLIMPORT char *syncrep_parse_error_msg;
 
 /* user-settable parameters for synchronous replication */
-extern char *SyncRepStandbyNames;
+extern PGDLLIMPORT char *SyncRepStandbyNames;
 
 /* called by user backend */
 extern void SyncRepWaitForLSN(XLogRecPtr lsn, bool commit);
diff --git a/src/include/replication/walreceiver.h b/src/include/replication/walreceiver.h
index 92f73a55b8..81184aa92f 100644
--- a/src/include/replication/walreceiver.h
+++ b/src/include/replication/walreceiver.h
@@ -25,9 +25,9 @@
 #include "utils/tuplestore.h"
 
 /* user-settable parameters */
-extern int	wal_receiver_status_interval;
-extern int	wal_receiver_timeout;
-extern bool hot_standby_feedback;
+extern PGDLLIMPORT int wal_receiver_status_interval;
+extern PGDLLIMPORT int wal_receiver_timeout;
+extern PGDLLIMPORT bool hot_standby_feedback;
 
 /*
  * MAXCONNINFO: maximum size of a connection string.
@@ -160,7 +160,7 @@ typedef struct
 	sig_atomic_t force_reply;	/* used as a bool */
 } WalRcvData;
 
-extern WalRcvData *WalRcv;
+extern PGDLLIMPORT WalRcvData *WalRcv;
 
 typedef struct
 {
diff --git a/src/include/replication/walsender.h b/src/include/replication/walsender.h
index b1892e9e4b..d99a21b077 100644
--- a/src/include/replication/walsender.h
+++ b/src/include/replication/walsender.h
@@ -25,15 +25,15 @@ typedef enum
 } CRSSnapshotAction;
 
 /* global state */
-extern bool am_walsender;
-extern bool am_cascading_walsender;
-extern bool am_db_walsender;
-extern bool wake_wal_senders;
+extern PGDLLIMPORT bool am_walsender;
+extern PGDLLIMPORT bool am_cascading_walsender;
+extern PGDLLIMPORT bool am_db_walsender;
+extern PGDLLIMPORT bool wake_wal_senders;
 
 /* user-settable parameters */
-extern int	max_wal_senders;
-extern int	wal_sender_timeout;
-extern bool log_replication_commands;
+extern PGDLLIMPORT int max_wal_senders;
+extern PGDLLIMPORT int wal_sender_timeout;
+extern PGDLLIMPORT bool log_replication_commands;
 
 extern void InitWalSender(void);
 extern bool exec_replication_command(const char *query_string);
diff --git a/src/include/replication/walsender_private.h b/src/include/replication/walsender_private.h
index 9631047c6c..c14888e493 100644
--- a/src/include/replication/walsender_private.h
+++ b/src/include/replication/walsender_private.h
@@ -80,7 +80,7 @@ typedef struct WalSnd
 	TimestampTz replyTime;
 } WalSnd;
 
-extern WalSnd *MyWalSnd;
+extern PGDLLIMPORT WalSnd *MyWalSnd;
 
 /* There is one WalSndCtl struct for the whole database cluster */
 typedef struct
@@ -107,7 +107,7 @@ typedef struct
 	WalSnd		walsnds[FLEXIBLE_ARRAY_MEMBER];
 } WalSndCtlData;
 
-extern WalSndCtlData *WalSndCtl;
+extern PGDLLIMPORT WalSndCtlData *WalSndCtl;
 
 
 extern void WalSndSetState(WalSndState state);
@@ -123,6 +123,6 @@ extern void replication_scanner_init(const char *query_string);
 extern void replication_scanner_finish(void);
 extern bool replication_scanner_is_replication_command(void);
 
-extern Node *replication_parse_result;
+extern PGDLLIMPORT Node *replication_parse_result;
 
 #endif							/* _WALSENDER_PRIVATE_H */
diff --git a/src/include/replication/worker_internal.h b/src/include/replication/worker_internal.h
index 3c3f5f6a3a..4485d4ebee 100644
--- a/src/include/replication/worker_internal.h
+++ b/src/include/replication/worker_internal.h
@@ -69,16 +69,16 @@ typedef struct LogicalRepWorker
 } LogicalRepWorker;
 
 /* Main memory context for apply worker. Permanent during worker lifetime. */
-extern MemoryContext ApplyContext;
+extern PGDLLIMPORT MemoryContext ApplyContext;
 
 /* libpqreceiver connection */
-extern struct WalReceiverConn *LogRepWorkerWalRcvConn;
+extern PGDLLIMPORT struct WalReceiverConn *LogRepWorkerWalRcvConn;
 
 /* Worker and subscription objects. */
-extern Subscription *MySubscription;
-extern LogicalRepWorker *MyLogicalRepWorker;
+extern PGDLLIMPORT Subscription *MySubscription;
+extern PGDLLIMPORT LogicalRepWorker *MyLogicalRepWorker;
 
-extern bool in_remote_transaction;
+extern PGDLLIMPORT bool in_remote_transaction;
 
 extern void logicalrep_worker_attach(int slot);
 extern LogicalRepWorker *logicalrep_worker_find(Oid subid, Oid relid,
diff --git a/src/include/storage/buf_internals.h b/src/include/storage/buf_internals.h
index b903d2bcaf..a17e7b28a5 100644
--- a/src/include/storage/buf_internals.h
+++ b/src/include/storage/buf_internals.h
@@ -279,7 +279,7 @@ extern PGDLLIMPORT BufferDescPadded *BufferDescriptors;
 extern PGDLLIMPORT WritebackContext BackendWritebackContext;
 
 /* in localbuf.c */
-extern BufferDesc *LocalBufferDescriptors;
+extern PGDLLIMPORT BufferDesc *LocalBufferDescriptors;
 
 /* in bufmgr.c */
 
@@ -298,7 +298,7 @@ typedef struct CkptSortItem
 	int			buf_id;
 } CkptSortItem;
 
-extern CkptSortItem *CkptBufferIds;
+extern PGDLLIMPORT CkptSortItem *CkptBufferIds;
 
 /*
  * Internal buffer management routines
diff --git a/src/include/storage/bufmgr.h b/src/include/storage/bufmgr.h
index a6b657f0ba..58391406f6 100644
--- a/src/include/storage/bufmgr.h
+++ b/src/include/storage/bufmgr.h
@@ -65,16 +65,16 @@ struct SMgrRelationData;
 extern PGDLLIMPORT int NBuffers;
 
 /* in bufmgr.c */
-extern bool zero_damaged_pages;
-extern int	bgwriter_lru_maxpages;
-extern double bgwriter_lru_multiplier;
-extern bool track_io_timing;
-extern int	effective_io_concurrency;
-extern int	maintenance_io_concurrency;
-
-extern int	checkpoint_flush_after;
-extern int	backend_flush_after;
-extern int	bgwriter_flush_after;
+extern PGDLLIMPORT bool zero_damaged_pages;
+extern PGDLLIMPORT int bgwriter_lru_maxpages;
+extern PGDLLIMPORT double bgwriter_lru_multiplier;
+extern PGDLLIMPORT bool track_io_timing;
+extern PGDLLIMPORT int effective_io_concurrency;
+extern PGDLLIMPORT int maintenance_io_concurrency;
+
+extern PGDLLIMPORT int checkpoint_flush_after;
+extern PGDLLIMPORT int backend_flush_after;
+extern PGDLLIMPORT int bgwriter_flush_after;
 
 /* in buf_init.c */
 extern PGDLLIMPORT char *BufferBlocks;
diff --git a/src/include/storage/dsm_impl.h b/src/include/storage/dsm_impl.h
index f60b76f075..c51584dc6a 100644
--- a/src/include/storage/dsm_impl.h
+++ b/src/include/storage/dsm_impl.h
@@ -39,8 +39,8 @@
 #endif
 
 /* GUC. */
-extern int	dynamic_shared_memory_type;
-extern int	min_dynamic_shared_memory;
+extern PGDLLIMPORT int dynamic_shared_memory_type;
+extern PGDLLIMPORT int min_dynamic_shared_memory;
 
 /*
  * Directory for on-disk state.
diff --git a/src/include/storage/fd.h b/src/include/storage/fd.h
index 29209e2724..69549b000f 100644
--- a/src/include/storage/fd.h
+++ b/src/include/storage/fd.h
@@ -59,12 +59,12 @@ typedef int File;
 /* GUC parameter */
 extern PGDLLIMPORT int max_files_per_process;
 extern PGDLLIMPORT bool data_sync_retry;
-extern int	recovery_init_sync_method;
+extern PGDLLIMPORT int recovery_init_sync_method;
 
 /*
  * This is private to fd.c, but exported for save/restore_backend_variables()
  */
-extern int	max_safe_fds;
+extern PGDLLIMPORT int max_safe_fds;
 
 /*
  * On Windows, we have to interpret EACCES as possibly meaning the same as
diff --git a/src/include/storage/large_object.h b/src/include/storage/large_object.h
index 274b97fd42..b826a7dcd5 100644
--- a/src/include/storage/large_object.h
+++ b/src/include/storage/large_object.h
@@ -79,7 +79,7 @@ typedef struct LargeObjectDesc
 /*
  * GUC: backwards-compatibility flag to suppress LO permission checks
  */
-extern bool lo_compat_privileges;
+extern PGDLLIMPORT bool lo_compat_privileges;
 
 /*
  * Function definitions...
diff --git a/src/include/storage/lock.h b/src/include/storage/lock.h
index dc537e20f2..e4e1495b24 100644
--- a/src/include/storage/lock.h
+++ b/src/include/storage/lock.h
@@ -34,14 +34,14 @@ typedef struct PROC_QUEUE
 } PROC_QUEUE;
 
 /* GUC variables */
-extern int	max_locks_per_xact;
+extern PGDLLIMPORT int max_locks_per_xact;
 
 #ifdef LOCK_DEBUG
-extern int	Trace_lock_oidmin;
-extern bool Trace_locks;
-extern bool Trace_userlocks;
-extern int	Trace_lock_table;
-extern bool Debug_deadlocks;
+extern PGDLLIMPORT int Trace_lock_oidmin;
+extern PGDLLIMPORT bool Trace_locks;
+extern PGDLLIMPORT bool Trace_userlocks;
+extern PGDLLIMPORT int Trace_lock_table;
+extern PGDLLIMPORT bool Debug_deadlocks;
 #endif							/* LOCK_DEBUG */
 
 
@@ -154,7 +154,7 @@ typedef enum LockTagType
 
 #define LOCKTAG_LAST_TYPE	LOCKTAG_ADVISORY
 
-extern const char *const LockTagTypeNames[];
+extern PGDLLIMPORT const char *const LockTagTypeNames[];
 
 /*
  * The LOCKTAG struct is defined with malice aforethought to fit into 16
diff --git a/src/include/storage/lwlock.h b/src/include/storage/lwlock.h
index c3d5889d7b..cbd5e3ebce 100644
--- a/src/include/storage/lwlock.h
+++ b/src/include/storage/lwlock.h
@@ -110,7 +110,7 @@ typedef enum LWLockMode
 
 
 #ifdef LOCK_DEBUG
-extern bool Trace_lwlocks;
+extern PGDLLIMPORT bool Trace_lwlocks;
 #endif
 
 extern bool LWLockAcquire(LWLock *lock, LWLockMode mode);
diff --git a/src/include/storage/pg_shmem.h b/src/include/storage/pg_shmem.h
index 50e5c5f99b..da5962edb9 100644
--- a/src/include/storage/pg_shmem.h
+++ b/src/include/storage/pg_shmem.h
@@ -42,9 +42,9 @@ typedef struct PGShmemHeader	/* standard header for all Postgres shmem */
 } PGShmemHeader;
 
 /* GUC variables */
-extern int	shared_memory_type;
-extern int	huge_pages;
-extern int	huge_page_size;
+extern PGDLLIMPORT int shared_memory_type;
+extern PGDLLIMPORT int huge_pages;
+extern PGDLLIMPORT int huge_page_size;
 
 /* Possible values for huge_pages */
 typedef enum
@@ -63,12 +63,12 @@ typedef enum
 }			PGShmemType;
 
 #ifndef WIN32
-extern unsigned long UsedShmemSegID;
+extern PGDLLIMPORT unsigned long UsedShmemSegID;
 #else
-extern HANDLE UsedShmemSegID;
-extern void *ShmemProtectiveRegion;
+extern PGDLLIMPORT HANDLE UsedShmemSegID;
+extern PGDLLIMPORT void *ShmemProtectiveRegion;
 #endif
-extern void *UsedShmemSegAddr;
+extern PGDLLIMPORT void *UsedShmemSegAddr;
 
 #if !defined(WIN32) && !defined(EXEC_BACKEND)
 #define DEFAULT_SHARED_MEMORY_TYPE SHMEM_TYPE_MMAP
diff --git a/src/include/storage/pmsignal.h b/src/include/storage/pmsignal.h
index ea42c2072d..58f4ddf476 100644
--- a/src/include/storage/pmsignal.h
+++ b/src/include/storage/pmsignal.h
@@ -89,7 +89,7 @@ extern void PostmasterDeathSignalInit(void);
 #endif
 
 #ifdef USE_POSTMASTER_DEATH_SIGNAL
-extern volatile sig_atomic_t postmaster_possibly_dead;
+extern PGDLLIMPORT volatile sig_atomic_t postmaster_possibly_dead;
 
 static inline bool
 PostmasterIsAlive(void)
diff --git a/src/include/storage/predicate.h b/src/include/storage/predicate.h
index ba12904f22..8dfcb3944b 100644
--- a/src/include/storage/predicate.h
+++ b/src/include/storage/predicate.h
@@ -22,9 +22,9 @@
 /*
  * GUC variables
  */
-extern int	max_predicate_locks_per_xact;
-extern int	max_predicate_locks_per_relation;
-extern int	max_predicate_locks_per_page;
+extern PGDLLIMPORT int max_predicate_locks_per_xact;
+extern PGDLLIMPORT int max_predicate_locks_per_relation;
+extern PGDLLIMPORT int max_predicate_locks_per_page;
 
 
 /* Number of SLRU buffers to use for Serial SLRU */
diff --git a/src/include/storage/proc.h b/src/include/storage/proc.h
index 36ecf7d005..c02001d3a0 100644
--- a/src/include/storage/proc.h
+++ b/src/include/storage/proc.h
@@ -400,7 +400,7 @@ typedef struct PROC_HDR
 
 extern PGDLLIMPORT PROC_HDR *ProcGlobal;
 
-extern PGPROC *PreparedXactProcs;
+extern PGDLLIMPORT PGPROC *PreparedXactProcs;
 
 /* Accessor for PGPROC given a pgprocno. */
 #define GetPGProcByNumber(n) (&ProcGlobal->allProcs[(n)])
@@ -421,7 +421,7 @@ extern PGDLLIMPORT int StatementTimeout;
 extern PGDLLIMPORT int LockTimeout;
 extern PGDLLIMPORT int IdleInTransactionSessionTimeout;
 extern PGDLLIMPORT int IdleSessionTimeout;
-extern bool log_lock_waits;
+extern PGDLLIMPORT bool log_lock_waits;
 
 
 /*
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 8a5a905e38..dae912c073 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -1025,7 +1025,7 @@ extern int	tas(volatile slock_t *lock);		/* in port/.../tas.s, or
 #define TAS_SPIN(lock)	TAS(lock)
 #endif	 /* TAS_SPIN */
 
-extern slock_t dummy_spinlock;
+extern PGDLLIMPORT slock_t dummy_spinlock;
 
 /*
  * Platform-independent out-of-line support routines
diff --git a/src/include/storage/sinval.h b/src/include/storage/sinval.h
index 593a4211af..e7cd45658c 100644
--- a/src/include/storage/sinval.h
+++ b/src/include/storage/sinval.h
@@ -123,9 +123,9 @@ typedef union
 
 
 /* Counter of messages processed; don't worry about overflow. */
-extern uint64 SharedInvalidMessageCounter;
+extern PGDLLIMPORT uint64 SharedInvalidMessageCounter;
 
-extern volatile sig_atomic_t catchupInterruptPending;
+extern PGDLLIMPORT volatile sig_atomic_t catchupInterruptPending;
 
 extern void SendSharedInvalidMessages(const SharedInvalidationMessage *msgs,
 									  int n);
diff --git a/src/include/storage/spin.h b/src/include/storage/spin.h
index 70070ca9ab..7031f1d2c5 100644
--- a/src/include/storage/spin.h
+++ b/src/include/storage/spin.h
@@ -71,7 +71,7 @@ extern Size SpinlockSemaSize(void);
 
 #ifndef HAVE_SPINLOCKS
 extern void SpinlockSemaInit(void);
-extern PGSemaphore *SpinlockSemaArray;
+extern PGDLLIMPORT PGSemaphore *SpinlockSemaArray;
 #endif
 
 #endif							/* SPIN_H */
diff --git a/src/include/storage/standby.h b/src/include/storage/standby.h
index 58ea21aa13..6a7763264b 100644
--- a/src/include/storage/standby.h
+++ b/src/include/storage/standby.h
@@ -21,10 +21,10 @@
 #include "storage/standbydefs.h"
 
 /* User-settable GUC parameters */
-extern int	vacuum_defer_cleanup_age;
-extern int	max_standby_archive_delay;
-extern int	max_standby_streaming_delay;
-extern bool log_recovery_conflict_waits;
+extern PGDLLIMPORT int vacuum_defer_cleanup_age;
+extern PGDLLIMPORT int max_standby_archive_delay;
+extern PGDLLIMPORT int max_standby_streaming_delay;
+extern PGDLLIMPORT bool log_recovery_conflict_waits;
 
 extern void InitRecoveryTransactionEnvironment(void);
 extern void ShutdownRecoveryTransactionEnvironment(void);
diff --git a/src/include/tcop/tcopprot.h b/src/include/tcop/tcopprot.h
index 92291a750d..87e408b719 100644
--- a/src/include/tcop/tcopprot.h
+++ b/src/include/tcop/tcopprot.h
@@ -25,11 +25,11 @@
 /* Required daylight between max_stack_depth and the kernel limit, in bytes */
 #define STACK_DEPTH_SLOP (512 * 1024L)
 
-extern CommandDest whereToSendOutput;
+extern PGDLLIMPORT CommandDest whereToSendOutput;
 extern PGDLLIMPORT const char *debug_query_string;
-extern int	max_stack_depth;
-extern int	PostAuthDelay;
-extern int	client_connection_check_interval;
+extern PGDLLIMPORT int max_stack_depth;
+extern PGDLLIMPORT int PostAuthDelay;
+extern PGDLLIMPORT int client_connection_check_interval;
 
 /* GUC-configurable parameters */
 
diff --git a/src/include/tsearch/ts_cache.h b/src/include/tsearch/ts_cache.h
index 5e70d74b41..5e4a49ea1c 100644
--- a/src/include/tsearch/ts_cache.h
+++ b/src/include/tsearch/ts_cache.h
@@ -84,7 +84,7 @@ typedef struct
 /*
  * GUC variable for current configuration
  */
-extern char *TSCurrentConfig;
+extern PGDLLIMPORT char *TSCurrentConfig;
 
 
 extern TSParserCacheEntry *lookup_ts_parser_cache(Oid prsId);
diff --git a/src/include/tsearch/ts_type.h b/src/include/tsearch/ts_type.h
index 1a8bad8491..a2008f5504 100644
--- a/src/include/tsearch/ts_type.h
+++ b/src/include/tsearch/ts_type.h
@@ -169,7 +169,7 @@ typedef struct
 #define OP_PHRASE		4		/* highest code, tsquery_cleanup.c */
 #define OP_COUNT		4
 
-extern const int tsearch_op_priority[OP_COUNT];
+extern PGDLLIMPORT const int tsearch_op_priority[OP_COUNT];
 
 /* get operation priority  by its code*/
 #define OP_PRIORITY(x)	( tsearch_op_priority[(x) - 1] )
diff --git a/src/include/utils/array.h b/src/include/utils/array.h
index 2dba156d35..656c766a9a 100644
--- a/src/include/utils/array.h
+++ b/src/include/utils/array.h
@@ -339,7 +339,7 @@ typedef struct ArrayIteratorData *ArrayIterator;
 /*
  * GUC parameter
  */
-extern bool Array_nulls;
+extern PGDLLIMPORT bool Array_nulls;
 
 /*
  * prototypes for functions defined in arrayfuncs.c
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index 666e545496..221c3e6c3d 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -64,7 +64,7 @@ extern char *regexp_fixed_prefix(text *text_re, bool case_insensitive,
 								 Oid collation, bool *exact);
 
 /* ruleutils.c */
-extern bool quote_all_identifiers;
+extern PGDLLIMPORT bool quote_all_identifiers;
 extern const char *quote_identifier(const char *ident);
 extern char *quote_qualified_identifier(const char *qualifier,
 										const char *ident);
diff --git a/src/include/utils/bytea.h b/src/include/utils/bytea.h
index dfef8e2d52..c3c9e54707 100644
--- a/src/include/utils/bytea.h
+++ b/src/include/utils/bytea.h
@@ -22,6 +22,7 @@ typedef enum
 	BYTEA_OUTPUT_HEX
 }			ByteaOutputType;
 
-extern int	bytea_output;		/* ByteaOutputType, but int for GUC enum */
+extern PGDLLIMPORT int bytea_output;	/* ByteaOutputType, but int for GUC
+										 * enum */
 
 #endif							/* BYTEA_H */
diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h
index 0d158f3e4b..199724e5d3 100644
--- a/src/include/utils/datetime.h
+++ b/src/include/utils/datetime.h
@@ -257,9 +257,10 @@ do { \
  * Include check for leap year.
  */
 
-extern const char *const months[];	/* months (3-char abbreviations) */
-extern const char *const days[];	/* days (full names) */
-extern const int day_tab[2][13];
+extern PGDLLIMPORT const char *const months[];	/* months (3-char
+												 * abbreviations) */
+extern PGDLLIMPORT const char *const days[];	/* days (full names) */
+extern PGDLLIMPORT const int day_tab[2][13];
 
 /*
  * These are the rules for the Gregorian calendar, which was adopted in 1582.
diff --git a/src/include/utils/elog.h b/src/include/utils/elog.h
index 3eb8de3966..f5c6cd904d 100644
--- a/src/include/utils/elog.h
+++ b/src/include/utils/elog.h
@@ -424,12 +424,12 @@ typedef enum
 	PGERROR_VERBOSE				/* all the facts, ma'am */
 }			PGErrorVerbosity;
 
-extern int	Log_error_verbosity;
-extern char *Log_line_prefix;
-extern int	Log_destination;
-extern char *Log_destination_string;
-extern bool syslog_sequence_numbers;
-extern bool syslog_split_messages;
+extern PGDLLIMPORT int Log_error_verbosity;
+extern PGDLLIMPORT char *Log_line_prefix;
+extern PGDLLIMPORT int Log_destination;
+extern PGDLLIMPORT char *Log_destination_string;
+extern PGDLLIMPORT bool syslog_sequence_numbers;
+extern PGDLLIMPORT bool syslog_split_messages;
 
 /* Log destination bitmap */
 #define LOG_DESTINATION_STDERR	 1
diff --git a/src/include/utils/fmgrtab.h b/src/include/utils/fmgrtab.h
index e5f53d6295..0a59937656 100644
--- a/src/include/utils/fmgrtab.h
+++ b/src/include/utils/fmgrtab.h
@@ -32,17 +32,18 @@ typedef struct
 	PGFunction	func;			/* pointer to compiled function */
 } FmgrBuiltin;
 
-extern const FmgrBuiltin fmgr_builtins[];
+extern PGDLLIMPORT const FmgrBuiltin fmgr_builtins[];
 
-extern const int fmgr_nbuiltins;	/* number of entries in table */
+extern PGDLLIMPORT const int fmgr_nbuiltins;	/* number of entries in table */
 
-extern const Oid fmgr_last_builtin_oid; /* highest function OID in table */
+extern PGDLLIMPORT const Oid fmgr_last_builtin_oid; /* highest function OID in
+													 * table */
 
 /*
  * Mapping from a builtin function's OID to its index in the fmgr_builtins
  * array.  This is indexed from 0 through fmgr_last_builtin_oid.
  */
 #define InvalidOidBuiltinMapping PG_UINT16_MAX
-extern const uint16 fmgr_builtin_oid_index[];
+extern PGDLLIMPORT const uint16 fmgr_builtin_oid_index[];
 
 #endif							/* FMGRTAB_H */
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index ea774968f0..debdb4f5f1 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -239,53 +239,53 @@ typedef enum
 
 
 /* GUC vars that are actually declared in guc.c, rather than elsewhere */
-extern bool Debug_print_plan;
-extern bool Debug_print_parse;
-extern bool Debug_print_rewritten;
-extern bool Debug_pretty_print;
+extern PGDLLIMPORT bool Debug_print_plan;
+extern PGDLLIMPORT bool Debug_print_parse;
+extern PGDLLIMPORT bool Debug_print_rewritten;
+extern PGDLLIMPORT bool Debug_pretty_print;
 
-extern bool log_parser_stats;
-extern bool log_planner_stats;
-extern bool log_executor_stats;
-extern bool log_statement_stats;
-extern bool log_btree_build_stats;
+extern PGDLLIMPORT bool log_parser_stats;
+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 bool check_function_bodies;
-extern bool session_auth_is_superuser;
+extern PGDLLIMPORT bool session_auth_is_superuser;
 
-extern bool log_duration;
-extern int	log_parameter_max_length;
-extern int	log_parameter_max_length_on_error;
-extern int	log_min_error_statement;
+extern PGDLLIMPORT bool log_duration;
+extern PGDLLIMPORT int log_parameter_max_length;
+extern PGDLLIMPORT int log_parameter_max_length_on_error;
+extern PGDLLIMPORT int log_min_error_statement;
 extern PGDLLIMPORT int log_min_messages;
 extern PGDLLIMPORT int client_min_messages;
-extern int	log_min_duration_sample;
-extern int	log_min_duration_statement;
-extern int	log_temp_files;
-extern double log_statement_sample_rate;
-extern double log_xact_sample_rate;
-extern char *backtrace_functions;
-extern char *backtrace_symbol_list;
+extern PGDLLIMPORT int log_min_duration_sample;
+extern PGDLLIMPORT int log_min_duration_statement;
+extern PGDLLIMPORT int log_temp_files;
+extern PGDLLIMPORT double log_statement_sample_rate;
+extern PGDLLIMPORT double log_xact_sample_rate;
+extern PGDLLIMPORT char *backtrace_functions;
+extern PGDLLIMPORT char *backtrace_symbol_list;
 
-extern int	temp_file_limit;
+extern PGDLLIMPORT int temp_file_limit;
 
-extern int	num_temp_buffers;
+extern PGDLLIMPORT int num_temp_buffers;
 
 extern PGDLLIMPORT char *cluster_name;
 extern PGDLLIMPORT char *ConfigFileName;
-extern char *HbaFileName;
-extern char *IdentFileName;
-extern char *external_pid_file;
+extern PGDLLIMPORT char *HbaFileName;
+extern PGDLLIMPORT char *IdentFileName;
+extern PGDLLIMPORT char *external_pid_file;
 
 extern PGDLLIMPORT char *application_name;
 
-extern int	tcp_keepalives_idle;
-extern int	tcp_keepalives_interval;
-extern int	tcp_keepalives_count;
-extern int	tcp_user_timeout;
+extern PGDLLIMPORT int tcp_keepalives_idle;
+extern PGDLLIMPORT int tcp_keepalives_interval;
+extern PGDLLIMPORT int tcp_keepalives_count;
+extern PGDLLIMPORT int tcp_user_timeout;
 
 #ifdef TRACE_SORT
-extern bool trace_sort;
+extern PGDLLIMPORT bool trace_sort;
 #endif
 
 /*
diff --git a/src/include/utils/guc_tables.h b/src/include/utils/guc_tables.h
index f7e54a87b7..9a55d0241b 100644
--- a/src/include/utils/guc_tables.h
+++ b/src/include/utils/guc_tables.h
@@ -248,10 +248,10 @@ struct config_enum
 };
 
 /* constant tables corresponding to enums above and in guc.h */
-extern const char *const config_group_names[];
-extern const char *const config_type_names[];
-extern const char *const GucContext_Names[];
-extern const char *const GucSource_Names[];
+extern PGDLLIMPORT const char *const config_group_names[];
+extern PGDLLIMPORT const char *const config_type_names[];
+extern PGDLLIMPORT const char *const GucContext_Names[];
+extern PGDLLIMPORT const char *const GucSource_Names[];
 
 /* get the current set of variables */
 extern struct config_generic **get_guc_variables(void);
diff --git a/src/include/utils/pg_locale.h b/src/include/utils/pg_locale.h
index a44e17ffdf..e7385faef8 100644
--- a/src/include/utils/pg_locale.h
+++ b/src/include/utils/pg_locale.h
@@ -38,16 +38,16 @@
 #define LOCALE_NAME_BUFLEN 128
 
 /* GUC settings */
-extern char *locale_messages;
-extern char *locale_monetary;
-extern char *locale_numeric;
-extern char *locale_time;
+extern PGDLLIMPORT char *locale_messages;
+extern PGDLLIMPORT char *locale_monetary;
+extern PGDLLIMPORT char *locale_numeric;
+extern PGDLLIMPORT char *locale_time;
 
 /* lc_time localization cache */
-extern char *localized_abbrev_days[];
-extern char *localized_full_days[];
-extern char *localized_abbrev_months[];
-extern char *localized_full_months[];
+extern PGDLLIMPORT char *localized_abbrev_days[];
+extern PGDLLIMPORT char *localized_full_days[];
+extern PGDLLIMPORT char *localized_abbrev_months[];
+extern PGDLLIMPORT char *localized_full_months[];
 
 
 extern bool check_locale_messages(char **newval, void **extra, GucSource source);
@@ -103,7 +103,7 @@ struct pg_locale_struct
 
 typedef struct pg_locale_struct *pg_locale_t;
 
-extern struct pg_locale_struct default_locale;
+extern PGDLLIMPORT struct pg_locale_struct default_locale;
 
 extern void make_icu_collator(const char *iculocstr,
 							  struct pg_locale_struct *resultp);
diff --git a/src/include/utils/pgstat_internal.h b/src/include/utils/pgstat_internal.h
index abbb4f8d96..44f7de0baa 100644
--- a/src/include/utils/pgstat_internal.h
+++ b/src/include/utils/pgstat_internal.h
@@ -133,29 +133,29 @@ extern bool pgstat_wal_pending(void);
  * Variables in pgstat.c
  */
 
-extern pgsocket pgStatSock;
+extern PGDLLIMPORT pgsocket pgStatSock;
 
 
 /*
  * Variables in pgstat_database.c
  */
 
-extern int	pgStatXactCommit;
-extern int	pgStatXactRollback;
+extern PGDLLIMPORT int pgStatXactCommit;
+extern PGDLLIMPORT int pgStatXactRollback;
 
 
 /*
  * Variables in pgstat_functions.c
  */
 
-extern bool have_function_stats;
+extern PGDLLIMPORT bool have_function_stats;
 
 
 /*
  * Variables in pgstat_relation.c
  */
 
-extern bool have_relation_stats;
+extern PGDLLIMPORT bool have_relation_stats;
 
 
 #endif							/* PGSTAT_INTERNAL_H */
diff --git a/src/include/utils/plancache.h b/src/include/utils/plancache.h
index 95b99e3d25..0499635f59 100644
--- a/src/include/utils/plancache.h
+++ b/src/include/utils/plancache.h
@@ -35,7 +35,7 @@ typedef enum
 }			PlanCacheMode;
 
 /* GUC parameter */
-extern int	plan_cache_mode;
+extern PGDLLIMPORT int plan_cache_mode;
 
 #define CACHEDPLANSOURCE_MAGIC		195726186
 #define CACHEDPLAN_MAGIC			953717834
diff --git a/src/include/utils/ps_status.h b/src/include/utils/ps_status.h
index 9f43e1fdf0..bba463591f 100644
--- a/src/include/utils/ps_status.h
+++ b/src/include/utils/ps_status.h
@@ -12,7 +12,7 @@
 #ifndef PS_STATUS_H
 #define PS_STATUS_H
 
-extern bool update_process_title;
+extern PGDLLIMPORT bool update_process_title;
 
 extern char **save_ps_display_args(int argc, char **argv);
 
diff --git a/src/include/utils/queryjumble.h b/src/include/utils/queryjumble.h
index c670662db2..3c2d9beab2 100644
--- a/src/include/utils/queryjumble.h
+++ b/src/include/utils/queryjumble.h
@@ -62,14 +62,14 @@ enum ComputeQueryIdType
 };
 
 /* GUC parameters */
-extern int	compute_query_id;
+extern PGDLLIMPORT int compute_query_id;
 
 
 extern const char *CleanQuerytext(const char *query, int *location, int *len);
 extern JumbleState *JumbleQuery(Query *query, const char *querytext);
 extern void EnableQueryId(void);
 
-extern bool query_id_enabled;
+extern PGDLLIMPORT bool query_id_enabled;
 
 /*
  * Returns whether query identifier computation has been enabled, either
diff --git a/src/include/utils/relcache.h b/src/include/utils/relcache.h
index 2281a7dc53..86dddbd975 100644
--- a/src/include/utils/relcache.h
+++ b/src/include/utils/relcache.h
@@ -145,9 +145,9 @@ extern void RelationCacheInitFilePostInvalidate(void);
 extern void RelationCacheInitFileRemove(void);
 
 /* should be used only by relcache.c and catcache.c */
-extern bool criticalRelcachesBuilt;
+extern PGDLLIMPORT bool criticalRelcachesBuilt;
 
 /* should be used only by relcache.c and postinit.c */
-extern bool criticalSharedRelcachesBuilt;
+extern PGDLLIMPORT bool criticalSharedRelcachesBuilt;
 
 #endif							/* RELCACHE_H */
diff --git a/src/include/utils/rls.h b/src/include/utils/rls.h
index c1896d6735..75259cc1f7 100644
--- a/src/include/utils/rls.h
+++ b/src/include/utils/rls.h
@@ -14,7 +14,7 @@
 #define RLS_H
 
 /* GUC variable */
-extern bool row_security;
+extern PGDLLIMPORT bool row_security;
 
 /*
  * Used by callers of check_enable_rls.
diff --git a/src/include/utils/snapmgr.h b/src/include/utils/snapmgr.h
index e04018c034..67b217b1c1 100644
--- a/src/include/utils/snapmgr.h
+++ b/src/include/utils/snapmgr.h
@@ -53,7 +53,7 @@ extern TimestampTz GetSnapshotCurrentTimestamp(void);
 extern TimestampTz GetOldSnapshotThresholdTimestamp(void);
 extern void SnapshotTooOldMagicForTest(void);
 
-extern bool FirstSnapshotSet;
+extern PGDLLIMPORT bool FirstSnapshotSet;
 
 extern PGDLLIMPORT TransactionId TransactionXmin;
 extern PGDLLIMPORT TransactionId RecentXmin;
diff --git a/src/include/utils/timestamp.h b/src/include/utils/timestamp.h
index c1a74f8e2b..bd86c523c0 100644
--- a/src/include/utils/timestamp.h
+++ b/src/include/utils/timestamp.h
@@ -57,10 +57,10 @@
 
 
 /* Set at postmaster start */
-extern TimestampTz PgStartTime;
+extern PGDLLIMPORT TimestampTz PgStartTime;
 
 /* Set at configuration reload */
-extern TimestampTz PgReloadTime;
+extern PGDLLIMPORT TimestampTz PgReloadTime;
 
 
 /* Internal routines (not fmgr-callable) */
diff --git a/src/include/utils/xml.h b/src/include/utils/xml.h
index c1de08d15b..6620a62619 100644
--- a/src/include/utils/xml.h
+++ b/src/include/utils/xml.h
@@ -75,10 +75,10 @@ extern char *map_sql_identifier_to_xml_name(const char *ident, bool fully_escape
 extern char *map_xml_name_to_sql_identifier(const char *name);
 extern char *map_sql_value_to_xml_value(Datum value, Oid type, bool xml_escape_strings);
 
-extern int	xmlbinary;			/* XmlBinaryType, but int for guc enum */
+extern PGDLLIMPORT int xmlbinary;	/* XmlBinaryType, but int for guc enum */
 
-extern int	xmloption;			/* XmlOptionType, but int for guc enum */
+extern PGDLLIMPORT int xmloption;	/* XmlOptionType, but int for guc enum */
 
-extern const TableFuncRoutine XmlTableRoutine;
+extern PGDLLIMPORT const TableFuncRoutine XmlTableRoutine;
 
 #endif							/* XML_H */
-- 
2.24.3 (Apple Git-128)

