From b8b2e3b2deeaab19715af063fc009b7c230b2336 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Mon, 25 Jun 2012 01:51:46 +0300
Subject: [PATCH] Replace int2/int4 in C code with int16/int32

The latter was already the dominant use, and it's preferable because
in C the convention is that intXX means XX bits.  Therefore, allowing
mixed use of int2, int4, int8, int16, int32 is obviously confusing.

Remove the typedefs for int2 and int4 for now.  They don't seem to be
widely used outside of the PostgreSQL source tree, and the few uses
can probably be cleaned up by the time this ships.
---
 contrib/btree_gist/btree_int2.c             | 10 +--
 contrib/btree_gist/btree_int4.c             | 10 +--
 contrib/cube/cube.c                         |  4 +-
 contrib/hstore/hstore.h                     |  4 +-
 contrib/hstore/hstore_gist.c                | 30 ++++----
 contrib/hstore/hstore_io.c                  | 32 ++++----
 contrib/intarray/_int.h                     | 18 ++---
 contrib/intarray/_int_bool.c                | 82 ++++++++++-----------
 contrib/intarray/_int_gin.c                 |  2 +-
 contrib/intarray/_int_gist.c                |  8 +-
 contrib/intarray/_int_tool.c                | 16 ++--
 contrib/intarray/_intbig_gist.c             | 32 ++++----
 contrib/ltree/_ltree_gist.c                 | 26 +++----
 contrib/ltree/ltree.h                       | 16 ++--
 contrib/ltree/ltree_gist.c                  | 12 +--
 contrib/ltree/ltree_op.c                    |  8 +-
 contrib/ltree/ltxtquery_io.c                | 74 +++++++++----------
 contrib/ltree/ltxtquery_op.c                |  4 +-
 contrib/pg_trgm/trgm_gist.c                 | 52 ++++++-------
 doc/src/sgml/xfunc.sgml                     | 13 +++-
 src/backend/access/hash/hashfunc.c          |  2 +-
 src/backend/access/spgist/spgquadtreeproc.c |  2 +-
 src/backend/catalog/Catalog.pm              |  2 +
 src/backend/catalog/namespace.c             |  2 +-
 src/backend/catalog/pg_type.c               |  2 +-
 src/backend/commands/cluster.c              |  4 +-
 src/backend/commands/trigger.c              | 18 ++---
 src/backend/optimizer/prep/prepunion.c      |  2 +-
 src/backend/parser/parse_utilcmd.c          |  2 +-
 src/backend/tsearch/to_tsany.c              | 14 ++--
 src/backend/tsearch/ts_parse.c              |  2 +-
 src/backend/tsearch/wparser_def.c           | 22 +++---
 src/backend/utils/adt/arrayfuncs.c          |  4 +-
 src/backend/utils/adt/int.c                 |  8 +-
 src/backend/utils/adt/ruleutils.c           |  6 +-
 src/backend/utils/adt/tsginidx.c            |  2 +-
 src/backend/utils/adt/tsgistidx.c           | 78 ++++++++++----------
 src/backend/utils/adt/tsquery.c             |  2 +-
 src/backend/utils/adt/tsquery_gist.c        |  8 +-
 src/backend/utils/adt/tsrank.c              | 12 +--
 src/backend/utils/adt/tsvector.c            |  2 +-
 src/backend/utils/adt/tsvector_op.c         | 10 +--
 src/include/access/gin_private.h            |  2 +-
 src/include/c.h                             |  4 +-
 src/include/catalog/namespace.h             |  2 +-
 src/include/catalog/pg_am.h                 |  4 +-
 src/include/catalog/pg_amop.h               |  2 +-
 src/include/catalog/pg_amproc.h             |  2 +-
 src/include/catalog/pg_attrdef.h            |  2 +-
 src/include/catalog/pg_attribute.h          | 14 ++--
 src/include/catalog/pg_authid.h             |  2 +-
 src/include/catalog/pg_class.h              |  8 +-
 src/include/catalog/pg_collation.h          |  2 +-
 src/include/catalog/pg_constraint.h         |  6 +-
 src/include/catalog/pg_conversion.h         |  4 +-
 src/include/catalog/pg_database.h           |  4 +-
 src/include/catalog/pg_depend.h             |  4 +-
 src/include/catalog/pg_description.h        |  2 +-
 src/include/catalog/pg_index.h              |  2 +-
 src/include/catalog/pg_inherits.h           |  2 +-
 src/include/catalog/pg_largeobject.h        |  2 +-
 src/include/catalog/pg_proc.h               |  4 +-
 src/include/catalog/pg_rewrite.h            |  2 +-
 src/include/catalog/pg_seclabel.h           |  2 +-
 src/include/catalog/pg_shdepend.h           |  2 +-
 src/include/catalog/pg_statistic.h          | 14 ++--
 src/include/catalog/pg_trigger.h            |  4 +-
 src/include/catalog/pg_ts_config_map.h      |  4 +-
 src/include/catalog/pg_type.h               |  6 +-
 src/include/commands/vacuum.h               |  6 +-
 src/include/tsearch/ts_public.h             | 10 +--
 src/include/tsearch/ts_type.h               |  6 +-
 src/include/tsearch/ts_utils.h              | 20 ++---
 src/include/utils/builtins.h                |  2 +-
 src/interfaces/ecpg/ecpglib/sqlda.c         |  4 +-
 75 files changed, 411 insertions(+), 404 deletions(-)

diff --git a/contrib/btree_gist/btree_int2.c b/contrib/btree_gist/btree_int2.c
index a40912b13d6..6a438bf1f22 100644
--- a/contrib/btree_gist/btree_int2.c
+++ b/contrib/btree_gist/btree_int2.c
@@ -77,7 +77,7 @@ gbt_int2key_cmp(const void *a, const void *b)
 static float8
 gbt_int2_dist(const void *a, const void *b)
 {
-	return GET_FLOAT_DISTANCE(int2, a, b);
+	return GET_FLOAT_DISTANCE(int16, a, b);
 }
 
 
@@ -100,10 +100,10 @@ Datum		int2_dist(PG_FUNCTION_ARGS);
 Datum
 int2_dist(PG_FUNCTION_ARGS)
 {
-	int2		a = PG_GETARG_INT16(0);
-	int2		b = PG_GETARG_INT16(1);
-	int2		r;
-	int2		ra;
+	int16		a = PG_GETARG_INT16(0);
+	int16		b = PG_GETARG_INT16(1);
+	int16		r;
+	int16		ra;
 
 	r = a - b;
 	ra = Abs(r);
diff --git a/contrib/btree_gist/btree_int4.c b/contrib/btree_gist/btree_int4.c
index 426f23f3fe0..df2164fc5eb 100644
--- a/contrib/btree_gist/btree_int4.c
+++ b/contrib/btree_gist/btree_int4.c
@@ -78,7 +78,7 @@ gbt_int4key_cmp(const void *a, const void *b)
 static float8
 gbt_int4_dist(const void *a, const void *b)
 {
-	return GET_FLOAT_DISTANCE(int4, a, b);
+	return GET_FLOAT_DISTANCE(int32, a, b);
 }
 
 
@@ -101,10 +101,10 @@ Datum		int4_dist(PG_FUNCTION_ARGS);
 Datum
 int4_dist(PG_FUNCTION_ARGS)
 {
-	int4		a = PG_GETARG_INT32(0);
-	int4		b = PG_GETARG_INT32(1);
-	int4		r;
-	int4		ra;
+	int32		a = PG_GETARG_INT32(0);
+	int32		b = PG_GETARG_INT32(1);
+	int32		r;
+	int32		ra;
 
 	r = a - b;
 	ra = Abs(r);
diff --git a/contrib/cube/cube.c b/contrib/cube/cube.c
index 1d119ddbb50..b591133ec70 100644
--- a/contrib/cube/cube.c
+++ b/contrib/cube/cube.c
@@ -266,7 +266,7 @@ cube_subset(PG_FUNCTION_ARGS)
 				(errcode(ERRCODE_ARRAY_ELEMENT_ERROR),
 				 errmsg("cannot work with arrays containing NULLs")));
 
-	dx = (int4 *) ARR_DATA_PTR(idx);
+	dx = (int32 *) ARR_DATA_PTR(idx);
 
 	dim = ARRNELEMS(idx);
 	size = offsetof(NDBOX, x[0]) +sizeof(double) * 2 * dim;
@@ -1360,7 +1360,7 @@ cube_enlarge(PG_FUNCTION_ARGS)
 {
 	NDBOX	   *a = PG_GETARG_NDBOX(0);
 	double		r = PG_GETARG_FLOAT8(1);
-	int4		n = PG_GETARG_INT32(2);
+	int32		n = PG_GETARG_INT32(2);
 	NDBOX	   *result;
 	int			dim = 0;
 	int			size;
diff --git a/contrib/hstore/hstore.h b/contrib/hstore/hstore.h
index 8906397ad23..23c8a6f0e28 100644
--- a/contrib/hstore/hstore.h
+++ b/contrib/hstore/hstore.h
@@ -159,8 +159,8 @@ typedef struct
 	bool		needfree;		/* need to pfree the value? */
 } Pairs;
 
-extern int	hstoreUniquePairs(Pairs *a, int4 l, int4 *buflen);
-extern HStore *hstorePairs(Pairs *pairs, int4 pcount, int4 buflen);
+extern int	hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen);
+extern HStore *hstorePairs(Pairs *pairs, int32 pcount, int32 buflen);
 
 extern size_t hstoreCheckKeyLen(size_t len);
 extern size_t hstoreCheckValLen(size_t len);
diff --git a/contrib/hstore/hstore_gist.c b/contrib/hstore/hstore_gist.c
index f5c4b71eaff..90011801424 100644
--- a/contrib/hstore/hstore_gist.c
+++ b/contrib/hstore/hstore_gist.c
@@ -40,7 +40,7 @@ typedef char *BITVECP;
 typedef struct
 {
 	int32		vl_len_;		/* varlena header (do not touch directly!) */
-	int4		flag;
+	int32		flag;
 	char		data[1];
 } GISTTYPE;
 
@@ -48,7 +48,7 @@ typedef struct
 
 #define ISALLTRUE(x)	( ((GISTTYPE*)x)->flag & ALLISTRUE )
 
-#define GTHDRSIZE		(VARHDRSZ + sizeof(int4))
+#define GTHDRSIZE		(VARHDRSZ + sizeof(int32))
 #define CALCGTSIZE(flag) ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) )
 
 #define GETSIGN(x)		( (BITVECP)( (char*)x+GTHDRSIZE ) )
@@ -143,7 +143,7 @@ ghstore_compress(PG_FUNCTION_ARGS)
 	}
 	else if (!ISALLTRUE(DatumGetPointer(entry->key)))
 	{
-		int4		i;
+		int32		i;
 		GISTTYPE   *res;
 		BITVECP		sign = GETSIGN(DatumGetPointer(entry->key));
 
@@ -192,7 +192,7 @@ ghstore_same(PG_FUNCTION_ARGS)
 		*result = false;
 	else
 	{
-		int4		i;
+		int32		i;
 		BITVECP		sa = GETSIGN(a),
 					sb = GETSIGN(b);
 
@@ -209,10 +209,10 @@ ghstore_same(PG_FUNCTION_ARGS)
 	PG_RETURN_POINTER(result);
 }
 
-static int4
+static int32
 sizebitvec(BITVECP sign)
 {
-	int4		size = 0,
+	int32		size = 0,
 				i;
 
 	LOOPBYTE
@@ -253,10 +253,10 @@ hemdist(GISTTYPE *a, GISTTYPE *b)
 	return hemdistsign(GETSIGN(a), GETSIGN(b));
 }
 
-static int4
+static int32
 unionkey(BITVECP sbase, GISTTYPE *add)
 {
-	int4		i;
+	int32		i;
 	BITVECP		sadd = GETSIGN(add);
 
 	if (ISALLTRUE(add))
@@ -270,12 +270,12 @@ Datum
 ghstore_union(PG_FUNCTION_ARGS)
 {
 	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
-	int4		len = entryvec->n;
+	int32		len = entryvec->n;
 
 	int		   *size = (int *) PG_GETARG_POINTER(1);
 	BITVEC		base;
-	int4		i;
-	int4		flag = 0;
+	int32		i;
+	int32		flag = 0;
 	GISTTYPE   *result;
 
 	MemSet((void *) base, 0, sizeof(BITVEC));
@@ -316,7 +316,7 @@ ghstore_penalty(PG_FUNCTION_ARGS)
 typedef struct
 {
 	OffsetNumber pos;
-	int4		cost;
+	int32		cost;
 } SPLITCOST;
 
 static int
@@ -339,11 +339,11 @@ ghstore_picksplit(PG_FUNCTION_ARGS)
 			   *datum_r;
 	BITVECP		union_l,
 				union_r;
-	int4		size_alpha,
+	int32		size_alpha,
 				size_beta;
-	int4		size_waste,
+	int32		size_waste,
 				waste = -1;
-	int4		nbytes;
+	int32		nbytes;
 	OffsetNumber seed_1 = 0,
 				seed_2 = 0;
 	OffsetNumber *left,
diff --git a/contrib/hstore/hstore_io.c b/contrib/hstore/hstore_io.c
index dde6c4b376e..aadf050410e 100644
--- a/contrib/hstore/hstore_io.c
+++ b/contrib/hstore/hstore_io.c
@@ -36,7 +36,7 @@ typedef struct
 do { \
 		if ( state->cur - state->word + 1 >= state->wordlen ) \
 		{ \
-				int4 clen = state->cur - state->word; \
+				int32 clen = state->cur - state->word; \
 				state->wordlen *= 2; \
 				state->word = (char*)repalloc( (void*)state->word, state->wordlen ); \
 				state->cur = state->word + clen; \
@@ -74,7 +74,7 @@ get_val(HSParser *state, bool ignoreeq, bool *escaped)
 			}
 			else if (*(state->ptr) == '=' && !ignoreeq)
 			{
-				elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int4) (state->ptr - state->begin));
+				elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int32) (state->ptr - state->begin));
 			}
 			else if (*(state->ptr) == '\\')
 			{
@@ -215,7 +215,7 @@ parse_hstore(HSParser *state)
 			}
 			else if (!isspace((unsigned char) *(state->ptr)))
 			{
-				elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int4) (state->ptr - state->begin));
+				elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int32) (state->ptr - state->begin));
 			}
 		}
 		else if (st == WGT)
@@ -230,7 +230,7 @@ parse_hstore(HSParser *state)
 			}
 			else
 			{
-				elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int4) (state->ptr - state->begin));
+				elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int32) (state->ptr - state->begin));
 			}
 		}
 		else if (st == WVAL)
@@ -263,7 +263,7 @@ parse_hstore(HSParser *state)
 			}
 			else if (!isspace((unsigned char) *(state->ptr)))
 			{
-				elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int4) (state->ptr - state->begin));
+				elog(ERROR, "Syntax error near '%c' at position %d", *(state->ptr), (int32) (state->ptr - state->begin));
 			}
 		}
 		else
@@ -304,7 +304,7 @@ comparePairs(const void *a, const void *b)
  * and (b) who knows whether they might be needed by some caller.
  */
 int
-hstoreUniquePairs(Pairs *a, int4 l, int4 *buflen)
+hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen)
 {
 	Pairs	   *ptr,
 			   *res;
@@ -367,14 +367,14 @@ hstoreCheckValLen(size_t len)
 
 
 HStore *
-hstorePairs(Pairs *pairs, int4 pcount, int4 buflen)
+hstorePairs(Pairs *pairs, int32 pcount, int32 buflen)
 {
 	HStore	   *out;
 	HEntry	   *entry;
 	char	   *ptr;
 	char	   *buf;
-	int4		len;
-	int4		i;
+	int32		len;
+	int32		i;
 
 	len = CALCDATASIZE(pcount, buflen);
 	out = palloc(len);
@@ -402,7 +402,7 @@ Datum
 hstore_in(PG_FUNCTION_ARGS)
 {
 	HSParser	state;
-	int4		buflen;
+	int32		buflen;
 	HStore	   *out;
 
 	state.begin = PG_GETARG_CSTRING(0);
@@ -422,11 +422,11 @@ Datum		hstore_recv(PG_FUNCTION_ARGS);
 Datum
 hstore_recv(PG_FUNCTION_ARGS)
 {
-	int4		buflen;
+	int32		buflen;
 	HStore	   *out;
 	Pairs	   *pairs;
-	int4		i;
-	int4		pcount;
+	int32		i;
+	int32		pcount;
 	StringInfo	buf = (StringInfo) PG_GETARG_POINTER(0);
 
 	pcount = pq_getmsgint(buf, 4);
@@ -518,7 +518,7 @@ Datum		hstore_from_arrays(PG_FUNCTION_ARGS);
 Datum
 hstore_from_arrays(PG_FUNCTION_ARGS)
 {
-	int4		buflen;
+	int32		buflen;
 	HStore	   *out;
 	Pairs	   *pairs;
 	Datum	   *key_datums;
@@ -632,7 +632,7 @@ hstore_from_array(PG_FUNCTION_ARGS)
 	ArrayType  *in_array = PG_GETARG_ARRAYTYPE_P(0);
 	int			ndims = ARR_NDIM(in_array);
 	int			count;
-	int4		buflen;
+	int32		buflen;
 	HStore	   *out;
 	Pairs	   *pairs;
 	Datum	   *in_datums;
@@ -737,7 +737,7 @@ Datum
 hstore_from_record(PG_FUNCTION_ARGS)
 {
 	HeapTupleHeader rec;
-	int4		buflen;
+	int32		buflen;
 	HStore	   *out;
 	Pairs	   *pairs;
 	Oid			tupType;
diff --git a/contrib/intarray/_int.h b/contrib/intarray/_int.h
index 11c069890ea..56aa23cfde0 100644
--- a/contrib/intarray/_int.h
+++ b/contrib/intarray/_int.h
@@ -10,7 +10,7 @@
 #define MAXNUMRANGE 100
 
 /* useful macros for accessing int4 arrays */
-#define ARRPTR(x)  ( (int4 *) ARR_DATA_PTR(x) )
+#define ARRPTR(x)  ( (int32 *) ARR_DATA_PTR(x) )
 #define ARRNELEMS(x)  ArrayGetNItems(ARR_NDIM(x), ARR_DIMS(x))
 
 /* reject arrays we can't handle; to wit, those containing nulls */
@@ -71,7 +71,7 @@ typedef char *BITVECP;
 typedef struct
 {
 	int32		vl_len_;		/* varlena header (do not touch directly!) */
-	int4		flag;
+	int32		flag;
 	char		data[1];
 } GISTTYPE;
 
@@ -79,7 +79,7 @@ typedef struct
 
 #define ISALLTRUE(x)	( ((GISTTYPE*)x)->flag & ALLISTRUE )
 
-#define GTHDRSIZE		(VARHDRSZ + sizeof(int4))
+#define GTHDRSIZE		(VARHDRSZ + sizeof(int32))
 #define CALCGTSIZE(flag) ( GTHDRSIZE+(((flag) & ALLISTRUE) ? 0 : SIGLEN) )
 
 #define GETSIGN(x)		( (BITVECP)( (char*)x+GTHDRSIZE ) )
@@ -93,7 +93,7 @@ typedef void (*formfloat) (ArrayType *, float *);
 /*
  * useful functions
  */
-bool		isort(int4 *a, int len);
+bool		isort(int32 *a, int len);
 ArrayType  *new_intArrayType(int num);
 ArrayType  *copy_intArrayType(ArrayType *a);
 ArrayType  *resize_intArrayType(ArrayType *a, int num);
@@ -123,15 +123,15 @@ void		gensign(BITVEC sign, int *a, int len);
  */
 typedef struct ITEM
 {
-	int2		type;
-	int2		left;
-	int4		val;
+	int16		type;
+	int16		left;
+	int32		val;
 } ITEM;
 
 typedef struct QUERYTYPE
 {
 	int32		vl_len_;		/* varlena header (do not touch directly!) */
-	int4		size;			/* number of ITEMs */
+	int32		size;			/* number of ITEMs */
 	ITEM		items[1];		/* variable length array */
 } QUERYTYPE;
 
@@ -167,7 +167,7 @@ int			compDESC(const void *a, const void *b);
 	do { \
 		int		_nelems_ = ARRNELEMS(a); \
 		if (_nelems_ > 1) \
-			qsort((void*) ARRPTR(a), _nelems_, sizeof(int4), \
+			qsort((void*) ARRPTR(a), _nelems_, sizeof(int32), \
 				  (direction) ? compASC : compDESC ); \
 	} while(0)
 
diff --git a/contrib/intarray/_int_bool.c b/contrib/intarray/_int_bool.c
index 4e63f6d66c1..dfb113a8ea5 100644
--- a/contrib/intarray/_int_bool.c
+++ b/contrib/intarray/_int_bool.c
@@ -34,27 +34,27 @@ Datum		querytree(PG_FUNCTION_ARGS);
  */
 typedef struct NODE
 {
-	int4		type;
-	int4		val;
+	int32		type;
+	int32		val;
 	struct NODE *next;
 } NODE;
 
 typedef struct
 {
 	char	   *buf;
-	int4		state;
-	int4		count;
+	int32		state;
+	int32		count;
 	/* reverse polish notation in list (for temporary usage) */
 	NODE	   *str;
 	/* number in str */
-	int4		num;
+	int32		num;
 } WORKSTATE;
 
 /*
  * get token from query string
  */
-static int4
-gettoken(WORKSTATE *state, int4 *val)
+static int32
+gettoken(WORKSTATE *state, int32 *val)
 {
 	char		nnn[16];
 	int			innn;
@@ -79,7 +79,7 @@ gettoken(WORKSTATE *state, int4 *val)
 				else if (*(state->buf) == '!')
 				{
 					(state->buf)++;
-					*val = (int4) '!';
+					*val = (int32) '!';
 					return OPR;
 				}
 				else if (*(state->buf) == '(')
@@ -103,7 +103,7 @@ gettoken(WORKSTATE *state, int4 *val)
 					nnn[innn] = '\0';
 					errno = 0;
 					lval = strtol(nnn, NULL, 0);
-					*val = (int4) lval;
+					*val = (int32) lval;
 					if (errno != 0 || (long) *val != lval)
 						return ERR;
 					state->state = WAITOPERATOR;
@@ -115,7 +115,7 @@ gettoken(WORKSTATE *state, int4 *val)
 				if (*(state->buf) == '&' || *(state->buf) == '|')
 				{
 					state->state = WAITOPERAND;
-					*val = (int4) *(state->buf);
+					*val = (int32) *(state->buf);
 					(state->buf)++;
 					return OPR;
 				}
@@ -143,7 +143,7 @@ gettoken(WORKSTATE *state, int4 *val)
  * push new one in polish notation reverse view
  */
 static void
-pushquery(WORKSTATE *state, int4 type, int4 val)
+pushquery(WORKSTATE *state, int32 type, int32 val)
 {
 	NODE	   *tmp = (NODE *) palloc(sizeof(NODE));
 
@@ -159,13 +159,13 @@ pushquery(WORKSTATE *state, int4 type, int4 val)
 /*
  * make polish notation of query
  */
-static int4
+static int32
 makepol(WORKSTATE *state)
 {
-	int4		val,
+	int32		val,
 				type;
-	int4		stack[STACKDEPTH];
-	int4		lenstack = 0;
+	int32		stack[STACKDEPTH];
+	int32		lenstack = 0;
 
 	/* since this function recurses, it could be driven to stack overflow */
 	check_stack_depth();
@@ -176,15 +176,15 @@ makepol(WORKSTATE *state)
 		{
 			case VAL:
 				pushquery(state, type, val);
-				while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
-									stack[lenstack - 1] == (int4) '!'))
+				while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
+									stack[lenstack - 1] == (int32) '!'))
 				{
 					lenstack--;
 					pushquery(state, OPR, stack[lenstack]);
 				}
 				break;
 			case OPR:
-				if (lenstack && val == (int4) '|')
+				if (lenstack && val == (int32) '|')
 					pushquery(state, OPR, val);
 				else
 				{
@@ -199,8 +199,8 @@ makepol(WORKSTATE *state)
 			case OPEN:
 				if (makepol(state) == ERR)
 					return ERR;
-				while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
-									stack[lenstack - 1] == (int4) '!'))
+				while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
+									stack[lenstack - 1] == (int32) '!'))
 				{
 					lenstack--;
 					pushquery(state, OPR, stack[lenstack]);
@@ -234,8 +234,8 @@ makepol(WORKSTATE *state)
 
 typedef struct
 {
-	int4	   *arrb;
-	int4	   *arre;
+	int32	   *arrb;
+	int32	   *arre;
 } CHKVAL;
 
 /*
@@ -244,9 +244,9 @@ typedef struct
 static bool
 checkcondition_arr(void *checkval, ITEM *item)
 {
-	int4	   *StopLow = ((CHKVAL *) checkval)->arrb;
-	int4	   *StopHigh = ((CHKVAL *) checkval)->arre;
-	int4	   *StopMiddle;
+	int32	   *StopLow = ((CHKVAL *) checkval)->arrb;
+	int32	   *StopHigh = ((CHKVAL *) checkval)->arre;
+	int32	   *StopMiddle;
 
 	/* Loop invariant: StopLow <= val < StopHigh */
 
@@ -281,13 +281,13 @@ execute(ITEM *curitem, void *checkval, bool calcnot,
 
 	if (curitem->type == VAL)
 		return (*chkcond) (checkval, curitem);
-	else if (curitem->val == (int4) '!')
+	else if (curitem->val == (int32) '!')
 	{
 		return (calcnot) ?
 			((execute(curitem - 1, checkval, calcnot, chkcond)) ? false : true)
 			: true;
 	}
-	else if (curitem->val == (int4) '&')
+	else if (curitem->val == (int32) '&')
 	{
 		if (execute(curitem + curitem->left, checkval, calcnot, chkcond))
 			return execute(curitem - 1, checkval, calcnot, chkcond);
@@ -379,7 +379,7 @@ contains_required_value(ITEM *curitem)
 
 	if (curitem->type == VAL)
 		return true;
-	else if (curitem->val == (int4) '!')
+	else if (curitem->val == (int32) '!')
 	{
 		/*
 		 * Assume anything under a NOT is non-required.  For some cases with
@@ -388,7 +388,7 @@ contains_required_value(ITEM *curitem)
 		 */
 		return false;
 	}
-	else if (curitem->val == (int4) '&')
+	else if (curitem->val == (int32) '&')
 	{
 		/* If either side has a required value, we're good */
 		if (contains_required_value(curitem + curitem->left))
@@ -449,7 +449,7 @@ boolop(PG_FUNCTION_ARGS)
 }
 
 static void
-findoprnd(ITEM *ptr, int4 *pos)
+findoprnd(ITEM *ptr, int32 *pos)
 {
 #ifdef BS_DEBUG
 	elog(DEBUG3, (ptr[*pos].type == OPR) ?
@@ -460,7 +460,7 @@ findoprnd(ITEM *ptr, int4 *pos)
 		ptr[*pos].left = 0;
 		(*pos)--;
 	}
-	else if (ptr[*pos].val == (int4) '!')
+	else if (ptr[*pos].val == (int32) '!')
 	{
 		ptr[*pos].left = -1;
 		(*pos)--;
@@ -469,7 +469,7 @@ findoprnd(ITEM *ptr, int4 *pos)
 	else
 	{
 		ITEM	   *curitem = &ptr[*pos];
-		int4		tmp = *pos;
+		int32		tmp = *pos;
 
 		(*pos)--;
 		findoprnd(ptr, pos);
@@ -487,12 +487,12 @@ bqarr_in(PG_FUNCTION_ARGS)
 {
 	char	   *buf = (char *) PG_GETARG_POINTER(0);
 	WORKSTATE	state;
-	int4		i;
+	int32		i;
 	QUERYTYPE  *query;
-	int4		commonlen;
+	int32		commonlen;
 	ITEM	   *ptr;
 	NODE	   *tmp;
-	int4		pos = 0;
+	int32		pos = 0;
 
 #ifdef BS_DEBUG
 	StringInfoData pbuf;
@@ -553,11 +553,11 @@ typedef struct
 	ITEM	   *curpol;
 	char	   *buf;
 	char	   *cur;
-	int4		buflen;
+	int32		buflen;
 } INFIX;
 
 #define RESIZEBUF(inf,addsize) while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) { \
-	int4 len = inf->cur - inf->buf; \
+	int32 len = inf->cur - inf->buf; \
 	inf->buflen *= 2; \
 	inf->buf = (char*) repalloc( (void*)inf->buf, inf->buflen ); \
 	inf->cur = inf->buf + len; \
@@ -573,7 +573,7 @@ infix(INFIX *in, bool first)
 		in->cur = strchr(in->cur, '\0');
 		in->curpol--;
 	}
-	else if (in->curpol->val == (int4) '!')
+	else if (in->curpol->val == (int32) '!')
 	{
 		bool		isopr = false;
 
@@ -599,11 +599,11 @@ infix(INFIX *in, bool first)
 	}
 	else
 	{
-		int4		op = in->curpol->val;
+		int32		op = in->curpol->val;
 		INFIX		nrm;
 
 		in->curpol--;
-		if (op == (int4) '|' && !first)
+		if (op == (int32) '|' && !first)
 		{
 			RESIZEBUF(in, 2);
 			sprintf(in->cur, "( ");
@@ -627,7 +627,7 @@ infix(INFIX *in, bool first)
 		in->cur = strchr(in->cur, '\0');
 		pfree(nrm.buf);
 
-		if (op == (int4) '|' && !first)
+		if (op == (int32) '|' && !first)
 		{
 			RESIZEBUF(in, 2);
 			sprintf(in->cur, " )");
diff --git a/contrib/intarray/_int_gin.c b/contrib/intarray/_int_gin.c
index 9abe54e55f9..be71e5ce696 100644
--- a/contrib/intarray/_int_gin.c
+++ b/contrib/intarray/_int_gin.c
@@ -65,7 +65,7 @@ ginint4_queryextract(PG_FUNCTION_ARGS)
 		*nentries = ARRNELEMS(query);
 		if (*nentries > 0)
 		{
-			int4	   *arr;
+			int32	   *arr;
 			int32		i;
 
 			res = (Datum *) palloc(sizeof(Datum) * (*nentries));
diff --git a/contrib/intarray/_int_gist.c b/contrib/intarray/_int_gist.c
index 0123906be88..e429c8b58c9 100644
--- a/contrib/intarray/_int_gist.c
+++ b/contrib/intarray/_int_gist.c
@@ -106,7 +106,7 @@ g_int_union(PG_FUNCTION_ARGS)
 {
 	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 	int		   *size = (int *) PG_GETARG_POINTER(1);
-	int4		i,
+	int32		i,
 			   *ptr;
 	ArrayType  *res;
 	int			totlen = 0;
@@ -128,7 +128,7 @@ g_int_union(PG_FUNCTION_ARGS)
 		int			nel;
 
 		nel = ARRNELEMS(ent);
-		memcpy(ptr, ARRPTR(ent), nel * sizeof(int4));
+		memcpy(ptr, ARRPTR(ent), nel * sizeof(int32));
 		ptr += nel;
 	}
 
@@ -317,8 +317,8 @@ g_int_same(PG_FUNCTION_ARGS)
 	ArrayType  *a = PG_GETARG_ARRAYTYPE_P(0);
 	ArrayType  *b = PG_GETARG_ARRAYTYPE_P(1);
 	bool	   *result = (bool *) PG_GETARG_POINTER(2);
-	int4		n = ARRNELEMS(a);
-	int4	   *da,
+	int32		n = ARRNELEMS(a);
+	int32	   *da,
 			   *db;
 
 	CHECKARRVALID(a);
diff --git a/contrib/intarray/_int_tool.c b/contrib/intarray/_int_tool.c
index 132d1531605..863557672ee 100644
--- a/contrib/intarray/_int_tool.c
+++ b/contrib/intarray/_int_tool.c
@@ -186,11 +186,11 @@ rt__int_size(ArrayType *a, float *size)
 
 /* Sort the given data (len >= 2).	Return true if any duplicates found */
 bool
-isort(int4 *a, int len)
+isort(int32 *a, int len)
 {
-	int4		cur,
+	int32		cur,
 				prev;
-	int4	   *pcur,
+	int32	   *pcur,
 			   *pprev,
 			   *end;
 	bool		r = FALSE;
@@ -268,7 +268,7 @@ copy_intArrayType(ArrayType *a)
 	int			n = ARRNELEMS(a);
 
 	r = new_intArrayType(n);
-	memcpy(ARRPTR(r), ARRPTR(a), n * sizeof(int4));
+	memcpy(ARRPTR(r), ARRPTR(a), n * sizeof(int32));
 	return r;
 }
 
@@ -389,15 +389,15 @@ int_to_intset(int32 n)
 int
 compASC(const void *a, const void *b)
 {
-	if (*(const int4 *) a == *(const int4 *) b)
+	if (*(const int32 *) a == *(const int32 *) b)
 		return 0;
-	return (*(const int4 *) a > *(const int4 *) b) ? 1 : -1;
+	return (*(const int32 *) a > *(const int32 *) b) ? 1 : -1;
 }
 
 int
 compDESC(const void *a, const void *b)
 {
-	if (*(const int4 *) a == *(const int4 *) b)
+	if (*(const int32 *) a == *(const int32 *) b)
 		return 0;
-	return (*(const int4 *) a < *(const int4 *) b) ? 1 : -1;
+	return (*(const int32 *) a < *(const int32 *) b) ? 1 : -1;
 }
diff --git a/contrib/intarray/_intbig_gist.c b/contrib/intarray/_intbig_gist.c
index c6b00eaeff0..1bad024c099 100644
--- a/contrib/intarray/_intbig_gist.c
+++ b/contrib/intarray/_intbig_gist.c
@@ -81,7 +81,7 @@ static bool
 _intbig_overlap(GISTTYPE *a, ArrayType *b)
 {
 	int			num = ARRNELEMS(b);
-	int4	   *ptr = ARRPTR(b);
+	int32	   *ptr = ARRPTR(b);
 
 	CHECKARRVALID(b);
 
@@ -99,7 +99,7 @@ static bool
 _intbig_contains(GISTTYPE *a, ArrayType *b)
 {
 	int			num = ARRNELEMS(b);
-	int4	   *ptr = ARRPTR(b);
+	int32	   *ptr = ARRPTR(b);
 
 	CHECKARRVALID(b);
 
@@ -128,7 +128,7 @@ g_intbig_same(PG_FUNCTION_ARGS)
 		*result = false;
 	else
 	{
-		int4		i;
+		int32		i;
 		BITVECP		sa = GETSIGN(a),
 					sb = GETSIGN(b);
 
@@ -154,7 +154,7 @@ g_intbig_compress(PG_FUNCTION_ARGS)
 	{
 		GISTENTRY  *retval;
 		ArrayType  *in = DatumGetArrayTypeP(entry->key);
-		int4	   *ptr;
+		int32	   *ptr;
 		int			num;
 		GISTTYPE   *res = (GISTTYPE *) palloc0(CALCGTSIZE(0));
 
@@ -216,10 +216,10 @@ g_intbig_compress(PG_FUNCTION_ARGS)
 }
 
 
-static int4
+static int32
 sizebitvec(BITVECP sign)
 {
-	int4		size = 0,
+	int32		size = 0,
 				i;
 
 	LOOPBYTE
@@ -264,10 +264,10 @@ g_intbig_decompress(PG_FUNCTION_ARGS)
 	PG_RETURN_DATUM(PG_GETARG_DATUM(0));
 }
 
-static int4
+static int32
 unionkey(BITVECP sbase, GISTTYPE *add)
 {
-	int4		i;
+	int32		i;
 	BITVECP		sadd = GETSIGN(add);
 
 	if (ISALLTRUE(add))
@@ -283,9 +283,9 @@ g_intbig_union(PG_FUNCTION_ARGS)
 	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 	int		   *size = (int *) PG_GETARG_POINTER(1);
 	BITVEC		base;
-	int4		i,
+	int32		i,
 				len;
-	int4		flag = 0;
+	int32		flag = 0;
 	GISTTYPE   *result;
 
 	MemSet((void *) base, 0, sizeof(BITVEC));
@@ -326,7 +326,7 @@ g_intbig_penalty(PG_FUNCTION_ARGS)
 typedef struct
 {
 	OffsetNumber pos;
-	int4		cost;
+	int32		cost;
 } SPLITCOST;
 
 static int
@@ -347,11 +347,11 @@ g_intbig_picksplit(PG_FUNCTION_ARGS)
 			   *datum_r;
 	BITVECP		union_l,
 				union_r;
-	int4		size_alpha,
+	int32		size_alpha,
 				size_beta;
-	int4		size_waste,
+	int32		size_waste,
 				waste = -1;
-	int4		nbytes;
+	int32		nbytes;
 	OffsetNumber seed_1 = 0,
 				seed_2 = 0;
 	OffsetNumber *left,
@@ -538,7 +538,7 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
 			{
 				int			i,
 							num = ARRNELEMS(query);
-				int4	   *ptr = ARRPTR(query);
+				int32	   *ptr = ARRPTR(query);
 				BITVEC		qp;
 				BITVECP		dq,
 							de;
@@ -577,7 +577,7 @@ g_intbig_consistent(PG_FUNCTION_ARGS)
 			{
 				int			i,
 							num = ARRNELEMS(query);
-				int4	   *ptr = ARRPTR(query);
+				int32	   *ptr = ARRPTR(query);
 				BITVEC		qp;
 				BITVECP		dq,
 							de;
diff --git a/contrib/ltree/_ltree_gist.c b/contrib/ltree/_ltree_gist.c
index 8afc2bd5407..93507158c02 100644
--- a/contrib/ltree/_ltree_gist.c
+++ b/contrib/ltree/_ltree_gist.c
@@ -83,7 +83,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
 	{							/* ltree */
 		ltree_gist *key;
 		ArrayType  *val = DatumGetArrayTypeP(entry->key);
-		int4		len = LTG_HDRSIZE + ASIGLEN;
+		int32		len = LTG_HDRSIZE + ASIGLEN;
 		int			num = ArrayGetNItems(ARR_NDIM(val), ARR_DIMS(val));
 		ltree	   *item = (ltree *) ARR_DATA_PTR(val);
 
@@ -115,7 +115,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
 	}
 	else if (!LTG_ISALLTRUE(entry->key))
 	{
-		int4		i,
+		int32		i,
 					len;
 		ltree_gist *key;
 
@@ -154,7 +154,7 @@ _ltree_same(PG_FUNCTION_ARGS)
 		*result = false;
 	else
 	{
-		int4		i;
+		int32		i;
 		BITVECP		sa = LTG_SIGN(a),
 					sb = LTG_SIGN(b);
 
@@ -171,10 +171,10 @@ _ltree_same(PG_FUNCTION_ARGS)
 	PG_RETURN_POINTER(result);
 }
 
-static int4
+static int32
 unionkey(BITVECP sbase, ltree_gist *add)
 {
-	int4		i;
+	int32		i;
 	BITVECP		sadd = LTG_SIGN(add);
 
 	if (LTG_ISALLTRUE(add))
@@ -191,9 +191,9 @@ _ltree_union(PG_FUNCTION_ARGS)
 	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 	int		   *size = (int *) PG_GETARG_POINTER(1);
 	ABITVEC		base;
-	int4		i,
+	int32		i,
 				len;
-	int4		flag = 0;
+	int32		flag = 0;
 	ltree_gist *result;
 
 	MemSet((void *) base, 0, sizeof(ABITVEC));
@@ -217,10 +217,10 @@ _ltree_union(PG_FUNCTION_ARGS)
 	PG_RETURN_POINTER(result);
 }
 
-static int4
+static int32
 sizebitvec(BITVECP sign)
 {
-	int4		size = 0,
+	int32		size = 0,
 				i;
 
 	ALOOPBYTE
@@ -274,7 +274,7 @@ _ltree_penalty(PG_FUNCTION_ARGS)
 typedef struct
 {
 	OffsetNumber pos;
-	int4		cost;
+	int32		cost;
 } SPLITCOST;
 
 static int
@@ -294,11 +294,11 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
 			   *datum_r;
 	BITVECP		union_l,
 				union_r;
-	int4		size_alpha,
+	int32		size_alpha,
 				size_beta;
-	int4		size_waste,
+	int32		size_waste,
 				waste = -1;
-	int4		nbytes;
+	int32		nbytes;
 	OffsetNumber seed_1 = 0,
 				seed_2 = 0;
 	OffsetNumber *left,
diff --git a/contrib/ltree/ltree.h b/contrib/ltree/ltree.h
index aec445847f9..563970a67a4 100644
--- a/contrib/ltree/ltree.h
+++ b/contrib/ltree/ltree.h
@@ -30,7 +30,7 @@ typedef struct
 
 typedef struct
 {
-	int4		val;
+	int32		val;
 	uint16		len;
 	uint8		flag;
 	char		name[1];
@@ -89,9 +89,9 @@ typedef struct
  */
 typedef struct ITEM
 {
-	int2		type;
-	int2		left;
-	int4		val;
+	int16		type;
+	int16		left;
+	int32		val;
 	uint8		flag;
 	/* user-friendly value */
 	uint8		length;
@@ -105,11 +105,11 @@ typedef struct ITEM
 typedef struct
 {
 	int32		vl_len_;		/* varlena header (do not touch directly!) */
-	int4		size;
+	int32		size;
 	char		data[1];
 } ltxtquery;
 
-#define HDRSIZEQT		MAXALIGN(VARHDRSZ + sizeof(int4))
+#define HDRSIZEQT		MAXALIGN(VARHDRSZ + sizeof(int32))
 #define COMPUTESIZE(size,lenofoperand)	( HDRSIZEQT + (size) * sizeof(ITEM) + (lenofoperand) )
 #define GETQUERY(x)  (ITEM*)( (char*)(x)+HDRSIZEQT )
 #define GETOPERAND(x)	( (char*)GETQUERY(x) + ((ltxtquery*)x)->size * sizeof(ITEM) )
@@ -173,7 +173,7 @@ int			ltree_strncasecmp(const char *a, const char *b, size_t s);
 
 #define BITBYTE 8
 #define SIGLENINT  2
-#define SIGLEN	( sizeof(int4)*SIGLENINT )
+#define SIGLEN	( sizeof(int32)*SIGLENINT )
 #define SIGLENBIT (SIGLEN*BITBYTE)
 typedef unsigned char BITVEC[SIGLEN];
 typedef unsigned char *BITVECP;
@@ -229,7 +229,7 @@ typedef struct
 /* GiST support for ltree[] */
 
 #define ASIGLENINT	(7)
-#define ASIGLEN		(sizeof(int4)*ASIGLENINT)
+#define ASIGLEN		(sizeof(int32)*ASIGLENINT)
 #define ASIGLENBIT (ASIGLEN*BITBYTE)
 typedef unsigned char ABITVEC[ASIGLEN];
 
diff --git a/contrib/ltree/ltree_gist.c b/contrib/ltree/ltree_gist.c
index 13d96656d2e..5324c65f59e 100644
--- a/contrib/ltree/ltree_gist.c
+++ b/contrib/ltree/ltree_gist.c
@@ -70,7 +70,7 @@ ltree_compress(PG_FUNCTION_ARGS)
 	{							/* ltree */
 		ltree_gist *key;
 		ltree	   *val = (ltree *) DatumGetPointer(PG_DETOAST_DATUM(entry->key));
-		int4		len = LTG_HDRSIZE + VARSIZE(val);
+		int32		len = LTG_HDRSIZE + VARSIZE(val);
 
 		key = (ltree_gist *) palloc(len);
 		SET_VARSIZE(key, len);
@@ -118,7 +118,7 @@ ltree_same(PG_FUNCTION_ARGS)
 		*result = (ISEQ(LTG_NODE(a), LTG_NODE(b))) ? true : false;
 	else
 	{
-		int4		i;
+		int32		i;
 		BITVECP		sa = LTG_SIGN(a),
 					sb = LTG_SIGN(b);
 
@@ -169,7 +169,7 @@ ltree_union(PG_FUNCTION_ARGS)
 	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 	int		   *size = (int *) PG_GETARG_POINTER(1);
 	BITVEC		base;
-	int4		i,
+	int32		i,
 				j;
 	ltree_gist *result,
 			   *cur;
@@ -253,7 +253,7 @@ ltree_penalty(PG_FUNCTION_ARGS)
 	ltree_gist *origval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(0))->key);
 	ltree_gist *newval = (ltree_gist *) DatumGetPointer(((GISTENTRY *) PG_GETARG_POINTER(1))->key);
 	float	   *penalty = (float *) PG_GETARG_POINTER(2);
-	int4		cmpr,
+	int32		cmpr,
 				cmpl;
 
 	cmpl = ltree_compare(LTG_GETLNODE(origval), LTG_GETLNODE(newval));
@@ -287,7 +287,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
 	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 	GIST_SPLITVEC *v = (GIST_SPLITVEC *) PG_GETARG_POINTER(1);
 	OffsetNumber j;
-	int4		i;
+	int32		i;
 	RIX		   *array;
 	OffsetNumber maxoff;
 	int			nbytes;
@@ -441,7 +441,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
 static bool
 gist_isparent(ltree_gist *key, ltree *query)
 {
-	int4		numlevel = query->numlevel;
+	int32		numlevel = query->numlevel;
 	int			i;
 
 	for (i = query->numlevel; i >= 0; i--)
diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c
index 4290ad4e63b..4d8fb842c14 100644
--- a/contrib/ltree/ltree_op.c
+++ b/contrib/ltree/ltree_op.c
@@ -200,7 +200,7 @@ ltree_risparent(PG_FUNCTION_ARGS)
 
 
 static ltree *
-inner_subltree(ltree *t, int4 startpos, int4 endpos)
+inner_subltree(ltree *t, int32 startpos, int32 endpos)
 {
 	char	   *start = NULL,
 			   *end = NULL;
@@ -252,9 +252,9 @@ Datum
 subpath(PG_FUNCTION_ARGS)
 {
 	ltree	   *t = PG_GETARG_LTREE(0);
-	int4		start = PG_GETARG_INT32(1);
-	int4		len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
-	int4		end;
+	int32		start = PG_GETARG_INT32(1);
+	int32		len = (fcinfo->nargs == 3) ? PG_GETARG_INT32(2) : 0;
+	int32		end;
 	ltree	   *res;
 
 	end = start + len;
diff --git a/contrib/ltree/ltxtquery_io.c b/contrib/ltree/ltxtquery_io.c
index 826f4e1c9dd..c2e532c3b81 100644
--- a/contrib/ltree/ltxtquery_io.c
+++ b/contrib/ltree/ltxtquery_io.c
@@ -28,10 +28,10 @@ Datum		ltxtq_out(PG_FUNCTION_ARGS);
  */
 typedef struct NODE
 {
-	int4		type;
-	int4		val;
-	int2		distance;
-	int2		length;
+	int32		type;
+	int32		val;
+	int16		distance;
+	int16		length;
 	uint16		flag;
 	struct NODE *next;
 } NODE;
@@ -39,16 +39,16 @@ typedef struct NODE
 typedef struct
 {
 	char	   *buf;
-	int4		state;
-	int4		count;
+	int32		state;
+	int32		count;
 	/* reverse polish notation in list (for temporary usage) */
 	NODE	   *str;
 	/* number in str */
-	int4		num;
+	int32		num;
 
 	/* user-friendly operand */
-	int4		lenop;
-	int4		sumlen;
+	int32		lenop;
+	int32		sumlen;
 	char	   *op;
 	char	   *curop;
 } QPRS_STATE;
@@ -56,8 +56,8 @@ typedef struct
 /*
  * get token from query string
  */
-static int4
-gettoken_query(QPRS_STATE *state, int4 *val, int4 *lenval, char **strval, uint16 *flag)
+static int32
+gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint16 *flag)
 {
 	int			charlen;
 
@@ -71,7 +71,7 @@ gettoken_query(QPRS_STATE *state, int4 *val, int4 *lenval, char **strval, uint16
 				if (charlen == 1 && t_iseq(state->buf, '!'))
 				{
 					(state->buf)++;
-					*val = (int4) '!';
+					*val = (int32) '!';
 					return OPR;
 				}
 				else if (charlen == 1 && t_iseq(state->buf, '('))
@@ -117,7 +117,7 @@ gettoken_query(QPRS_STATE *state, int4 *val, int4 *lenval, char **strval, uint16
 				if (charlen == 1 && (t_iseq(state->buf, '&') || t_iseq(state->buf, '|')))
 				{
 					state->state = WAITOPERAND;
-					*val = (int4) *(state->buf);
+					*val = (int32) *(state->buf);
 					(state->buf)++;
 					return OPR;
 				}
@@ -146,7 +146,7 @@ gettoken_query(QPRS_STATE *state, int4 *val, int4 *lenval, char **strval, uint16
  * push new one in polish notation reverse view
  */
 static void
-pushquery(QPRS_STATE *state, int4 type, int4 val, int4 distance, int4 lenval, uint16 flag)
+pushquery(QPRS_STATE *state, int32 type, int32 val, int32 distance, int32 lenval, uint16 flag)
 {
 	NODE	   *tmp = (NODE *) palloc(sizeof(NODE));
 
@@ -184,7 +184,7 @@ pushval_asis(QPRS_STATE *state, int type, char *strval, int lenval, uint16 flag)
 
 	while (state->curop - state->op + lenval + 1 >= state->lenop)
 	{
-		int4		tmp = state->curop - state->op;
+		int32		tmp = state->curop - state->op;
 
 		state->lenop *= 2;
 		state->op = (char *) repalloc((void *) state->op, state->lenop);
@@ -202,15 +202,15 @@ pushval_asis(QPRS_STATE *state, int type, char *strval, int lenval, uint16 flag)
 /*
  * make polish notaion of query
  */
-static int4
+static int32
 makepol(QPRS_STATE *state)
 {
-	int4		val = 0,
+	int32		val = 0,
 				type;
-	int4		lenval = 0;
+	int32		lenval = 0;
 	char	   *strval = NULL;
-	int4		stack[STACKDEPTH];
-	int4		lenstack = 0;
+	int32		stack[STACKDEPTH];
+	int32		lenstack = 0;
 	uint16		flag = 0;
 
 	while ((type = gettoken_query(state, &val, &lenval, &strval, &flag)) != END)
@@ -219,15 +219,15 @@ makepol(QPRS_STATE *state)
 		{
 			case VAL:
 				pushval_asis(state, VAL, strval, lenval, flag);
-				while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
-									stack[lenstack - 1] == (int4) '!'))
+				while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
+									stack[lenstack - 1] == (int32) '!'))
 				{
 					lenstack--;
 					pushquery(state, OPR, stack[lenstack], 0, 0, 0);
 				}
 				break;
 			case OPR:
-				if (lenstack && val == (int4) '|')
+				if (lenstack && val == (int32) '|')
 					pushquery(state, OPR, val, 0, 0, 0);
 				else
 				{
@@ -241,8 +241,8 @@ makepol(QPRS_STATE *state)
 			case OPEN:
 				if (makepol(state) == ERR)
 					return ERR;
-				while (lenstack && (stack[lenstack - 1] == (int4) '&' ||
-									stack[lenstack - 1] == (int4) '!'))
+				while (lenstack && (stack[lenstack - 1] == (int32) '&' ||
+									stack[lenstack - 1] == (int32) '!'))
 				{
 					lenstack--;
 					pushquery(state, OPR, stack[lenstack], 0, 0, 0);
@@ -275,14 +275,14 @@ makepol(QPRS_STATE *state)
 }
 
 static void
-findoprnd(ITEM *ptr, int4 *pos)
+findoprnd(ITEM *ptr, int32 *pos)
 {
 	if (ptr[*pos].type == VAL || ptr[*pos].type == VALTRUE)
 	{
 		ptr[*pos].left = 0;
 		(*pos)++;
 	}
-	else if (ptr[*pos].val == (int4) '!')
+	else if (ptr[*pos].val == (int32) '!')
 	{
 		ptr[*pos].left = 1;
 		(*pos)++;
@@ -291,7 +291,7 @@ findoprnd(ITEM *ptr, int4 *pos)
 	else
 	{
 		ITEM	   *curitem = &ptr[*pos];
-		int4		tmp = *pos;
+		int32		tmp = *pos;
 
 		(*pos)++;
 		findoprnd(ptr, pos);
@@ -308,12 +308,12 @@ static ltxtquery *
 queryin(char *buf)
 {
 	QPRS_STATE	state;
-	int4		i;
+	int32		i;
 	ltxtquery  *query;
-	int4		commonlen;
+	int32		commonlen;
 	ITEM	   *ptr;
 	NODE	   *tmp;
-	int4		pos = 0;
+	int32		pos = 0;
 
 #ifdef BS_DEBUG
 	char		pbuf[16384],
@@ -390,13 +390,13 @@ typedef struct
 	char	   *buf;
 	char	   *cur;
 	char	   *op;
-	int4		buflen;
+	int32		buflen;
 } INFIX;
 
 #define RESIZEBUF(inf,addsize) \
 while( ( (inf)->cur - (inf)->buf ) + (addsize) + 1 >= (inf)->buflen ) \
 { \
-	int4 len = (inf)->cur - (inf)->buf; \
+	int32 len = (inf)->cur - (inf)->buf; \
 	(inf)->buflen *= 2; \
 	(inf)->buf = (char*) repalloc( (void*)(inf)->buf, (inf)->buflen ); \
 	(inf)->cur = (inf)->buf + len; \
@@ -438,7 +438,7 @@ infix(INFIX *in, bool first)
 		*(in->cur) = '\0';
 		in->curpol++;
 	}
-	else if (in->curpol->val == (int4) '!')
+	else if (in->curpol->val == (int32) '!')
 	{
 		bool		isopr = false;
 
@@ -464,11 +464,11 @@ infix(INFIX *in, bool first)
 	}
 	else
 	{
-		int4		op = in->curpol->val;
+		int32		op = in->curpol->val;
 		INFIX		nrm;
 
 		in->curpol++;
-		if (op == (int4) '|' && !first)
+		if (op == (int32) '|' && !first)
 		{
 			RESIZEBUF(in, 2);
 			sprintf(in->cur, "( ");
@@ -493,7 +493,7 @@ infix(INFIX *in, bool first)
 		in->cur = strchr(in->cur, '\0');
 		pfree(nrm.buf);
 
-		if (op == (int4) '|' && !first)
+		if (op == (int32) '|' && !first)
 		{
 			RESIZEBUF(in, 2);
 			sprintf(in->cur, " )");
diff --git a/contrib/ltree/ltxtquery_op.c b/contrib/ltree/ltxtquery_op.c
index 1c138886058..bedbe247eb8 100644
--- a/contrib/ltree/ltxtquery_op.c
+++ b/contrib/ltree/ltxtquery_op.c
@@ -20,13 +20,13 @@ ltree_execute(ITEM *curitem, void *checkval, bool calcnot, bool (*chkcond) (void
 {
 	if (curitem->type == VAL)
 		return (*chkcond) (checkval, curitem);
-	else if (curitem->val == (int4) '!')
+	else if (curitem->val == (int32) '!')
 	{
 		return (calcnot) ?
 			((ltree_execute(curitem + 1, checkval, calcnot, chkcond)) ? false : true)
 			: true;
 	}
-	else if (curitem->val == (int4) '&')
+	else if (curitem->val == (int32) '&')
 	{
 		if (ltree_execute(curitem + curitem->left, checkval, calcnot, chkcond))
 			return ltree_execute(curitem + 1, checkval, calcnot, chkcond);
diff --git a/contrib/pg_trgm/trgm_gist.c b/contrib/pg_trgm/trgm_gist.c
index d59c8eb670b..605d7ea3569 100644
--- a/contrib/pg_trgm/trgm_gist.c
+++ b/contrib/pg_trgm/trgm_gist.c
@@ -78,10 +78,10 @@ gtrgm_out(PG_FUNCTION_ARGS)
 static void
 makesign(BITVECP sign, TRGM *a)
 {
-	int4		k,
+	int32		k,
 				len = ARRNELEM(a);
 	trgm	   *ptr = GETARR(a);
-	int4		tmp = 0;
+	int32		tmp = 0;
 
 	MemSet((void *) sign, 0, sizeof(BITVEC));
 	SETBIT(sign, SIGLENBIT);	/* set last unused bit */
@@ -112,7 +112,7 @@ gtrgm_compress(PG_FUNCTION_ARGS)
 	else if (ISSIGNKEY(DatumGetPointer(entry->key)) &&
 			 !ISALLTRUE(DatumGetPointer(entry->key)))
 	{
-		int4		i,
+		int32		i,
 					len;
 		TRGM	   *res;
 		BITVECP		sign = GETSIGN(DatumGetPointer(entry->key));
@@ -160,14 +160,14 @@ gtrgm_decompress(PG_FUNCTION_ARGS)
 	}
 }
 
-static int4
+static int32
 cnt_sml_sign_common(TRGM *qtrg, BITVECP sign)
 {
-	int4		count = 0;
-	int4		k,
+	int32		count = 0;
+	int32		k,
 				len = ARRNELEM(qtrg);
 	trgm	   *ptr = GETARR(qtrg);
-	int4		tmp = 0;
+	int32		tmp = 0;
 
 	for (k = 0; k < len; k++)
 	{
@@ -267,8 +267,8 @@ gtrgm_consistent(PG_FUNCTION_ARGS)
 			}
 			else
 			{					/* non-leaf contains signature */
-				int4		count = cnt_sml_sign_common(qtrg, GETSIGN(key));
-				int4		len = ARRNELEM(qtrg);
+				int32		count = cnt_sml_sign_common(qtrg, GETSIGN(key));
+				int32		len = ARRNELEM(qtrg);
 
 				if (len == 0)
 					res = false;
@@ -379,8 +379,8 @@ gtrgm_distance(PG_FUNCTION_ARGS)
 			}
 			else
 			{					/* non-leaf contains signature */
-				int4		count = cnt_sml_sign_common(qtrg, GETSIGN(key));
-				int4		len = ARRNELEM(qtrg);
+				int32		count = cnt_sml_sign_common(qtrg, GETSIGN(key));
+				int32		len = ARRNELEM(qtrg);
 
 				res = (len == 0) ? -1.0 : 1.0 - ((float8) count) / ((float8) len);
 			}
@@ -394,10 +394,10 @@ gtrgm_distance(PG_FUNCTION_ARGS)
 	PG_RETURN_FLOAT8(res);
 }
 
-static int4
+static int32
 unionkey(BITVECP sbase, TRGM *add)
 {
-	int4		i;
+	int32		i;
 
 	if (ISSIGNKEY(add))
 	{
@@ -412,7 +412,7 @@ unionkey(BITVECP sbase, TRGM *add)
 	else
 	{
 		trgm	   *ptr = GETARR(add);
-		int4		tmp = 0;
+		int32		tmp = 0;
 
 		for (i = 0; i < ARRNELEM(add); i++)
 		{
@@ -428,11 +428,11 @@ Datum
 gtrgm_union(PG_FUNCTION_ARGS)
 {
 	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
-	int4		len = entryvec->n;
+	int32		len = entryvec->n;
 	int		   *size = (int *) PG_GETARG_POINTER(1);
 	BITVEC		base;
-	int4		i;
-	int4		flag = 0;
+	int32		i;
+	int32		flag = 0;
 	TRGM	   *result;
 
 	MemSet((void *) base, 0, sizeof(BITVEC));
@@ -474,7 +474,7 @@ gtrgm_same(PG_FUNCTION_ARGS)
 			*result = false;
 		else
 		{
-			int4		i;
+			int32		i;
 			BITVECP		sa = GETSIGN(a),
 						sb = GETSIGN(b);
 
@@ -491,7 +491,7 @@ gtrgm_same(PG_FUNCTION_ARGS)
 	}
 	else
 	{							/* a and b ISARRKEY */
-		int4		lena = ARRNELEM(a),
+		int32		lena = ARRNELEM(a),
 					lenb = ARRNELEM(b);
 
 		if (lena != lenb)
@@ -500,7 +500,7 @@ gtrgm_same(PG_FUNCTION_ARGS)
 		{
 			trgm	   *ptra = GETARR(a),
 					   *ptrb = GETARR(b);
-			int4		i;
+			int32		i;
 
 			*result = true;
 			for (i = 0; i < lena; i++)
@@ -515,10 +515,10 @@ gtrgm_same(PG_FUNCTION_ARGS)
 	PG_RETURN_POINTER(result);
 }
 
-static int4
+static int32
 sizebitvec(BITVECP sign)
 {
-	int4		size = 0,
+	int32		size = 0,
 				i;
 
 	LOOPBYTE
@@ -634,7 +634,7 @@ fillcache(CACHESIGN *item, TRGM *key)
 typedef struct
 {
 	OffsetNumber pos;
-	int4		cost;
+	int32		cost;
 } SPLITCOST;
 
 static int
@@ -675,11 +675,11 @@ gtrgm_picksplit(PG_FUNCTION_ARGS)
 			   *datum_r;
 	BITVECP		union_l,
 				union_r;
-	int4		size_alpha,
+	int32		size_alpha,
 				size_beta;
-	int4		size_waste,
+	int32		size_waste,
 				waste = -1;
-	int4		nbytes;
+	int32		nbytes;
 	OffsetNumber seed_1 = 0,
 				seed_2 = 0;
 	OffsetNumber *left,
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index e2b10703ee9..7b2d2b0ad39 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -1739,6 +1739,13 @@ PG_MODULE_MAGIC;
 /* 4-byte integer, passed by value */
 typedef int int4;
 </programlisting>
+
+     (The actual PostgreSQL C code calls this type <type>int32</type>, because
+     it is a convention in C that <type>int<replaceable>XX</replaceable></type>
+     means <replaceable>XX</replaceable> <emphasis>bits</emphasis>.  Note
+     therefore also that the C type <type>int8</type> is 1 byte in size.  The
+     SQL type <type>int8</type> is called <type>int64</type> in C.  See also
+     <xref linkend="xfunc-c-type-table">.)
     </para>
 
     <para>
@@ -1801,7 +1808,7 @@ typedef struct
 
 <programlisting>
 typedef struct {
-    int4 length;
+    int32 length;
     char data[1];
 } text;
 </programlisting>
@@ -1913,7 +1920,7 @@ memcpy(destination->data, buffer, 40);
         </row>
         <row>
          <entry><type>smallint</type> (<type>int2</type>)</entry>
-         <entry><type>int2</type> or <type>int16</type></entry>
+         <entry><type>int16</type></entry>
          <entry><filename>postgres.h</filename></entry>
         </row>
         <row>
@@ -1923,7 +1930,7 @@ memcpy(destination->data, buffer, 40);
         </row>
         <row>
          <entry><type>integer</type> (<type>int4</type>)</entry>
-         <entry><type>int4</type> or <type>int32</type></entry>
+         <entry><type>int32</type></entry>
          <entry><filename>postgres.h</filename></entry>
         </row>
         <row>
diff --git a/src/backend/access/hash/hashfunc.c b/src/backend/access/hash/hashfunc.c
index 0e4cf8e0a3e..033674652db 100644
--- a/src/backend/access/hash/hashfunc.c
+++ b/src/backend/access/hash/hashfunc.c
@@ -135,7 +135,7 @@ hashint2vector(PG_FUNCTION_ARGS)
 {
 	int2vector *key = (int2vector *) PG_GETARG_POINTER(0);
 
-	return hash_any((unsigned char *) key->values, key->dim1 * sizeof(int2));
+	return hash_any((unsigned char *) key->values, key->dim1 * sizeof(int16));
 }
 
 Datum
diff --git a/src/backend/access/spgist/spgquadtreeproc.c b/src/backend/access/spgist/spgquadtreeproc.c
index 5da265025e6..e8fdc4990ba 100644
--- a/src/backend/access/spgist/spgquadtreeproc.c
+++ b/src/backend/access/spgist/spgquadtreeproc.c
@@ -50,7 +50,7 @@ spg_quad_config(PG_FUNCTION_ARGS)
  * Points on one of the axes are taken to lie in the lowest-numbered
  * adjacent quadrant.
  */
-static int2
+static int16
 getQuadrant(Point *centroid, Point *tst)
 {
 	if ((SPTEST(point_above, tst, centroid) ||
diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm
index cdb0bee1305..0be29e304e6 100644
--- a/src/backend/catalog/Catalog.pm
+++ b/src/backend/catalog/Catalog.pm
@@ -31,6 +31,8 @@ sub Catalogs
     # There are a few types which are given one name in the C source, but a
     # different name at the SQL level.  These are enumerated here.
     my %RENAME_ATTTYPE = (
+        'int16'		=> 'int2',
+        'int32'		=> 'int4',
         'Oid'           => 'oid',
         'NameData'      => 'name',
         'TransactionId' => 'xid'
diff --git a/src/backend/catalog/namespace.c b/src/backend/catalog/namespace.c
index 1b6bb3bb6d7..20850ab034a 100644
--- a/src/backend/catalog/namespace.c
+++ b/src/backend/catalog/namespace.c
@@ -3332,7 +3332,7 @@ get_conversion_oid(List *name, bool missing_ok)
  * FindDefaultConversionProc - find default encoding conversion proc
  */
 Oid
-FindDefaultConversionProc(int4 for_encoding, int4 to_encoding)
+FindDefaultConversionProc(int32 for_encoding, int32 to_encoding)
 {
 	Oid			proc;
 	ListCell   *l;
diff --git a/src/backend/catalog/pg_type.c b/src/backend/catalog/pg_type.c
index 5b2ad6bfe0d..6062926e604 100644
--- a/src/backend/catalog/pg_type.c
+++ b/src/backend/catalog/pg_type.c
@@ -91,7 +91,7 @@ TypeShellMake(const char *typeName, Oid typeNamespace, Oid ownerId)
 	values[Anum_pg_type_typname - 1] = NameGetDatum(&name);
 	values[Anum_pg_type_typnamespace - 1] = ObjectIdGetDatum(typeNamespace);
 	values[Anum_pg_type_typowner - 1] = ObjectIdGetDatum(ownerId);
-	values[Anum_pg_type_typlen - 1] = Int16GetDatum(sizeof(int4));
+	values[Anum_pg_type_typlen - 1] = Int16GetDatum(sizeof(int32));
 	values[Anum_pg_type_typbyval - 1] = BoolGetDatum(true);
 	values[Anum_pg_type_typtype - 1] = CharGetDatum(TYPTYPE_PSEUDO);
 	values[Anum_pg_type_typcategory - 1] = CharGetDatum(TYPCATEGORY_PSEUDOTYPE);
diff --git a/src/backend/commands/cluster.c b/src/backend/commands/cluster.c
index a72b0ad5ff2..cfec413d54f 100644
--- a/src/backend/commands/cluster.c
+++ b/src/backend/commands/cluster.c
@@ -1204,9 +1204,9 @@ swap_relation_files(Oid r1, Oid r2, bool target_is_pg_class,
 
 	/* swap size statistics too, since new rel has freshly-updated stats */
 	{
-		int4		swap_pages;
+		int32		swap_pages;
 		float4		swap_tuples;
-		int4		swap_allvisible;
+		int32		swap_allvisible;
 
 		swap_pages = relform1->relpages;
 		relform1->relpages = relform2->relpages;
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 834b694ec6b..faa7f0c4c50 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -121,7 +121,7 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
 {
 	int16		tgtype;
 	int			ncolumns;
-	int2	   *columns;
+	int16	   *columns;
 	int2vector *tgattr;
 	Node	   *whenClause;
 	List	   *whenRtable;
@@ -589,11 +589,11 @@ CreateTrigger(CreateTrigStmt *stmt, const char *queryString,
 		ListCell   *cell;
 		int			i = 0;
 
-		columns = (int2 *) palloc(ncolumns * sizeof(int2));
+		columns = (int16 *) palloc(ncolumns * sizeof(int16));
 		foreach(cell, stmt->columns)
 		{
 			char	   *name = strVal(lfirst(cell));
-			int2		attnum;
+			int16		attnum;
 			int			j;
 
 			/* Lookup column name.	System columns are not allowed */
@@ -1501,9 +1501,9 @@ RelationBuildTriggers(Relation relation)
 		build->tgnattr = pg_trigger->tgattr.dim1;
 		if (build->tgnattr > 0)
 		{
-			build->tgattr = (int2 *) palloc(build->tgnattr * sizeof(int2));
+			build->tgattr = (int16 *) palloc(build->tgnattr * sizeof(int16));
 			memcpy(build->tgattr, &(pg_trigger->tgattr.values),
-				   build->tgnattr * sizeof(int2));
+				   build->tgnattr * sizeof(int16));
 		}
 		else
 			build->tgattr = NULL;
@@ -1654,11 +1654,11 @@ CopyTriggerDesc(TriggerDesc *trigdesc)
 		trigger->tgname = pstrdup(trigger->tgname);
 		if (trigger->tgnattr > 0)
 		{
-			int2	   *newattr;
+			int16	   *newattr;
 
-			newattr = (int2 *) palloc(trigger->tgnattr * sizeof(int2));
+			newattr = (int16 *) palloc(trigger->tgnattr * sizeof(int16));
 			memcpy(newattr, trigger->tgattr,
-				   trigger->tgnattr * sizeof(int2));
+				   trigger->tgnattr * sizeof(int16));
 			trigger->tgattr = newattr;
 		}
 		if (trigger->tgnargs > 0)
@@ -1772,7 +1772,7 @@ equalTriggerDescs(TriggerDesc *trigdesc1, TriggerDesc *trigdesc2)
 				return false;
 			if (trig1->tgnattr > 0 &&
 				memcmp(trig1->tgattr, trig2->tgattr,
-					   trig1->tgnattr * sizeof(int2)) != 0)
+					   trig1->tgnattr * sizeof(int16)) != 0)
 				return false;
 			for (j = 0; j < trig1->tgnargs; j++)
 				if (strcmp(trig1->tgargs[j], trig2->tgargs[j]) != 0)
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index 6475633ae7d..8ee6cf7f0e0 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -987,7 +987,7 @@ generate_setop_tlist(List *colTypes, List *colCollations,
 		expr = (Node *) makeConst(INT4OID,
 								  -1,
 								  InvalidOid,
-								  sizeof(int4),
+								  sizeof(int32),
 								  Int32GetDatum(flag),
 								  false,
 								  true);
diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c
index 8810d0dbad5..adc0d5b775e 100644
--- a/src/backend/parser/parse_utilcmd.c
+++ b/src/backend/parser/parse_utilcmd.c
@@ -1578,7 +1578,7 @@ transformIndexConstraint(Constraint *constraint, CreateStmtContext *cxt)
 
 		for (i = 0; i < index_form->indnatts; i++)
 		{
-			int2		attnum = index_form->indkey.values[i];
+			int16		attnum = index_form->indkey.values[i];
 			Form_pg_attribute attform;
 			char	   *attname;
 			Oid			defopclass;
diff --git a/src/backend/tsearch/to_tsany.c b/src/backend/tsearch/to_tsany.c
index bb886ee5849..7a4fa93ee75 100644
--- a/src/backend/tsearch/to_tsany.c
+++ b/src/backend/tsearch/to_tsany.c
@@ -49,7 +49,7 @@ compareWORD(const void *a, const void *b)
 }
 
 static int
-uniqueWORD(ParsedWord *a, int4 l)
+uniqueWORD(ParsedWord *a, int32 l)
 {
 	ParsedWord *ptr,
 			   *res;
@@ -265,9 +265,9 @@ to_tsvector(PG_FUNCTION_ARGS)
  * and different variants are ORred together.
  */
 static void
-pushval_morph(Datum opaque, TSQueryParserState state, char *strval, int lenval, int2 weight, bool prefix)
+pushval_morph(Datum opaque, TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
 {
-	int4		count = 0;
+	int32		count = 0;
 	ParsedText	prs;
 	uint32		variant,
 				pos,
@@ -333,7 +333,7 @@ to_tsquery_byid(PG_FUNCTION_ARGS)
 	text	   *in = PG_GETARG_TEXT_P(1);
 	TSQuery		query;
 	QueryItem  *res;
-	int4		len;
+	int32		len;
 
 	query = parse_tsquery(text_to_cstring(in), pushval_morph, ObjectIdGetDatum(cfgid), false);
 
@@ -357,7 +357,7 @@ to_tsquery_byid(PG_FUNCTION_ARGS)
 	if (len != query->size)
 	{
 		char	   *oldoperand = GETOPERAND(query);
-		int4		lenoperand = VARSIZE(query) - (oldoperand - (char *) query);
+		int32		lenoperand = VARSIZE(query) - (oldoperand - (char *) query);
 
 		Assert(len < query->size);
 
@@ -389,7 +389,7 @@ plainto_tsquery_byid(PG_FUNCTION_ARGS)
 	text	   *in = PG_GETARG_TEXT_P(1);
 	TSQuery		query;
 	QueryItem  *res;
-	int4		len;
+	int32		len;
 
 	query = parse_tsquery(text_to_cstring(in), pushval_morph, ObjectIdGetDatum(cfgid), true);
 
@@ -408,7 +408,7 @@ plainto_tsquery_byid(PG_FUNCTION_ARGS)
 	if (len != query->size)
 	{
 		char	   *oldoperand = GETOPERAND(query);
-		int4		lenoperand = VARSIZE(query) - (oldoperand - (char *) query);
+		int32		lenoperand = VARSIZE(query) - (oldoperand - (char *) query);
 
 		Assert(len < query->size);
 
diff --git a/src/backend/tsearch/ts_parse.c b/src/backend/tsearch/ts_parse.c
index 805fa25d5ee..ae59c34938c 100644
--- a/src/backend/tsearch/ts_parse.c
+++ b/src/backend/tsearch/ts_parse.c
@@ -592,7 +592,7 @@ generateHeadline(HeadlineParsedText *prs)
 	char	   *ptr;
 	int			len = 128;
 	int			numfragments = 0;
-	int2		infrag = 0;
+	int16		infrag = 0;
 
 	HeadlineWordEntry *wrd = prs->words;
 
diff --git a/src/backend/tsearch/wparser_def.c b/src/backend/tsearch/wparser_def.c
index f2ec784ac23..56763412f3b 100644
--- a/src/backend/tsearch/wparser_def.c
+++ b/src/backend/tsearch/wparser_def.c
@@ -2133,12 +2133,12 @@ mark_fragment(HeadlineParsedText *prs, int highlight, int startpos, int endpos)
 
 typedef struct
 {
-	int4		startpos;
-	int4		endpos;
-	int4		poslen;
-	int4		curlen;
-	int2		in;
-	int2		excluded;
+	int32		startpos;
+	int32		endpos;
+	int32		poslen;
+	int32		curlen;
+	int16		in;
+	int16		excluded;
 } CoverPos;
 
 static void
@@ -2191,24 +2191,24 @@ mark_hl_fragments(HeadlineParsedText *prs, TSQuery query, int highlight,
 				  int shortword, int min_words,
 				  int max_words, int max_fragments)
 {
-	int4		poslen,
+	int32		poslen,
 				curlen,
 				i,
 				f,
 				num_f = 0;
-	int4		stretch,
+	int32		stretch,
 				maxstretch,
 				posmarker;
 
-	int4		startpos = 0,
+	int32		startpos = 0,
 				endpos = 0,
 				p = 0,
 				q = 0;
 
-	int4		numcovers = 0,
+	int32		numcovers = 0,
 				maxcovers = 32;
 
-	int4		minI,
+	int32		minI,
 				minwords,
 				maxitems;
 	CoverPos   *covers;
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c
index 5582a06c7f2..c221c20c9f6 100644
--- a/src/backend/utils/adt/arrayfuncs.c
+++ b/src/backend/utils/adt/arrayfuncs.c
@@ -4713,8 +4713,8 @@ array_smaller(PG_FUNCTION_ARGS)
 
 typedef struct generate_subscripts_fctx
 {
-	int4		lower;
-	int4		upper;
+	int32		lower;
+	int32		upper;
 	bool		reverse;
 } generate_subscripts_fctx;
 
diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c
index a339abf17b6..4be39014495 100644
--- a/src/backend/utils/adt/int.c
+++ b/src/backend/utils/adt/int.c
@@ -40,7 +40,7 @@
 
 #define SAMESIGN(a,b)	(((a) < 0) == ((b) < 0))
 
-#define Int2VectorSize(n)	(offsetof(int2vector, values) + (n) * sizeof(int2))
+#define Int2VectorSize(n)	(offsetof(int2vector, values) + (n) * sizeof(int16))
 
 typedef struct
 {
@@ -109,14 +109,14 @@ int2send(PG_FUNCTION_ARGS)
  * If int2s is NULL then caller must fill values[] afterward
  */
 int2vector *
-buildint2vector(const int2 *int2s, int n)
+buildint2vector(const int16 *int2s, int n)
 {
 	int2vector *result;
 
 	result = (int2vector *) palloc0(Int2VectorSize(n));
 
 	if (n > 0 && int2s)
-		memcpy(result->values, int2s, n * sizeof(int2));
+		memcpy(result->values, int2s, n * sizeof(int16));
 
 	/*
 	 * Attach standard array header.  For historical reasons, we set the index
@@ -266,7 +266,7 @@ int2vectoreq(PG_FUNCTION_ARGS)
 
 	if (a->dim1 != b->dim1)
 		PG_RETURN_BOOL(false);
-	PG_RETURN_BOOL(memcmp(a->values, b->values, a->dim1 * sizeof(int2)) == 0);
+	PG_RETURN_BOOL(memcmp(a->values, b->values, a->dim1 * sizeof(int16)) == 0);
 }
 
 
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 5bf3533a114..ec93149f3e7 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2394,7 +2394,7 @@ make_ruledef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
 	char	   *rulename;
 	char		ev_type;
 	Oid			ev_class;
-	int2		ev_attr;
+	int16		ev_attr;
 	bool		is_instead;
 	char	   *ev_qual;
 	char	   *ev_action;
@@ -2584,7 +2584,7 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
 	Query	   *query;
 	char		ev_type;
 	Oid			ev_class;
-	int2		ev_attr;
+	int16		ev_attr;
 	bool		is_instead;
 	char	   *ev_qual;
 	char	   *ev_action;
@@ -2603,7 +2603,7 @@ make_viewdef(StringInfo buf, HeapTuple ruletup, TupleDesc rulettc,
 	ev_class = (Oid) SPI_getbinval(ruletup, rulettc, fno, &isnull);
 
 	fno = SPI_fnumber(rulettc, "ev_attr");
-	ev_attr = (int2) SPI_getbinval(ruletup, rulettc, fno, &isnull);
+	ev_attr = (int16) SPI_getbinval(ruletup, rulettc, fno, &isnull);
 
 	fno = SPI_fnumber(rulettc, "is_instead");
 	is_instead = (bool) SPI_getbinval(ruletup, rulettc, fno, &isnull);
diff --git a/src/backend/utils/adt/tsginidx.c b/src/backend/utils/adt/tsginidx.c
index 8900c0f4978..8b045c6e739 100644
--- a/src/backend/utils/adt/tsginidx.c
+++ b/src/backend/utils/adt/tsginidx.c
@@ -109,7 +109,7 @@ gin_extract_tsquery(PG_FUNCTION_ARGS)
 	if (query->size > 0)
 	{
 		QueryItem  *item = GETQUERY(query);
-		int4		i,
+		int32		i,
 					j;
 		bool	   *partialmatch;
 		int		   *map_item_operand;
diff --git a/src/backend/utils/adt/tsgistidx.c b/src/backend/utils/adt/tsgistidx.c
index 674e48c871d..dd8164b9dfe 100644
--- a/src/backend/utils/adt/tsgistidx.c
+++ b/src/backend/utils/adt/tsgistidx.c
@@ -22,7 +22,7 @@
 #define SIGLENINT  31			/* >121 => key will toast, so it will not work
 								 * !!! */
 
-#define SIGLEN	( sizeof(int4) * SIGLENINT )
+#define SIGLEN	( sizeof(int32) * SIGLENINT )
 #define SIGLENBIT (SIGLEN * BITS_PER_BYTE)
 
 typedef char BITVEC[SIGLEN];
@@ -49,7 +49,7 @@ typedef char *BITVECP;
 typedef struct
 {
 	int32		vl_len_;		/* varlena header (do not touch directly!) */
-	int4		flag;
+	int32		flag;
 	char		data[1];
 } SignTSVector;
 
@@ -61,12 +61,12 @@ typedef struct
 #define ISSIGNKEY(x)	( ((SignTSVector*)(x))->flag & SIGNKEY )
 #define ISALLTRUE(x)	( ((SignTSVector*)(x))->flag & ALLISTRUE )
 
-#define GTHDRSIZE	( VARHDRSZ + sizeof(int4) )
-#define CALCGTSIZE(flag, len) ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int4)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
+#define GTHDRSIZE	( VARHDRSZ + sizeof(int32) )
+#define CALCGTSIZE(flag, len) ( GTHDRSIZE + ( ( (flag) & ARRKEY ) ? ((len)*sizeof(int32)) : (((flag) & ALLISTRUE) ? 0 : SIGLEN) ) )
 
 #define GETSIGN(x)	( (BITVECP)( (char*)(x)+GTHDRSIZE ) )
-#define GETARR(x)	( (int4*)( (char*)(x)+GTHDRSIZE ) )
-#define ARRNELEM(x) ( ( VARSIZE(x) - GTHDRSIZE )/sizeof(int4) )
+#define GETARR(x)	( (int32*)( (char*)(x)+GTHDRSIZE ) )
+#define ARRNELEM(x) ( ( VARSIZE(x) - GTHDRSIZE )/sizeof(int32) )
 
 /* Number of one-bits in an unsigned byte */
 static const uint8 number_of_ones[256] = {
@@ -88,7 +88,7 @@ static const uint8 number_of_ones[256] = {
 	4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
 };
 
-static int4 sizebitvec(BITVECP sign);
+static int32 sizebitvec(BITVECP sign);
 
 Datum
 gtsvectorin(PG_FUNCTION_ARGS)
@@ -131,8 +131,8 @@ gtsvectorout(PG_FUNCTION_ARGS)
 static int
 compareint(const void *va, const void *vb)
 {
-	int4		a = *((const int4 *) va);
-	int4		b = *((const int4 *) vb);
+	int32		a = *((const int32 *) va);
+	int32		b = *((const int32 *) vb);
 
 	if (a == b)
 		return 0;
@@ -140,13 +140,13 @@ compareint(const void *va, const void *vb)
 }
 
 /*
- * Removes duplicates from an array of int4. 'l' is
+ * Removes duplicates from an array of int32. 'l' is
  * size of the input array. Returns the new size of the array.
  */
 static int
-uniqueint(int4 *a, int4 l)
+uniqueint(int32 *a, int32 l)
 {
-	int4	   *ptr,
+	int32	   *ptr,
 			   *res;
 
 	if (l <= 1)
@@ -154,7 +154,7 @@ uniqueint(int4 *a, int4 l)
 
 	ptr = res = a;
 
-	qsort((void *) a, l, sizeof(int4), compareint);
+	qsort((void *) a, l, sizeof(int32), compareint);
 
 	while (ptr - a < l)
 		if (*ptr != *res)
@@ -167,9 +167,9 @@ uniqueint(int4 *a, int4 l)
 static void
 makesign(BITVECP sign, SignTSVector *a)
 {
-	int4		k,
+	int32		k,
 				len = ARRNELEM(a);
-	int4	   *ptr = GETARR(a);
+	int32	   *ptr = GETARR(a);
 
 	MemSet((void *) sign, 0, sizeof(BITVEC));
 	for (k = 0; k < len; k++)
@@ -186,8 +186,8 @@ gtsvector_compress(PG_FUNCTION_ARGS)
 	{							/* tsvector */
 		SignTSVector *res;
 		TSVector	val = DatumGetTSVector(entry->key);
-		int4		len;
-		int4	   *arr;
+		int32		len;
+		int32	   *arr;
 		WordEntry  *ptr = ARRPTR(val);
 		char	   *words = STRPTR(val);
 
@@ -205,7 +205,7 @@ gtsvector_compress(PG_FUNCTION_ARGS)
 			COMP_CRC32(c, words + ptr->pos, ptr->len);
 			FIN_CRC32(c);
 
-			*arr = *(int4 *) &c;
+			*arr = *(int32 *) &c;
 			arr++;
 			ptr++;
 		}
@@ -243,7 +243,7 @@ gtsvector_compress(PG_FUNCTION_ARGS)
 	else if (ISSIGNKEY(DatumGetPointer(entry->key)) &&
 			 !ISALLTRUE(DatumGetPointer(entry->key)))
 	{
-		int4		i,
+		int32		i,
 					len;
 		SignTSVector *res;
 		BITVECP		sign = GETSIGN(DatumGetPointer(entry->key));
@@ -289,8 +289,8 @@ gtsvector_decompress(PG_FUNCTION_ARGS)
 
 typedef struct
 {
-	int4	   *arrb;
-	int4	   *arre;
+	int32	   *arrb;
+	int32	   *arre;
 } CHKVAL;
 
 /*
@@ -299,9 +299,9 @@ typedef struct
 static bool
 checkcondition_arr(void *checkval, QueryOperand *val)
 {
-	int4	   *StopLow = ((CHKVAL *) checkval)->arrb;
-	int4	   *StopHigh = ((CHKVAL *) checkval)->arre;
-	int4	   *StopMiddle;
+	int32	   *StopLow = ((CHKVAL *) checkval)->arrb;
+	int32	   *StopHigh = ((CHKVAL *) checkval)->arre;
+	int32	   *StopMiddle;
 
 	/* Loop invariant: StopLow <= val < StopHigh */
 
@@ -378,10 +378,10 @@ gtsvector_consistent(PG_FUNCTION_ARGS)
 	}
 }
 
-static int4
+static int32
 unionkey(BITVECP sbase, SignTSVector *add)
 {
-	int4		i;
+	int32		i;
 
 	if (ISSIGNKEY(add))
 	{
@@ -395,7 +395,7 @@ unionkey(BITVECP sbase, SignTSVector *add)
 	}
 	else
 	{
-		int4	   *ptr = GETARR(add);
+		int32	   *ptr = GETARR(add);
 
 		for (i = 0; i < ARRNELEM(add); i++)
 			HASH(sbase, ptr[i]);
@@ -410,9 +410,9 @@ gtsvector_union(PG_FUNCTION_ARGS)
 	GistEntryVector *entryvec = (GistEntryVector *) PG_GETARG_POINTER(0);
 	int		   *size = (int *) PG_GETARG_POINTER(1);
 	BITVEC		base;
-	int4		i,
+	int32		i,
 				len;
-	int4		flag = 0;
+	int32		flag = 0;
 	SignTSVector *result;
 
 	MemSet((void *) base, 0, sizeof(BITVEC));
@@ -454,7 +454,7 @@ gtsvector_same(PG_FUNCTION_ARGS)
 			*result = false;
 		else
 		{
-			int4		i;
+			int32		i;
 			BITVECP		sa = GETSIGN(a),
 						sb = GETSIGN(b);
 
@@ -471,16 +471,16 @@ gtsvector_same(PG_FUNCTION_ARGS)
 	}
 	else
 	{							/* a and b ISARRKEY */
-		int4		lena = ARRNELEM(a),
+		int32		lena = ARRNELEM(a),
 					lenb = ARRNELEM(b);
 
 		if (lena != lenb)
 			*result = false;
 		else
 		{
-			int4	   *ptra = GETARR(a),
+			int32	   *ptra = GETARR(a),
 					   *ptrb = GETARR(b);
-			int4		i;
+			int32		i;
 
 			*result = true;
 			for (i = 0; i < lena; i++)
@@ -495,10 +495,10 @@ gtsvector_same(PG_FUNCTION_ARGS)
 	PG_RETURN_POINTER(result);
 }
 
-static int4
+static int32
 sizebitvec(BITVECP sign)
 {
-	int4		size = 0,
+	int32		size = 0,
 				i;
 
 	LOOPBYTE
@@ -587,7 +587,7 @@ fillcache(CACHESIGN *item, SignTSVector *key)
 typedef struct
 {
 	OffsetNumber pos;
-	int4		cost;
+	int32		cost;
 } SPLITCOST;
 
 static int
@@ -630,11 +630,11 @@ gtsvector_picksplit(PG_FUNCTION_ARGS)
 			   *datum_r;
 	BITVECP		union_l,
 				union_r;
-	int4		size_alpha,
+	int32		size_alpha,
 				size_beta;
-	int4		size_waste,
+	int32		size_waste,
 				waste = -1;
-	int4		nbytes;
+	int32		nbytes;
 	OffsetNumber seed_1 = 0,
 				seed_2 = 0;
 	OffsetNumber *left,
diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c
index 6e1f8cfdb0d..010167a8a92 100644
--- a/src/backend/utils/adt/tsquery.c
+++ b/src/backend/utils/adt/tsquery.c
@@ -271,7 +271,7 @@ pushValue_internal(TSQueryParserState state, pg_crc32 valcrc, int distance, int
  * of the string.
  */
 void
-pushValue(TSQueryParserState state, char *strval, int lenval, int2 weight, bool prefix)
+pushValue(TSQueryParserState state, char *strval, int lenval, int16 weight, bool prefix)
 {
 	pg_crc32	valcrc;
 
diff --git a/src/backend/utils/adt/tsquery_gist.c b/src/backend/utils/adt/tsquery_gist.c
index 74e40246c42..f76f9fb54e3 100644
--- a/src/backend/utils/adt/tsquery_gist.c
+++ b/src/backend/utils/adt/tsquery_gist.c
@@ -150,7 +150,7 @@ gtsquery_penalty(PG_FUNCTION_ARGS)
 typedef struct
 {
 	OffsetNumber pos;
-	int4		cost;
+	int32		cost;
 } SPLITCOST;
 
 static int
@@ -174,11 +174,11 @@ gtsquery_picksplit(PG_FUNCTION_ARGS)
 				j;
 	TSQuerySign datum_l,
 				datum_r;
-	int4		size_alpha,
+	int32		size_alpha,
 				size_beta;
-	int4		size_waste,
+	int32		size_waste,
 				waste = -1;
-	int4		nbytes;
+	int32		nbytes;
 	OffsetNumber seed_1 = 0,
 				seed_2 = 0;
 	OffsetNumber *left,
diff --git a/src/backend/utils/adt/tsrank.c b/src/backend/utils/adt/tsrank.c
index a45caf05af5..acda098db1a 100644
--- a/src/backend/utils/adt/tsrank.c
+++ b/src/backend/utils/adt/tsrank.c
@@ -40,7 +40,7 @@ static float calc_rank_and(float *w, TSVector t, TSQuery q);
  * Returns a weight of a word collocation
  */
 static float4
-word_distance(int4 w)
+word_distance(int32 w)
 {
 	if (w > 100)
 		return 1e-30f;
@@ -213,7 +213,7 @@ calc_rank_and(float *w, TSVector t, TSQuery q)
 			   *firstentry;
 	WordEntryPos *post,
 			   *ct;
-	int4		dimt,
+	int32		dimt,
 				lenct,
 				dist,
 				nitem;
@@ -283,7 +283,7 @@ calc_rank_or(float *w, TSVector t, TSQuery q)
 	WordEntry  *entry,
 			   *firstentry;
 	WordEntryPos *post;
-	int4		dimt,
+	int32		dimt,
 				j,
 				i,
 				nitem;
@@ -297,7 +297,7 @@ calc_rank_or(float *w, TSVector t, TSQuery q)
 	{
 		float		resj,
 					wjm;
-		int4		jm;
+		int32		jm;
 
 		firstentry = entry = find_wordentry(t, q, item[i], &nitem);
 		if (!entry)
@@ -347,7 +347,7 @@ calc_rank_or(float *w, TSVector t, TSQuery q)
 }
 
 static float
-calc_rank(float *w, TSVector t, TSQuery q, int4 method)
+calc_rank(float *w, TSVector t, TSQuery q, int32 method)
 {
 	QueryItem  *item = GETQUERY(q);
 	float		res = 0.0;
@@ -621,7 +621,7 @@ get_docrep(TSVector txt, QueryRepresentation *qr, int *doclen)
 	WordEntry  *entry,
 			   *firstentry;
 	WordEntryPos *post;
-	int4		dimt,
+	int32		dimt,
 				j,
 				i,
 				nitem;
diff --git a/src/backend/utils/adt/tsvector.c b/src/backend/utils/adt/tsvector.c
index 8a81f3d8295..688e3652c72 100644
--- a/src/backend/utils/adt/tsvector.c
+++ b/src/backend/utils/adt/tsvector.c
@@ -309,7 +309,7 @@ tsvectorout(PG_FUNCTION_ARGS)
 {
 	TSVector	out = PG_GETARG_TSVECTOR(0);
 	char	   *outbuf;
-	int4		i,
+	int32		i,
 				lenbuf = 0,
 				pp;
 	WordEntry  *ptr = ARRPTR(out);
diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c
index eb5c45b3d81..34be330522c 100644
--- a/src/backend/utils/adt/tsvector_op.c
+++ b/src/backend/utils/adt/tsvector_op.c
@@ -51,7 +51,7 @@ typedef struct StatEntry
 
 typedef struct
 {
-	int4		weight;
+	int32		weight;
 
 	uint32		maxdepth;
 
@@ -221,7 +221,7 @@ Datum
 tsvector_length(PG_FUNCTION_ARGS)
 {
 	TSVector	in = PG_GETARG_TSVECTOR(0);
-	int4		ret = in->size;
+	int32		ret = in->size;
 
 	PG_FREE_IF_COPY(in, 0);
 	PG_RETURN_INT32(ret);
@@ -293,10 +293,10 @@ tsvector_setweight(PG_FUNCTION_ARGS)
  * Add positions from src to dest after offsetting them by maxpos.
  * Return the number added (might be less than expected due to overflow)
  */
-static int4
+static int32
 add_pos(TSVector src, WordEntry *srcptr,
 		TSVector dest, WordEntry *destptr,
-		int4 maxpos)
+		int32 maxpos)
 {
 	uint16	   *clen = &_POSVECPTR(dest, destptr)->npos;
 	int			i;
@@ -552,7 +552,7 @@ tsvector_concat(PG_FUNCTION_ARGS)
  *
  * if isPrefix = true then it returns zero value iff b has prefix a
  */
-int4
+int32
 tsCompareString(char *a, int lena, char *b, int lenb, bool prefix)
 {
 	int			cmp;
diff --git a/src/include/access/gin_private.h b/src/include/access/gin_private.h
index e56a92358c7..32f23ad6f5b 100644
--- a/src/include/access/gin_private.h
+++ b/src/include/access/gin_private.h
@@ -195,7 +195,7 @@ typedef signed char GinNullCategory;
  */
 #define GinCategoryOffset(itup,ginstate) \
 	(IndexInfoFindDataOffset((itup)->t_info) + \
-	 ((ginstate)->oneCol ? 0 : sizeof(int2)))
+	 ((ginstate)->oneCol ? 0 : sizeof(int16)))
 #define GinGetNullCategory(itup,ginstate) \
 	(*((GinNullCategory *) ((char*)(itup) + GinCategoryOffset(itup,ginstate))))
 #define GinSetNullCategory(itup,ginstate,c) \
diff --git a/src/include/c.h b/src/include/c.h
index 8b3c5e59967..50e1ecfde4d 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -329,8 +329,6 @@ typedef signed int Offset;
 /*
  * Common Postgres datatype names (as used in the catalogs)
  */
-typedef int16 int2;
-typedef int32 int4;
 typedef float float4;
 typedef double float8;
 
@@ -424,7 +422,7 @@ typedef struct
 	Oid			elemtype;
 	int			dim1;
 	int			lbound1;
-	int2		values[1];		/* VARIABLE LENGTH ARRAY */
+	int16		values[1];		/* VARIABLE LENGTH ARRAY */
 } int2vector;					/* VARIABLE LENGTH STRUCT */
 
 typedef struct
diff --git a/src/include/catalog/namespace.h b/src/include/catalog/namespace.h
index 76215dc8a1e..2b633345a88 100644
--- a/src/include/catalog/namespace.h
+++ b/src/include/catalog/namespace.h
@@ -133,7 +133,7 @@ extern void PopOverrideSearchPath(void);
 
 extern Oid	get_collation_oid(List *collname, bool missing_ok);
 extern Oid	get_conversion_oid(List *conname, bool missing_ok);
-extern Oid	FindDefaultConversionProc(int4 for_encoding, int4 to_encoding);
+extern Oid	FindDefaultConversionProc(int32 for_encoding, int32 to_encoding);
 
 /* initialization & transaction cleanup code */
 extern void InitializeSearchPath(void);
diff --git a/src/include/catalog/pg_am.h b/src/include/catalog/pg_am.h
index 0d7ed6857e8..77570c055f5 100644
--- a/src/include/catalog/pg_am.h
+++ b/src/include/catalog/pg_am.h
@@ -34,11 +34,11 @@
 CATALOG(pg_am,2601)
 {
 	NameData	amname;			/* access method name */
-	int2		amstrategies;	/* total number of strategies (operators) by
+	int16		amstrategies;	/* total number of strategies (operators) by
 								 * which we can traverse/search this AM. Zero
 								 * if AM does not have a fixed set of strategy
 								 * assignments. */
-	int2		amsupport;		/* total number of support functions that this
+	int16		amsupport;		/* total number of support functions that this
 								 * AM uses */
 	bool		amcanorder;		/* does AM support order by column value? */
 	bool		amcanorderbyop; /* does AM support order by operator result? */
diff --git a/src/include/catalog/pg_amop.h b/src/include/catalog/pg_amop.h
index 82391b09d8d..ee6ac8fb698 100644
--- a/src/include/catalog/pg_amop.h
+++ b/src/include/catalog/pg_amop.h
@@ -58,7 +58,7 @@ CATALOG(pg_amop,2602)
 	Oid			amopfamily;		/* the index opfamily this entry is for */
 	Oid			amoplefttype;	/* operator's left input data type */
 	Oid			amoprighttype;	/* operator's right input data type */
-	int2		amopstrategy;	/* operator strategy number */
+	int16		amopstrategy;	/* operator strategy number */
 	char		amoppurpose;	/* is operator for 's'earch or 'o'rdering? */
 	Oid			amopopr;		/* the operator's pg_operator OID */
 	Oid			amopmethod;		/* the index access method this entry is for */
diff --git a/src/include/catalog/pg_amproc.h b/src/include/catalog/pg_amproc.h
index 72307dec220..99d4676a5de 100644
--- a/src/include/catalog/pg_amproc.h
+++ b/src/include/catalog/pg_amproc.h
@@ -47,7 +47,7 @@ CATALOG(pg_amproc,2603)
 	Oid			amprocfamily;	/* the index opfamily this entry is for */
 	Oid			amproclefttype; /* procedure's left input data type */
 	Oid			amprocrighttype;	/* procedure's right input data type */
-	int2		amprocnum;		/* support procedure index */
+	int16		amprocnum;		/* support procedure index */
 	regproc		amproc;			/* OID of the proc */
 } FormData_pg_amproc;
 
diff --git a/src/include/catalog/pg_attrdef.h b/src/include/catalog/pg_attrdef.h
index b92fd1593f9..6c6366bb2f4 100644
--- a/src/include/catalog/pg_attrdef.h
+++ b/src/include/catalog/pg_attrdef.h
@@ -31,7 +31,7 @@
 CATALOG(pg_attrdef,2604)
 {
 	Oid			adrelid;		/* OID of table containing attribute */
-	int2		adnum;			/* attnum of attribute */
+	int16		adnum;			/* attnum of attribute */
 
 #ifdef CATALOG_VARLEN			/* variable-length fields start here */
 	pg_node_tree adbin;			/* nodeToString representation of default */
diff --git a/src/include/catalog/pg_attribute.h b/src/include/catalog/pg_attribute.h
index 4ee1d90ce32..3c4d9e20628 100644
--- a/src/include/catalog/pg_attribute.h
+++ b/src/include/catalog/pg_attribute.h
@@ -54,13 +54,13 @@ CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BK
 	 * that no value has been explicitly set for this column, so ANALYZE
 	 * should use the default setting.
 	 */
-	int4		attstattarget;
+	int32		attstattarget;
 
 	/*
 	 * attlen is a copy of the typlen field from pg_type for this attribute.
 	 * See atttypid comments above.
 	 */
-	int2		attlen;
+	int16		attlen;
 
 	/*
 	 * attnum is the "attribute number" for the attribute:	A value that
@@ -75,13 +75,13 @@ CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BK
 	 *
 	 * Note that (attnum - 1) is often used as the index to an array.
 	 */
-	int2		attnum;
+	int16		attnum;
 
 	/*
 	 * attndims is the declared number of dimensions, if an array type,
 	 * otherwise zero.
 	 */
-	int4		attndims;
+	int32		attndims;
 
 	/*
 	 * fastgetattr() uses attcacheoff to cache byte offsets of attributes in
@@ -90,7 +90,7 @@ CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BK
 	 * descriptor, we may then update attcacheoff in the copies. This speeds
 	 * up the attribute walking process.
 	 */
-	int4		attcacheoff;
+	int32		attcacheoff;
 
 	/*
 	 * atttypmod records type-specific data supplied at table creation time
@@ -98,7 +98,7 @@ CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BK
 	 * type-specific input and output functions as the third argument. The
 	 * value will generally be -1 for types that do not need typmod.
 	 */
-	int4		atttypmod;
+	int32		atttypmod;
 
 	/*
 	 * attbyval is a copy of the typbyval field from pg_type for this
@@ -140,7 +140,7 @@ CATALOG(pg_attribute,1249) BKI_BOOTSTRAP BKI_WITHOUT_OIDS BKI_ROWTYPE_OID(75) BK
 	bool		attislocal;
 
 	/* Number of times inherited from direct parent relation(s) */
-	int4		attinhcount;
+	int32		attinhcount;
 
 	/* attribute's collation */
 	Oid			attcollation;
diff --git a/src/include/catalog/pg_authid.h b/src/include/catalog/pg_authid.h
index e96c875f58a..0843ce3c264 100644
--- a/src/include/catalog/pg_authid.h
+++ b/src/include/catalog/pg_authid.h
@@ -52,7 +52,7 @@ CATALOG(pg_authid,1260) BKI_SHARED_RELATION BKI_ROWTYPE_OID(2842) BKI_SCHEMA_MAC
 	bool		rolcatupdate;	/* allowed to alter catalogs manually? */
 	bool		rolcanlogin;	/* allowed to log in as session user? */
 	bool		rolreplication; /* role used for streaming replication */
-	int4		rolconnlimit;	/* max connections allowed (-1=no limit) */
+	int32		rolconnlimit;	/* max connections allowed (-1=no limit) */
 
 	/* remaining fields may be null; use heap_getattr to read them! */
 	text		rolpassword;	/* password, if any */
diff --git a/src/include/catalog/pg_class.h b/src/include/catalog/pg_class.h
index a3307b44337..f83ce80a603 100644
--- a/src/include/catalog/pg_class.h
+++ b/src/include/catalog/pg_class.h
@@ -43,9 +43,9 @@ CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83) BKI_SCHEMA_MACRO
 
 	/* relfilenode == 0 means it is a "mapped" relation, see relmapper.c */
 	Oid			reltablespace;	/* identifier of table space for relation */
-	int4		relpages;		/* # of blocks (not always up-to-date) */
+	int32		relpages;		/* # of blocks (not always up-to-date) */
 	float4		reltuples;		/* # of tuples (not always up-to-date) */
-	int4		relallvisible;	/* # of all-visible blocks (not always
+	int32		relallvisible;	/* # of all-visible blocks (not always
 								 * up-to-date) */
 	Oid			reltoastrelid;	/* OID of toast table; 0 if none */
 	Oid			reltoastidxid;	/* if toast table, OID of chunk_id index */
@@ -53,14 +53,14 @@ CATALOG(pg_class,1259) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83) BKI_SCHEMA_MACRO
 	bool		relisshared;	/* T if shared across databases */
 	char		relpersistence; /* see RELPERSISTENCE_xxx constants below */
 	char		relkind;		/* see RELKIND_xxx constants below */
-	int2		relnatts;		/* number of user attributes */
+	int16		relnatts;		/* number of user attributes */
 
 	/*
 	 * Class pg_attribute must contain exactly "relnatts" user attributes
 	 * (with attnums ranging from 1 to relnatts) for this class.  It may also
 	 * contain entries with negative attnums for system attributes.
 	 */
-	int2		relchecks;		/* # of CHECK constraints for class */
+	int16		relchecks;		/* # of CHECK constraints for class */
 	bool		relhasoids;		/* T if we generate OIDs for rows of rel */
 	bool		relhaspkey;		/* has (or has had) PRIMARY KEY index */
 	bool		relhasrules;	/* has (or has had) any rules */
diff --git a/src/include/catalog/pg_collation.h b/src/include/catalog/pg_collation.h
index 8a1917e4f29..a578562b037 100644
--- a/src/include/catalog/pg_collation.h
+++ b/src/include/catalog/pg_collation.h
@@ -34,7 +34,7 @@ CATALOG(pg_collation,3456)
 	NameData	collname;		/* collation name */
 	Oid			collnamespace;	/* OID of namespace containing collation */
 	Oid			collowner;		/* owner of collation */
-	int4		collencoding;	/* encoding for this collation; -1 = "all" */
+	int32		collencoding;	/* encoding for this collation; -1 = "all" */
 	NameData	collcollate;	/* LC_COLLATE setting */
 	NameData	collctype;		/* LC_CTYPE setting */
 } FormData_pg_collation;
diff --git a/src/include/catalog/pg_constraint.h b/src/include/catalog/pg_constraint.h
index b9e4bf41f93..fc048ea7510 100644
--- a/src/include/catalog/pg_constraint.h
+++ b/src/include/catalog/pg_constraint.h
@@ -86,7 +86,7 @@ CATALOG(pg_constraint,2606)
 	bool		conislocal;
 
 	/* Number of times inherited from direct parent relation(s) */
-	int4		coninhcount;
+	int32		coninhcount;
 
 	/* Has a local definition and cannot be inherited */
 	bool		connoinherit;
@@ -97,12 +97,12 @@ CATALOG(pg_constraint,2606)
 	 * Columns of conrelid that the constraint applies to, if known (this is
 	 * NULL for trigger constraints)
 	 */
-	int2		conkey[1];
+	int16		conkey[1];
 
 	/*
 	 * If a foreign key, the referenced columns of confrelid
 	 */
-	int2		confkey[1];
+	int16		confkey[1];
 
 	/*
 	 * If a foreign key, the OIDs of the PK = FK equality operators for each
diff --git a/src/include/catalog/pg_conversion.h b/src/include/catalog/pg_conversion.h
index 04fe3e87064..318f9ca5cf1 100644
--- a/src/include/catalog/pg_conversion.h
+++ b/src/include/catalog/pg_conversion.h
@@ -42,8 +42,8 @@ CATALOG(pg_conversion,2607)
 	NameData	conname;
 	Oid			connamespace;
 	Oid			conowner;
-	int4		conforencoding;
-	int4		contoencoding;
+	int32		conforencoding;
+	int32		contoencoding;
 	regproc		conproc;
 	bool		condefault;
 } FormData_pg_conversion;
diff --git a/src/include/catalog/pg_database.h b/src/include/catalog/pg_database.h
index af803bba89b..d96628fe26c 100644
--- a/src/include/catalog/pg_database.h
+++ b/src/include/catalog/pg_database.h
@@ -33,12 +33,12 @@ CATALOG(pg_database,1262) BKI_SHARED_RELATION BKI_ROWTYPE_OID(1248) BKI_SCHEMA_M
 {
 	NameData	datname;		/* database name */
 	Oid			datdba;			/* owner of database */
-	int4		encoding;		/* character encoding */
+	int32		encoding;		/* character encoding */
 	NameData	datcollate;		/* LC_COLLATE setting */
 	NameData	datctype;		/* LC_CTYPE setting */
 	bool		datistemplate;	/* allowed as CREATE DATABASE template? */
 	bool		datallowconn;	/* new connections allowed? */
-	int4		datconnlimit;	/* max connections allowed (-1=no limit) */
+	int32		datconnlimit;	/* max connections allowed (-1=no limit) */
 	Oid			datlastsysoid;	/* highest OID to consider a system OID */
 	TransactionId datfrozenxid; /* all Xids < this are frozen in this DB */
 	Oid			dattablespace;	/* default table space for this DB */
diff --git a/src/include/catalog/pg_depend.h b/src/include/catalog/pg_depend.h
index e56dd1ad3d0..f547e815b78 100644
--- a/src/include/catalog/pg_depend.h
+++ b/src/include/catalog/pg_depend.h
@@ -37,14 +37,14 @@ CATALOG(pg_depend,2608) BKI_WITHOUT_OIDS
 	 */
 	Oid			classid;		/* OID of table containing object */
 	Oid			objid;			/* OID of object itself */
-	int4		objsubid;		/* column number, or 0 if not used */
+	int32		objsubid;		/* column number, or 0 if not used */
 
 	/*
 	 * Identification of the independent (referenced) object.
 	 */
 	Oid			refclassid;		/* OID of table containing object */
 	Oid			refobjid;		/* OID of object itself */
-	int4		refobjsubid;	/* column number, or 0 if not used */
+	int32		refobjsubid;	/* column number, or 0 if not used */
 
 	/*
 	 * Precise semantics of the relationship are specified by the deptype
diff --git a/src/include/catalog/pg_description.h b/src/include/catalog/pg_description.h
index a4541948930..c52e2dddff4 100644
--- a/src/include/catalog/pg_description.h
+++ b/src/include/catalog/pg_description.h
@@ -49,7 +49,7 @@ CATALOG(pg_description,2609) BKI_WITHOUT_OIDS
 {
 	Oid			objoid;			/* OID of object itself */
 	Oid			classoid;		/* OID of table containing object */
-	int4		objsubid;		/* column number, or 0 if not used */
+	int32		objsubid;		/* column number, or 0 if not used */
 
 #ifdef CATALOG_VARLEN			/* variable-length fields start here */
 	text		description;	/* description of object */
diff --git a/src/include/catalog/pg_index.h b/src/include/catalog/pg_index.h
index 9a86121cf9e..934fe97e5f2 100644
--- a/src/include/catalog/pg_index.h
+++ b/src/include/catalog/pg_index.h
@@ -32,7 +32,7 @@ CATALOG(pg_index,2610) BKI_WITHOUT_OIDS BKI_SCHEMA_MACRO
 {
 	Oid			indexrelid;		/* OID of the index */
 	Oid			indrelid;		/* OID of the relation it indexes */
-	int2		indnatts;		/* number of columns in index */
+	int16		indnatts;		/* number of columns in index */
 	bool		indisunique;	/* is this a unique index? */
 	bool		indisprimary;	/* is this index for primary key? */
 	bool		indisexclusion; /* is this index for exclusion constraint? */
diff --git a/src/include/catalog/pg_inherits.h b/src/include/catalog/pg_inherits.h
index 18552bde7ec..5ed78987c97 100644
--- a/src/include/catalog/pg_inherits.h
+++ b/src/include/catalog/pg_inherits.h
@@ -32,7 +32,7 @@ CATALOG(pg_inherits,2611) BKI_WITHOUT_OIDS
 {
 	Oid			inhrelid;
 	Oid			inhparent;
-	int4		inhseqno;
+	int32		inhseqno;
 } FormData_pg_inherits;
 
 /* ----------------
diff --git a/src/include/catalog/pg_largeobject.h b/src/include/catalog/pg_largeobject.h
index d442ec4e4a2..d0195eaed95 100644
--- a/src/include/catalog/pg_largeobject.h
+++ b/src/include/catalog/pg_largeobject.h
@@ -31,7 +31,7 @@
 CATALOG(pg_largeobject,2613) BKI_WITHOUT_OIDS
 {
 	Oid			loid;			/* Identifier of large object */
-	int4		pageno;			/* Page number (starting from 0) */
+	int32		pageno;			/* Page number (starting from 0) */
 
 	/* data has variable length, but we allow direct access; see inv_api.c */
 	bytea		data;			/* Data for page (may be zero-length) */
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 256f474bb4e..bee7154fd8c 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -50,8 +50,8 @@ CATALOG(pg_proc,1255) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81) BKI_SCHEMA_MACRO
 	bool		proisstrict;	/* strict with respect to NULLs? */
 	bool		proretset;		/* returns a set? */
 	char		provolatile;	/* see PROVOLATILE_ categories below */
-	int2		pronargs;		/* number of arguments */
-	int2		pronargdefaults;	/* number of arguments with defaults */
+	int16		pronargs;		/* number of arguments */
+	int16		pronargdefaults;	/* number of arguments with defaults */
 	Oid			prorettype;		/* OID of result type */
 
 	/*
diff --git a/src/include/catalog/pg_rewrite.h b/src/include/catalog/pg_rewrite.h
index 5171522da08..1ecdf1f3769 100644
--- a/src/include/catalog/pg_rewrite.h
+++ b/src/include/catalog/pg_rewrite.h
@@ -35,7 +35,7 @@ CATALOG(pg_rewrite,2618)
 {
 	NameData	rulename;
 	Oid			ev_class;
-	int2		ev_attr;
+	int16		ev_attr;
 	char		ev_type;
 	char		ev_enabled;
 	bool		is_instead;
diff --git a/src/include/catalog/pg_seclabel.h b/src/include/catalog/pg_seclabel.h
index 917efcf8ca9..26e2e52a1fe 100644
--- a/src/include/catalog/pg_seclabel.h
+++ b/src/include/catalog/pg_seclabel.h
@@ -24,7 +24,7 @@ CATALOG(pg_seclabel,3596) BKI_WITHOUT_OIDS
 {
 	Oid			objoid;			/* OID of the object itself */
 	Oid			classoid;		/* OID of table containing the object */
-	int4		objsubid;		/* column number, or 0 if not used */
+	int32		objsubid;		/* column number, or 0 if not used */
 
 #ifdef CATALOG_VARLEN			/* variable-length fields start here */
 	text		provider;		/* name of label provider */
diff --git a/src/include/catalog/pg_shdepend.h b/src/include/catalog/pg_shdepend.h
index 394fe43c582..33ec08a6a4d 100644
--- a/src/include/catalog/pg_shdepend.h
+++ b/src/include/catalog/pg_shdepend.h
@@ -39,7 +39,7 @@ CATALOG(pg_shdepend,1214) BKI_SHARED_RELATION BKI_WITHOUT_OIDS
 	Oid			dbid;			/* OID of database containing object */
 	Oid			classid;		/* OID of table containing object */
 	Oid			objid;			/* OID of object itself */
-	int4		objsubid;		/* column number, or 0 if not used */
+	int32		objsubid;		/* column number, or 0 if not used */
 
 	/*
 	 * Identification of the independent (referenced) object.  This is always
diff --git a/src/include/catalog/pg_statistic.h b/src/include/catalog/pg_statistic.h
index 3ad0c281102..8724cb50fa1 100644
--- a/src/include/catalog/pg_statistic.h
+++ b/src/include/catalog/pg_statistic.h
@@ -32,7 +32,7 @@ CATALOG(pg_statistic,2619) BKI_WITHOUT_OIDS
 {
 	/* These fields form the unique key for the entry: */
 	Oid			starelid;		/* relation containing attribute */
-	int2		staattnum;		/* attribute (column) stats are for */
+	int16		staattnum;		/* attribute (column) stats are for */
 	bool		stainherit;		/* true if inheritance children are included */
 
 	/* the fraction of the column's entries that are NULL: */
@@ -48,7 +48,7 @@ CATALOG(pg_statistic,2619) BKI_WITHOUT_OIDS
 	 * the statistic, which is to estimate sizes of in-memory hash tables of
 	 * tuples.
 	 */
-	int4		stawidth;
+	int32		stawidth;
 
 	/* ----------------
 	 * stadistinct indicates the (approximate) number of distinct non-null
@@ -84,11 +84,11 @@ CATALOG(pg_statistic,2619) BKI_WITHOUT_OIDS
 	 * ----------------
 	 */
 
-	int2		stakind1;
-	int2		stakind2;
-	int2		stakind3;
-	int2		stakind4;
-	int2		stakind5;
+	int16		stakind1;
+	int16		stakind2;
+	int16		stakind3;
+	int16		stakind4;
+	int16		stakind5;
 
 	Oid			staop1;
 	Oid			staop2;
diff --git a/src/include/catalog/pg_trigger.h b/src/include/catalog/pg_trigger.h
index 71afab58e56..fb3a99468ad 100644
--- a/src/include/catalog/pg_trigger.h
+++ b/src/include/catalog/pg_trigger.h
@@ -38,7 +38,7 @@ CATALOG(pg_trigger,2620)
 	Oid			tgrelid;		/* relation trigger is attached to */
 	NameData	tgname;			/* trigger's name */
 	Oid			tgfoid;			/* OID of function to be called */
-	int2		tgtype;			/* BEFORE/AFTER/INSTEAD, UPDATE/DELETE/INSERT,
+	int16		tgtype;			/* BEFORE/AFTER/INSTEAD, UPDATE/DELETE/INSERT,
 								 * ROW/STATEMENT; see below */
 	char		tgenabled;		/* trigger's firing configuration WRT
 								 * session_replication_role */
@@ -48,7 +48,7 @@ CATALOG(pg_trigger,2620)
 	Oid			tgconstraint;	/* associated pg_constraint entry, if any */
 	bool		tgdeferrable;	/* constraint trigger is deferrable */
 	bool		tginitdeferred; /* constraint trigger is deferred initially */
-	int2		tgnargs;		/* # of extra arguments in tgargs */
+	int16		tgnargs;		/* # of extra arguments in tgargs */
 
 	/*
 	 * Variable-length fields start here, but we allow direct access to
diff --git a/src/include/catalog/pg_ts_config_map.h b/src/include/catalog/pg_ts_config_map.h
index c3773381743..f85e1997266 100644
--- a/src/include/catalog/pg_ts_config_map.h
+++ b/src/include/catalog/pg_ts_config_map.h
@@ -33,8 +33,8 @@
 CATALOG(pg_ts_config_map,3603) BKI_WITHOUT_OIDS
 {
 	Oid			mapcfg;			/* OID of configuration owning this entry */
-	int4		maptokentype;	/* token type from parser */
-	int4		mapseqno;		/* order in which to consult dictionaries */
+	int32		maptokentype;	/* token type from parser */
+	int32		mapseqno;		/* order in which to consult dictionaries */
 	Oid			mapdict;		/* dictionary to consult */
 } FormData_pg_ts_config_map;
 
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 25c664b7c90..2865340982b 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -47,7 +47,7 @@ CATALOG(pg_type,1247) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71) BKI_SCHEMA_MACRO
 	 * "varlena" type (one that has a length word), -2 to indicate a
 	 * null-terminated C string.
 	 */
-	int2		typlen;
+	int16		typlen;
 
 	/*
 	 * typbyval determines whether internal Postgres routines pass a value of
@@ -185,13 +185,13 @@ CATALOG(pg_type,1247) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71) BKI_SCHEMA_MACRO
 	 * type (-1 if base type does not use a typmod).  -1 if this type is not a
 	 * domain.
 	 */
-	int4		typtypmod;
+	int32		typtypmod;
 
 	/*
 	 * typndims is the declared number of dimensions for an array domain type
 	 * (i.e., typbasetype is an array type).  Otherwise zero.
 	 */
-	int4		typndims;
+	int32		typndims;
 
 	/*
 	 * Collation: 0 if type cannot use collations, DEFAULT_COLLATION_OID for
diff --git a/src/include/commands/vacuum.h b/src/include/commands/vacuum.h
index 7a50d2fcb30..d1a3a9b0534 100644
--- a/src/include/commands/vacuum.h
+++ b/src/include/commands/vacuum.h
@@ -98,9 +98,9 @@ typedef struct VacAttrStats
 	 */
 	bool		stats_valid;
 	float4		stanullfrac;	/* fraction of entries that are NULL */
-	int4		stawidth;		/* average width of column values */
+	int32		stawidth;		/* average width of column values */
 	float4		stadistinct;	/* # distinct values */
-	int2		stakind[STATISTIC_NUM_SLOTS];
+	int16		stakind[STATISTIC_NUM_SLOTS];
 	Oid			staop[STATISTIC_NUM_SLOTS];
 	int			numnumbers[STATISTIC_NUM_SLOTS];
 	float4	   *stanumbers[STATISTIC_NUM_SLOTS];
@@ -114,7 +114,7 @@ typedef struct VacAttrStats
 	 * elements. It should then overwrite these fields.
 	 */
 	Oid			statypid[STATISTIC_NUM_SLOTS];
-	int2		statyplen[STATISTIC_NUM_SLOTS];
+	int16		statyplen[STATISTIC_NUM_SLOTS];
 	bool		statypbyval[STATISTIC_NUM_SLOTS];
 	char		statypalign[STATISTIC_NUM_SLOTS];
 
diff --git a/src/include/tsearch/ts_public.h b/src/include/tsearch/ts_public.h
index d5c18f2cf04..f8dffe060d9 100644
--- a/src/include/tsearch/ts_public.h
+++ b/src/include/tsearch/ts_public.h
@@ -49,14 +49,14 @@ typedef struct
 typedef struct
 {
 	HeadlineWordEntry *words;
-	int4		lenwords;
-	int4		curwords;
+	int32		lenwords;
+	int32		curwords;
 	char	   *startsel;
 	char	   *stopsel;
 	char	   *fragdelim;
-	int2		startsellen;
-	int2		stopsellen;
-	int2		fragdelimlen;
+	int16		startsellen;
+	int16		stopsellen;
+	int16		fragdelimlen;
 } HeadlineParsedText;
 
 /*
diff --git a/src/include/tsearch/ts_type.h b/src/include/tsearch/ts_type.h
index 3adc3369f9d..d80f7ade2be 100644
--- a/src/include/tsearch/ts_type.h
+++ b/src/include/tsearch/ts_type.h
@@ -21,7 +21,7 @@
  *
  * Structure of tsvector datatype:
  * 1) standard varlena header
- * 2) int4		size - number of lexemes (WordEntry array entries)
+ * 2) int32		size - number of lexemes (WordEntry array entries)
  * 3) Array of WordEntry - one per lexeme; must be sorted according to
  *				tsCompareString() (ie, memcmp of lexeme strings).
  *				WordEntry->pos gives the number of bytes from end of WordEntry
@@ -232,13 +232,13 @@ typedef union
 typedef struct
 {
 	int32		vl_len_;		/* varlena header (do not touch directly!) */
-	int4		size;			/* number of QueryItems */
+	int32		size;			/* number of QueryItems */
 	char		data[1];		/* data starts here */
 } TSQueryData;
 
 typedef TSQueryData *TSQuery;
 
-#define HDRSIZETQ	( VARHDRSZ + sizeof(int4) )
+#define HDRSIZETQ	( VARHDRSZ + sizeof(int32) )
 
 /* Computes the size of header and all QueryItems. size is the number of
  * QueryItems, and lenofoperand is the total length of all operands
diff --git a/src/include/tsearch/ts_utils.h b/src/include/tsearch/ts_utils.h
index 1db4c4f78b4..d3088fe517f 100644
--- a/src/include/tsearch/ts_utils.h
+++ b/src/include/tsearch/ts_utils.h
@@ -42,7 +42,7 @@ typedef struct TSQueryParserStateData *TSQueryParserState;
 
 typedef void (*PushFunction) (Datum opaque, TSQueryParserState state,
 										  char *token, int tokenlen,
-										  int2 tokenweights,	/* bitmap as described
+										  int16 tokenweights,	/* bitmap as described
 																 * in QueryOperand
 																 * struct */
 										  bool prefix);
@@ -53,7 +53,7 @@ extern TSQuery parse_tsquery(char *buf,
 
 /* Functions for use by PushFunction implementations */
 extern void pushValue(TSQueryParserState state,
-		  char *strval, int lenval, int2 weight, bool prefix);
+		  char *strval, int lenval, int16 weight, bool prefix);
 extern void pushStop(TSQueryParserState state);
 extern void pushOperator(TSQueryParserState state, int8 oper);
 
@@ -83,12 +83,12 @@ typedef struct
 typedef struct
 {
 	ParsedWord *words;
-	int4		lenwords;
-	int4		curwords;
-	int4		pos;
+	int32		lenwords;
+	int32		curwords;
+	int32		pos;
 } ParsedText;
 
-extern void parsetext(Oid cfgId, ParsedText *prs, char *buf, int4 buflen);
+extern void parsetext(Oid cfgId, ParsedText *prs, char *buf, int32 buflen);
 
 /*
  * headline framework, flow in common to generate:
@@ -98,7 +98,7 @@ extern void parsetext(Oid cfgId, ParsedText *prs, char *buf, int4 buflen);
  */
 
 extern void hlparsetext(Oid cfgId, HeadlineParsedText *prs, TSQuery query,
-			char *buf, int4 buflen);
+			char *buf, int32 buflen);
 extern text *generateHeadline(HeadlineParsedText *prs);
 
 /*
@@ -164,14 +164,14 @@ extern Datum gin_tsquery_consistent_6args(PG_FUNCTION_ARGS);
 /*
  * TSQuery Utilities
  */
-extern QueryItem *clean_NOT(QueryItem *ptr, int4 *len);
-extern QueryItem *clean_fakeval(QueryItem *ptr, int4 *len);
+extern QueryItem *clean_NOT(QueryItem *ptr, int32 *len);
+extern QueryItem *clean_fakeval(QueryItem *ptr, int32 *len);
 
 typedef struct QTNode
 {
 	QueryItem  *valnode;
 	uint32		flags;
-	int4		nchild;
+	int32		nchild;
 	char	   *word;
 	uint32		sign;
 	struct QTNode **child;
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index d1e83707606..10634039a44 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -256,7 +256,7 @@ extern Datum int2shl(PG_FUNCTION_ARGS);
 extern Datum int2shr(PG_FUNCTION_ARGS);
 extern Datum generate_series_int4(PG_FUNCTION_ARGS);
 extern Datum generate_series_step_int4(PG_FUNCTION_ARGS);
-extern int2vector *buildint2vector(const int2 *int2s, int n);
+extern int2vector *buildint2vector(const int16 *int2s, int n);
 
 /* name.c */
 extern Datum namein(PG_FUNCTION_ARGS);
diff --git a/src/interfaces/ecpg/ecpglib/sqlda.c b/src/interfaces/ecpg/ecpglib/sqlda.c
index 343a793c95d..bc94f2f8594 100644
--- a/src/interfaces/ecpg/ecpglib/sqlda.c
+++ b/src/interfaces/ecpg/ecpglib/sqlda.c
@@ -245,8 +245,8 @@ ecpg_build_compat_sqlda(int line, PGresult *res, int row, enum COMPAT_MODE compa
 /*
  * Sets values from PGresult.
  */
-static int2 value_is_null = -1;
-static int2 value_is_not_null = 0;
+static int16 value_is_null = -1;
+static int16 value_is_not_null = 0;
 
 void
 ecpg_set_compat_sqlda(int lineno, struct sqlda_compat ** _sqlda, const PGresult *res, int row, enum COMPAT_MODE compat)
-- 
GitLab