diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c
index daebd9d5e2bc34cb0f350a946a2fae8fd3fc6a86..c746c2319c3fff2c9be7d16840085ff9c8455aaf 100644
--- a/contrib/btree_gist/btree_ts.c
+++ b/contrib/btree_gist/btree_ts.c
@@ -154,7 +154,7 @@ ts_dist(PG_FUNCTION_ARGS)
 		p->day = INT_MAX;
 		p->month = INT_MAX;
 #ifdef HAVE_INT64_TIMESTAMP
-		p->time = INT64_MAX;
+		p->time = PG_INT64_MAX;
 #else
 		p->time = DBL_MAX;
 #endif
@@ -182,7 +182,7 @@ tstz_dist(PG_FUNCTION_ARGS)
 		p->day = INT_MAX;
 		p->month = INT_MAX;
 #ifdef HAVE_INT64_TIMESTAMP
-		p->time = INT64_MAX;
+		p->time = PG_INT64_MAX;
 #else
 		p->time = DBL_MAX;
 #endif
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 822adfd5817478ef6fa02e9b6e11cec7ef155171..321a6dbdc7f80f3c9cd46206869622d63ebed078 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -449,7 +449,7 @@ strtoint64(const char *str)
 		 */
 		if (strncmp(ptr, "9223372036854775808", 19) == 0)
 		{
-			result = INT64_MIN;
+			result = PG_INT64_MIN;
 			ptr += 19;
 			goto gotdigits;
 		}
@@ -3521,7 +3521,7 @@ threadRun(void *arg)
 		FD_ZERO(&input_mask);
 
 		maxsock = -1;
-		min_usec = INT64_MAX;
+		min_usec = PG_INT64_MAX;
 		for (i = 0; i < nstate; i++)
 		{
 			CState	   *st = &state[i];
@@ -3548,7 +3548,7 @@ threadRun(void *arg)
 				{
 					int			this_usec;
 
-					if (min_usec == INT64_MAX)
+					if (min_usec == PG_INT64_MAX)
 					{
 						instr_time	now;
 
@@ -3584,7 +3584,7 @@ threadRun(void *arg)
 		{
 			int			nsocks; /* return from select(2) */
 
-			if (min_usec != INT64_MAX)
+			if (min_usec != PG_INT64_MAX)
 			{
 				struct timeval timeout;
 
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 751253ba03c2c32359ee055703b4ab571dd59cf9..346a2b39f8585371e6700dfbf0ea65bb2c02f667 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -1408,7 +1408,7 @@ WALInsertLockAcquireExclusive(void)
 	{
 		LWLockAcquireWithVar(&WALInsertLocks[i].l.lock,
 							 &WALInsertLocks[i].l.insertingAt,
-							 UINT64_MAX);
+							 PG_UINT64_MAX);
 	}
 	LWLockAcquireWithVar(&WALInsertLocks[i].l.lock,
 						 &WALInsertLocks[i].l.insertingAt,
diff --git a/src/backend/tsearch/wparser_def.c b/src/backend/tsearch/wparser_def.c
index d95fdb1fabc049e7a82c52058edf23d9215dbe72..18ff9e2961c882b8d509a60ba05c8c09c89908cd 100644
--- a/src/backend/tsearch/wparser_def.c
+++ b/src/backend/tsearch/wparser_def.c
@@ -2260,7 +2260,7 @@ mark_hl_fragments(HeadlineParsedText *prs, TSQuery query, int highlight,
 	for (f = 0; f < max_fragments; f++)
 	{
 		maxitems = 0;
-		minwords = INT32_MAX;
+		minwords = PG_INT32_MAX;
 		minI = -1;
 
 		/*
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index b3a11918870cf4ec3bdb15a5233061c3cfcf5448..63a4fbb4a33b2dbfe60e0e7ece81754d9b608369 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -78,7 +78,7 @@ scanint8(const char *str, bool errorOK, int64 *result)
 		 */
 		if (strncmp(ptr, "9223372036854775808", 19) == 0)
 		{
-			tmp = INT64_MIN;
+			tmp = PG_INT64_MIN;
 			ptr += 19;
 			goto gotdigits;
 		}
diff --git a/src/backend/utils/adt/numutils.c b/src/backend/utils/adt/numutils.c
index 585da1e7322940c8b17a6d649a24405be77a1b4c..1dadbd597aea8686f3b659a58b3ccc49ef0619e7 100644
--- a/src/backend/utils/adt/numutils.c
+++ b/src/backend/utils/adt/numutils.c
@@ -190,7 +190,7 @@ pg_lltoa(int64 value, char *a)
 	 * Avoid problems with the most negative integer not being representable
 	 * as a positive integer.
 	 */
-	if (value == INT64_MIN)
+	if (value == PG_INT64_MIN)
 	{
 		memcpy(a, "-9223372036854775808", 21);
 		return;
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 33e859d35e1319ec83691c24d2e818548f8d9a01..86a014a2bbc58542d6f966929bdae7189ab38e34 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -3309,7 +3309,7 @@ interval_mul(PG_FUNCTION_ARGS)
 	result->day += (int32) month_remainder_days;
 #ifdef HAVE_INT64_TIMESTAMP
 	result_double = rint(span->time * factor + sec_remainder * USECS_PER_SEC);
-	if (result_double > INT64_MAX || result_double < INT64_MIN)
+	if (result_double > PG_INT64_MAX || result_double < PG_INT64_MIN)
 		ereport(ERROR,
 				(errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
 				 errmsg("interval out of range")));
diff --git a/src/backend/utils/adt/txid.c b/src/backend/utils/adt/txid.c
index 31f8033ae4846f8bd0149db8f0b81edb2c1969d9..1d7bb02ca466d68d151761b2af6e825e4d7d4856 100644
--- a/src/backend/utils/adt/txid.c
+++ b/src/backend/utils/adt/txid.c
@@ -34,7 +34,7 @@
 
 
 /* txid will be signed int8 in database, so must limit to 63 bits */
-#define MAX_TXID   ((uint64) INT64_MAX)
+#define MAX_TXID   ((uint64) PG_INT64_MAX)
 
 /* Use unsigned variant internally */
 typedef uint64 txid;
diff --git a/src/include/c.h b/src/include/c.h
index fd301b6da64697643a55bf2248eff2d92347092e..e63fd2f37d5d819381b250fa2d26bed6841a7923 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -249,36 +249,6 @@ typedef uint8 bits8;			/* >= 8 bits */
 typedef uint16 bits16;			/* >= 16 bits */
 typedef uint32 bits32;			/* >= 32 bits */
 
-/* should be defined in stdint.h, but we guarantee them here */
-#ifndef INT8_MIN
-#define INT8_MIN	(-0x7F-1)
-#endif
-#ifndef INT8_MAX
-#define INT8_MAX	(0x7F)
-#endif
-#ifndef INT16_MIN
-#define INT16_MIN	(-0x7FFF-1)
-#endif
-#ifndef INT16_MAX
-#define INT16_MAX	(0x7FFF)
-#endif
-#ifndef INT32_MIN
-#define INT32_MIN	(-0x7FFFFFFF-1)
-#endif
-#ifndef INT32_MAX
-#define INT32_MAX	(0x7FFFFFFF)
-#endif
-
-#ifndef UINT8_MAX
-#define UINT8_MAX	(0xFF)
-#endif
-#ifndef UINT16_MAX
-#define UINT16_MAX	(0xFFFF)
-#endif
-#ifndef UINT32_MAX
-#define UINT32_MAX	(0xFFFFFFFF)
-#endif
-
 /*
  * 64-bit integers
  */
@@ -314,26 +284,10 @@ typedef unsigned long long int uint64;
 #define UINT64CONST(x) ((uint64) x)
 #endif
 
-/* should be defined in stdint.h, but we guarantee them here */
-#ifndef INT64_MIN
-#define INT64_MIN	(-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
-#endif
-#ifndef INT64_MAX
-#define INT64_MAX	INT64CONST(0x7FFFFFFFFFFFFFFF)
-#endif
-#ifndef UINT64_MAX
-#define UINT64_MAX	UINT64CONST(0xFFFFFFFFFFFFFFFF)
-#endif
-
 /* snprintf format strings to use for 64-bit integers */
 #define INT64_FORMAT "%" INT64_MODIFIER "d"
 #define UINT64_FORMAT "%" INT64_MODIFIER "u"
 
-/* Select timestamp representation (float8 or int64) */
-#ifdef USE_INTEGER_DATETIMES
-#define HAVE_INT64_TIMESTAMP
-#endif
-
 /*
  * 128-bit signed and unsigned integers
  *		There currently is only a limited support for the type. E.g. 128bit
@@ -345,6 +299,28 @@ typedef PG_INT128_TYPE int128;
 typedef unsigned PG_INT128_TYPE uint128;
 #endif
 
+/*
+ * stdint.h limits aren't guaranteed to be present and aren't guaranteed to
+ * have compatible types with our fixed width types. So just define our own.
+ */
+#define PG_INT8_MIN		(-0x7F-1)
+#define PG_INT8_MAX		(0x7F)
+#define PG_UINT8_MAX	(0xFF)
+#define PG_INT16_MIN	(-0x7FFF-1)
+#define PG_INT16_MAX	(0x7FFF)
+#define PG_UINT16_MAX	(0xFFFF)
+#define PG_INT32_MIN	(-0x7FFFFFFF-1)
+#define PG_INT32_MAX	(0x7FFFFFFF)
+#define PG_UINT32_MAX	(0xFFFFFFFF)
+#define PG_INT64_MIN	(-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
+#define PG_INT64_MAX	INT64CONST(0x7FFFFFFFFFFFFFFF)
+#define PG_UINT64_MAX	UINT64CONST(0xFFFFFFFFFFFFFFFF)
+
+/* Select timestamp representation (float8 or int64) */
+#ifdef USE_INTEGER_DATETIMES
+#define HAVE_INT64_TIMESTAMP
+#endif
+
 /* sig_atomic_t is required by ANSI C, but may be missing on old platforms */
 #ifndef HAVE_SIG_ATOMIC_T
 typedef int sig_atomic_t;
diff --git a/src/include/datatype/timestamp.h b/src/include/datatype/timestamp.h
index d3450d69a8e41f2148ebbf1946f43ee61e5db633..e0e8e7c2f3de3745dcdb556b09831cabaf73e3a0 100644
--- a/src/include/datatype/timestamp.h
+++ b/src/include/datatype/timestamp.h
@@ -119,8 +119,8 @@ typedef struct
  * DT_NOBEGIN represents timestamp -infinity; DT_NOEND represents +infinity
  */
 #ifdef HAVE_INT64_TIMESTAMP
-#define DT_NOBEGIN		INT64_MIN
-#define DT_NOEND		INT64_MAX
+#define DT_NOBEGIN		PG_INT64_MIN
+#define DT_NOEND		PG_INT64_MAX
 #else							/* !HAVE_INT64_TIMESTAMP */
 #ifdef HUGE_VAL
 #define DT_NOBEGIN		(-HUGE_VAL)
diff --git a/src/include/executor/instrument.h b/src/include/executor/instrument.h
index db9d1e8ff05702629d2f793e2b6bfd57622fac50..c9a2129c7ae650f809c58c6e0d0518e3db648490 100644
--- a/src/include/executor/instrument.h
+++ b/src/include/executor/instrument.h
@@ -38,7 +38,7 @@ typedef enum InstrumentOption
 	INSTRUMENT_TIMER = 1 << 0,	/* needs timer (and row counts) */
 	INSTRUMENT_BUFFERS = 1 << 1,	/* needs buffer usage */
 	INSTRUMENT_ROWS = 1 << 2,	/* needs row count */
-	INSTRUMENT_ALL = INT32_MAX
+	INSTRUMENT_ALL = PG_INT32_MAX
 } InstrumentOption;
 
 typedef struct Instrumentation
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h
index 2893ceff18302f0e91e12889be35edd3094deba2..0e257ac46ce2104d2d410d6eb347609f5df51d78 100644
--- a/src/include/nodes/parsenodes.h
+++ b/src/include/nodes/parsenodes.h
@@ -587,7 +587,7 @@ typedef enum TableLikeOption
 	CREATE_TABLE_LIKE_INDEXES = 1 << 2,
 	CREATE_TABLE_LIKE_STORAGE = 1 << 3,
 	CREATE_TABLE_LIKE_COMMENTS = 1 << 4,
-	CREATE_TABLE_LIKE_ALL = INT32_MAX
+	CREATE_TABLE_LIKE_ALL = PG_INT32_MAX
 } TableLikeOption;
 
 /*
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h
index d3e9888b7b98455107bad58c927fd01473465b09..e278fa07d3d0d441d11972d6ba99428d8d488589 100644
--- a/src/include/pg_config_manual.h
+++ b/src/include/pg_config_manual.h
@@ -48,7 +48,7 @@
 /*
  * Set the upper and lower bounds of sequence values.
  */
-#define SEQ_MAXVALUE	INT64_MAX
+#define SEQ_MAXVALUE	PG_INT64_MAX
 #define SEQ_MINVALUE	(-SEQ_MAXVALUE)
 
 /*
@@ -185,7 +185,7 @@
  * the older rand() function, which is often different from --- and
  * considerably inferior to --- random().
  */
-#define MAX_RANDOM_VALUE  INT32_MAX
+#define MAX_RANDOM_VALUE  PG_INT32_MAX
 
 /*
  * On PPC machines, decide whether to use the mutex hint bit in LWARX
diff --git a/src/include/port/atomics.h b/src/include/port/atomics.h
index 99173644a43865cfb976b44e921844e6401a3cd0..e90d664d5a041b9bee99676ec7adfbe6cb71a753 100644
--- a/src/include/port/atomics.h
+++ b/src/include/port/atomics.h
@@ -489,7 +489,7 @@ STATIC_IF_INLINE uint64
 pg_atomic_fetch_sub_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
 {
 	AssertPointerAlignment(ptr, 8);
-	Assert(sub_ != INT64_MIN);
+	Assert(sub_ != PG_INT64_MIN);
 	return pg_atomic_fetch_sub_u64_impl(ptr, sub_);
 }
 
@@ -518,7 +518,7 @@ STATIC_IF_INLINE uint64
 pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
 {
 	AssertPointerAlignment(ptr, 8);
-	Assert(sub_ != INT64_MIN);
+	Assert(sub_ != PG_INT64_MIN);
 	return pg_atomic_sub_fetch_u64_impl(ptr, sub_);
 }
 
diff --git a/src/include/storage/predicate_internals.h b/src/include/storage/predicate_internals.h
index 8ecf923b1fb43ba12f37edcd55834786cf885f65..de1fc561a450153ee6527a1b9098e6a2d57ea92d 100644
--- a/src/include/storage/predicate_internals.h
+++ b/src/include/storage/predicate_internals.h
@@ -33,7 +33,7 @@ typedef uint64 SerCommitSeqNo;
  *	  at that point.  It's earlier than all normal sequence numbers,
  *	  and is only used by recovered prepared transactions
  */
-#define InvalidSerCommitSeqNo		((SerCommitSeqNo) UINT64_MAX)
+#define InvalidSerCommitSeqNo		((SerCommitSeqNo) PG_UINT64_MAX)
 #define RecoverySerCommitSeqNo		((SerCommitSeqNo) 1)
 #define FirstNormalSerCommitSeqNo	((SerCommitSeqNo) 2)
 
diff --git a/src/include/utils/date.h b/src/include/utils/date.h
index f07011c3851fad19198384cadeeaf74ce75795e4..c076fb846a81c813e722a52a504b7ec268f01fa8 100644
--- a/src/include/utils/date.h
+++ b/src/include/utils/date.h
@@ -36,8 +36,8 @@ typedef struct
 /*
  * Infinity and minus infinity must be the max and min values of DateADT.
  */
-#define DATEVAL_NOBEGIN		((DateADT) INT32_MIN)
-#define DATEVAL_NOEND		((DateADT) INT32_MAX)
+#define DATEVAL_NOBEGIN		((DateADT) PG_INT32_MIN)
+#define DATEVAL_NOEND		((DateADT) PG_INT32_MAX)
 
 #define DATE_NOBEGIN(j)		((j) = DATEVAL_NOBEGIN)
 #define DATE_IS_NOBEGIN(j)	((j) == DATEVAL_NOBEGIN)