From 431d3c24158600b432f851d73b8678af658515ba Mon Sep 17 00:00:00 2001
From: John Naylor <jcnaylor@gmail.com>
Date: Sat, 23 Dec 2017 18:19:36 +0700
Subject: [PATCH v5 07/13] Remove OID #define symbols from catalog headers

The headers that had OID symbols now include them from oid_symbols.h,
a header generated by genbki.pl from the .dat files where the symbols
are stored. This requires an analog of FindDefinedSymbol() that retrieves
the symbol from the data.

Arrange for the new header to be generated before src/common gets built,
since some places outside of the backend require OID symbols to be visible.

Automatically sync ECPG's knowledge of pg_type OIDs with the backend
and fix an out-of-date type name in ecpg_is_type_an_array().
---
 src/backend/Makefile                  | 30 +++++++----
 src/backend/catalog/.gitignore        |  1 +
 src/backend/catalog/Catalog.pm        | 13 +++++
 src/backend/catalog/Makefile          | 10 ++--
 src/backend/catalog/genbki.pl         | 94 +++++++++++++++++++++++++---------
 src/backend/utils/Gen_fmgrtab.pl      |  2 +-
 src/backend/utils/Makefile            |  7 ++-
 src/common/Makefile                   |  7 ++-
 src/include/Makefile                  |  4 +-
 src/include/catalog/.gitignore        |  1 +
 src/include/catalog/pg_am.h           |  8 +--
 src/include/catalog/pg_authid.h       |  8 +--
 src/include/catalog/pg_collation.h    |  5 +-
 src/include/catalog/pg_database.h     |  3 +-
 src/include/catalog/pg_language.h     |  5 +-
 src/include/catalog/pg_namespace.h    |  5 +-
 src/include/catalog/pg_opclass.h      | 12 +----
 src/include/catalog/pg_operator.h     | 51 +------------------
 src/include/catalog/pg_opfamily.h     | 14 +-----
 src/include/catalog/pg_tablespace.h   |  1 +
 src/include/catalog/pg_type.h         | 95 +----------------------------------
 src/interfaces/ecpg/ecpglib/execute.c |  2 +-
 src/interfaces/ecpg/ecpglib/pg_type.h | 65 +-----------------------
 src/tools/msvc/Solution.pm            |  5 +-
 src/tools/msvc/clean.bat              |  2 +
 25 files changed, 143 insertions(+), 307 deletions(-)

diff --git a/src/backend/Makefile b/src/backend/Makefile
index a0655e4..431249e 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -119,6 +119,10 @@ submake-errcodes: $(top_builddir)/src/include/utils/errcodes.h
 
 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
 
+# src/common/ needs a convenient way to force just oid_symbols.h to get built
+submake-oidsymbols: $(top_builddir)/src/include/catalog/oid_symbols.h
+
+.PHONY: submake-oidsymbols
 
 # The postgres.o target is needed by the rule in Makefile.global that
 # creates the exports file when MAKE_EXPORTS = true.
@@ -142,13 +146,15 @@ utils/errcodes.h: utils/generate-errcodes.pl utils/errcodes.txt
 # see explanation in parser/Makefile
 utils/fmgrprotos.h: utils/fmgroids.h ;
 
-utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.dat $(top_srcdir)/src/include/access/transam.h
+utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.dat $(top_srcdir)/src/include/catalog/pg_language.dat $(top_srcdir)/src/include/access/transam.h
 	$(MAKE) -C utils $(notdir $@)
 
 utils/probes.h: utils/probes.d
 	$(MAKE) -C utils probes.h
 
 # run this unconditionally to avoid needing to know its dependencies here:
+catalog/oid_symbols.h: catalog/schemapg.h ;
+
 catalog/schemapg.h: | submake-schemapg
 
 submake-schemapg:
@@ -167,15 +173,24 @@ submake-schemapg:
 # will be in the build tree, so a simple ../.. reference won't work.
 # For headers generated during regular builds, we prefer a relative symlink.
 
+GENERATED_HEADERS = $(addprefix $(top_builddir)/src/include/,\
+	parser/gram.h catalog/oid_symbols.h catalog/schemapg.h storage/lwlocknames.h \
+	utils/errcodes.h utils/fmgroids.h utils/fmgrprotos.h utils/probes.h)
+
 .PHONY: generated-headers
 
-generated-headers: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/catalog/schemapg.h $(top_builddir)/src/include/storage/lwlocknames.h $(top_builddir)/src/include/utils/errcodes.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/fmgrprotos.h $(top_builddir)/src/include/utils/probes.h
+generated-headers: $(GENERATED_HEADERS)
 
 $(top_builddir)/src/include/parser/gram.h: parser/gram.h
 	prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
 	  cd '$(dir $@)' && rm -f $(notdir $@) && \
 	  $(LN_S) "$$prereqdir/$(notdir $<)" .
 
+$(top_builddir)/src/include/catalog/oid_symbols.h: catalog/oid_symbols.h
+	prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
+	  cd '$(dir $@)' && rm -f $(notdir $@) && \
+	  $(LN_S) "$$prereqdir/$(notdir $<)" .
+
 $(top_builddir)/src/include/catalog/schemapg.h: catalog/schemapg.h
 	prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
 	  cd '$(dir $@)' && rm -f $(notdir $@) && \
@@ -216,7 +231,7 @@ utils/probes.o: utils/probes.d $(SUBDIROBJS)
 distprep:
 	$(MAKE) -C parser	gram.c gram.h scan.c
 	$(MAKE) -C bootstrap	bootparse.c bootscanner.c
-	$(MAKE) -C catalog	schemapg.h postgres.bki postgres.description postgres.shdescription
+	$(MAKE) -C catalog	oid_symbols.h schemapg.h postgres.bki postgres.description postgres.shdescription
 	$(MAKE) -C replication	repl_gram.c repl_scanner.c syncrep_gram.c syncrep_scanner.c
 	$(MAKE) -C storage/lmgr	lwlocknames.h
 	$(MAKE) -C utils	fmgrtab.c fmgroids.h fmgrprotos.h errcodes.h
@@ -306,13 +321,7 @@ endif
 ##########################################################################
 
 clean:
-	rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) \
-		$(top_builddir)/src/include/parser/gram.h \
-		$(top_builddir)/src/include/catalog/schemapg.h \
-		$(top_builddir)/src/include/storage/lwlocknames.h \
-		$(top_builddir)/src/include/utils/fmgroids.h \
-		$(top_builddir)/src/include/utils/fmgrprotos.h \
-		$(top_builddir)/src/include/utils/probes.h
+	rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) $(GENERATED_HEADERS)
 ifeq ($(PORTNAME), cygwin)
 	rm -f postgres.dll libpostgres.a
 endif
@@ -329,6 +338,7 @@ maintainer-clean: distclean
 	      parser/gram.c \
 	      parser/gram.h \
 	      parser/scan.c \
+	      catalog/oid_symbols.h \
 	      catalog/schemapg.h \
 	      catalog/postgres.bki \
 	      catalog/postgres.description \
diff --git a/src/backend/catalog/.gitignore b/src/backend/catalog/.gitignore
index 557af3c..1398e2d 100644
--- a/src/backend/catalog/.gitignore
+++ b/src/backend/catalog/.gitignore
@@ -2,3 +2,4 @@
 /postgres.description
 /postgres.shdescription
 /schemapg.h
+/oid_symbols.h
diff --git a/src/backend/catalog/Catalog.pm b/src/backend/catalog/Catalog.pm
index da251bb..9d37674 100644
--- a/src/backend/catalog/Catalog.pm
+++ b/src/backend/catalog/Catalog.pm
@@ -347,4 +347,17 @@ sub FindDefinedSymbol
 	die "$catalog_header: not found in any include directory\n";
 }
 
+sub FindDefinedSymbolFromData
+{
+	my ($data, $symbol) = @_;
+	foreach my $row (@{ $data })
+	{
+		if ($row->{oid_symbol} eq $symbol)
+		{
+			return $row->{oid};
+		}
+		die "no definition found for $symbol\n";
+	}
+}
+
 1;
diff --git a/src/backend/catalog/Makefile b/src/backend/catalog/Makefile
index 4f3a5ea..270dc9e 100644
--- a/src/backend/catalog/Makefile
+++ b/src/backend/catalog/Makefile
@@ -22,7 +22,7 @@ BKIFILES = postgres.bki postgres.description postgres.shdescription
 
 include $(top_srcdir)/src/backend/common.mk
 
-all: $(BKIFILES) schemapg.h
+all: $(BKIFILES) oid_symbols.h schemapg.h
 
 # Note: there are some undocumented dependencies on the ordering in which
 # the catalog header files are assembled into postgres.bki.  In particular,
@@ -54,15 +54,11 @@ POSTGRES_BKI_DATA = $(wildcard $(top_srcdir)/src/include/catalog/*.dat)
 # location of Catalog.pm
 catalogdir = $(top_srcdir)/src/backend/catalog
 
-# locations of headers that genbki.pl needs to read
-pg_includes = -I$(top_srcdir)/src/include/catalog -I$(top_builddir)/src/include/catalog
-
 # see explanation in ../parser/Makefile
 postgres.description: postgres.bki ;
-
 postgres.shdescription: postgres.bki ;
-
 schemapg.h: postgres.bki ;
+oid_symbols.h: postgres.bki ;
 
 # Technically, this should depend on Makefile.global, but then
 # postgres.bki would need to be rebuilt after every configure run,
@@ -71,7 +67,7 @@ schemapg.h: postgres.bki ;
 # changes.
 postgres.bki: genbki.pl Catalog.pm $(POSTGRES_BKI_SRCS) $(POSTGRES_BKI_DATA) $(top_srcdir)/configure $(top_srcdir)/src/include/catalog/duplicate_oids
 	cd $(top_srcdir)/src/include/catalog && $(PERL) ./duplicate_oids
-	$(PERL) -I $(catalogdir) $< $(pg_includes) --set-version=$(MAJORVERSION) $(POSTGRES_BKI_SRCS)
+	$(PERL) -I $(catalogdir) $< --set-version=$(MAJORVERSION) $(POSTGRES_BKI_SRCS)
 
 .PHONY: install-data
 install-data: $(BKIFILES) installdirs
diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl
index f941826..bc52bc6 100644
--- a/src/backend/catalog/genbki.pl
+++ b/src/backend/catalog/genbki.pl
@@ -20,7 +20,6 @@ use strict;
 use warnings;
 
 my @input_files;
-my @include_path;
 my $output_path = '';
 my $major_version;
 
@@ -36,10 +35,6 @@ while (@ARGV)
 	{
 		$output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
 	}
-	elsif ($arg =~ /^-I/)
-	{
-		push @include_path, length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
-	}
 	elsif ($arg =~ /^--set-version=(.*)$/)
 	{
 		$major_version = $1;
@@ -53,8 +48,7 @@ while (@ARGV)
 }
 
 # Sanity check arguments.
-die "No input files.\n"                                     if !@input_files;
-die "No include path; you must specify -I at least once.\n" if !@include_path;
+die "No input files.\n"                  if !@input_files;
 die "--set-version must be specified.\n" if !defined $major_version;
 
 # Make sure output_path ends in a slash.
@@ -77,21 +71,9 @@ open my $descr, '>', $descrfile . $tmpext
 my $shdescrfile = $output_path . 'postgres.shdescription';
 open my $shdescr, '>', $shdescrfile . $tmpext
   or die "can't open $shdescrfile$tmpext: $!";
-
-# Fetch some special data that we will substitute into the output file.
-# CAUTION: be wary about what symbols you substitute into the .bki file here!
-# It's okay to substitute things that are expected to be really constant
-# within a given Postgres release, such as fixed OIDs.  Do not substitute
-# anything that could depend on platform or configuration.  (The right place
-# to handle those sorts of things is in initdb.c's bootstrap_template1().)
-# NB: make sure that the files used here are known to be part of the .bki
-# file's dependencies by src/backend/catalog/Makefile.
-my $BOOTSTRAP_SUPERUSERID =
-  Catalog::FindDefinedSymbol('pg_authid.h', \@include_path,
-							 'BOOTSTRAP_SUPERUSERID');
-my $PG_CATALOG_NAMESPACE =
-  Catalog::FindDefinedSymbol('pg_namespace.h', \@include_path,
-							 'PG_CATALOG_NAMESPACE');
+my $symbolfile = $output_path . 'oid_symbols.h';
+open my $symbol, '>', $symbolfile . $tmpext
+  or die "can't open $symbolfile$tmpext: $!";
 
 # Read all the files into internal data structures. Not all catalogs
 # will have a data file.
@@ -131,6 +113,17 @@ foreach my $header (@input_files)
 	}
 }
 
+# Fetch some special data that we will substitute into the output file.
+# CAUTION: be wary about what symbols you substitute into the .bki file here!
+# It's okay to substitute things that are expected to be really constant
+# within a given Postgres release, such as fixed OIDs.  Do not substitute
+# anything that could depend on platform or configuration.  (The right place
+# to handle those sorts of things is in initdb.c's bootstrap_template1().)
+my $BOOTSTRAP_SUPERUSERID =
+  Catalog::FindDefinedSymbolFromData($catalog_data{pg_authid}, 'BOOTSTRAP_SUPERUSERID');
+my $PG_CATALOG_NAMESPACE =
+  Catalog::FindDefinedSymbolFromData($catalog_data{pg_namespace}, 'PG_CATALOG_NAMESPACE');
+
 # Generate postgres.bki, postgres.description, and postgres.shdescription
 
 # version marker for .bki file
@@ -142,6 +135,10 @@ my @tables_needing_macros;
 my %regprocoids;
 my @types;
 
+# var to hold data for oid_symbols.h
+my %oid_symbols;
+my @tables_with_oid_symbols;
+
 # produce output, one catalog at a time
 foreach my $catname (@catnames)
 {
@@ -242,6 +239,21 @@ foreach my $catname (@catnames)
 				push @types, \%type;
 			}
 
+			# Store OID symbols for later.
+			if (exists $bki_values{oid_symbol})
+			{
+				if (!@tables_with_oid_symbols
+				    or $tables_with_oid_symbols[-1] ne $catname)
+				{
+					push @tables_with_oid_symbols, $catname;
+					$oid_symbols{$catname} = [];
+				}
+
+				push @{ $oid_symbols{$catname} },
+				  sprintf "#define %s %s",
+				    $bki_values{oid_symbol}, $bki_values{oid};
+			}
+
 			# Add quotes where necessary.
 			quote_bki_values(\%bki_values, $schema);
 
@@ -394,17 +406,54 @@ foreach my $table_name (@tables_needing_macros)
 # Closing boilerplate for schemapg.h
 print $schemapg "\n#endif /* SCHEMAPG_H */\n";
 
+# Generate oid_symbols.h
+
+# Opening boilerplate for oid_symbol.h
+print $symbol <<EOM;
+/*-------------------------------------------------------------------------
+ *
+ * oid_symbols.h
+ *    Oid symbols to be included in catalog headers.
+ *
+ * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * NOTES
+ *  ******************************
+ *  *** DO NOT EDIT THIS FILE! ***
+ *  ******************************
+ *
+ *  It has been GENERATED by src/backend/catalog/genbki.pl
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef OID_SYMBOLS_H
+#define OID_SYMBOLS_H
+EOM
+
+# Emit oid symbols
+foreach my $table_name (@tables_with_oid_symbols)
+{
+	print $symbol "\n\n/* $table_name */\n";
+	print $symbol join "\n", @{ $oid_symbols{$table_name} };
+}
+
+# Closing boilerplate for oid_symbols.h
+print $symbol "\n\n#endif /* OID_SYMBOLS_H */\n";
+
 # We're done emitting data
 close $bki;
 close $schemapg;
 close $descr;
 close $shdescr;
+close $symbol;
 
 # Finally, rename the completed files into place.
 Catalog::RenameTempFile($bkifile,     $tmpext);
 Catalog::RenameTempFile($schemafile,  $tmpext);
 Catalog::RenameTempFile($descrfile,   $tmpext);
 Catalog::RenameTempFile($shdescrfile, $tmpext);
+Catalog::RenameTempFile($symbolfile,  $tmpext);
 
 exit 0;
 
@@ -588,7 +637,6 @@ sub usage
 Usage: genbki.pl [options] header...
 
 Options:
-    -I               path to include files
     -o               output path
     --set-version    PostgreSQL version number for initdb cross-check
 
diff --git a/src/backend/utils/Gen_fmgrtab.pl b/src/backend/utils/Gen_fmgrtab.pl
index 2e9b6ad..dc6bac6 100644
--- a/src/backend/utils/Gen_fmgrtab.pl
+++ b/src/backend/utils/Gen_fmgrtab.pl
@@ -82,7 +82,7 @@ foreach my $datfile (@input_files)
 my $FirstBootstrapObjectId =
 	Catalog::FindDefinedSymbol('access/transam.h', \@include_path, 'FirstBootstrapObjectId');
 my $INTERNALlanguageId =
-	Catalog::FindDefinedSymbol('catalog/pg_language.h', \@include_path, 'INTERNALlanguageId');
+	Catalog::FindDefinedSymbolFromData($catalog_data{pg_language}, 'INTERNALlanguageId');
 
 # Collect certain fields from pg_proc.dat.
 my @fmgr = ();
diff --git a/src/backend/utils/Makefile b/src/backend/utils/Makefile
index f71cdc5..5a8a35c 100644
--- a/src/backend/utils/Makefile
+++ b/src/backend/utils/Makefile
@@ -11,6 +11,9 @@ include $(top_builddir)/src/Makefile.global
 OBJS        = fmgrtab.o
 SUBDIRS     = adt cache error fmgr hash init mb misc mmgr resowner sort time
 
+FMGR_DATA = $(addprefix $(top_srcdir)/src/include/catalog/,\
+	pg_proc.dat pg_language.dat)
+
 # location of Catalog.pm
 catalogdir  = $(top_srcdir)/src/backend/catalog
 
@@ -24,8 +27,8 @@ $(SUBDIRS:%=%-recursive): fmgroids.h fmgrprotos.h
 fmgrprotos.h: fmgroids.h ;
 fmgroids.h: fmgrtab.c ;
 
-fmgrtab.c: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.dat $(top_srcdir)/src/include/access/transam.h
-	$(PERL) -I $(catalogdir) $< -I $(top_srcdir)/src/include/ $(top_srcdir)/src/include/catalog/pg_proc.dat
+fmgrtab.c: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(FMGR_DATA) $(top_srcdir)/src/include/access/transam.h
+	$(PERL) -I $(catalogdir) $< -I $(top_srcdir)/src/include/ $(FMGR_DATA)
 
 errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl
 	$(PERL) $(srcdir)/generate-errcodes.pl $< > $@
diff --git a/src/common/Makefile b/src/common/Makefile
index 80e78d7..3a05d11 100644
--- a/src/common/Makefile
+++ b/src/common/Makefile
@@ -88,13 +88,18 @@ libpgcommon_srv.a: $(OBJS_SRV)
 %_srv.o: %.c %.o
 	$(CC) $(CFLAGS) $(subst -DFRONTEND ,, $(CPPFLAGS)) -c $< -o $@
 
-$(OBJS_SRV): | submake-errcodes
+$(OBJS_SRV): | submake-errcodes submake-oidsymbols
 
 .PHONY: submake-errcodes
 
 submake-errcodes:
 	$(MAKE) -C ../backend submake-errcodes
 
+.PHONY: submake-oidsymbols
+
+submake-oidsymbols:
+	$(MAKE) -C ../backend submake-oidsymbols
+
 # Dependencies of keywords.o need to be managed explicitly to make sure
 # that you don't get broken parsing code, even in a non-enable-depend build.
 # Note that gram.h isn't required for the frontend version of keywords.o.
diff --git a/src/include/Makefile b/src/include/Makefile
index a689d35..934f630 100644
--- a/src/include/Makefile
+++ b/src/include/Makefile
@@ -54,7 +54,7 @@ install: all installdirs
 	  chmod $(INSTALL_DATA_MODE) '$(DESTDIR)$(includedir_server)'/$$dir/*.h  || exit; \
 	done
 ifeq ($(vpath_build),yes)
-	for file in dynloader.h catalog/schemapg.h parser/gram.h storage/lwlocknames.h utils/probes.h; do \
+	for file in dynloader.h catalog/oid_symbols.h catalog/schemapg.h parser/gram.h storage/lwlocknames.h utils/probes.h; do \
 	  cp $$file '$(DESTDIR)$(includedir_server)'/$$file || exit; \
 	  chmod $(INSTALL_DATA_MODE) '$(DESTDIR)$(includedir_server)'/$$file || exit; \
 	done
@@ -73,7 +73,7 @@ uninstall:
 
 
 clean:
-	rm -f utils/fmgroids.h utils/fmgrprotos.h utils/errcodes.h parser/gram.h utils/probes.h catalog/schemapg.h
+	rm -f utils/fmgroids.h utils/fmgrprotos.h utils/errcodes.h parser/gram.h utils/probes.h catalog/oid_symbols.h catalog/schemapg.h
 
 distclean maintainer-clean: clean
 	rm -f pg_config.h pg_config_ext.h pg_config_os.h dynloader.h stamp-h stamp-ext-h
diff --git a/src/include/catalog/.gitignore b/src/include/catalog/.gitignore
index 650202e..4e6163f 100644
--- a/src/include/catalog/.gitignore
+++ b/src/include/catalog/.gitignore
@@ -1 +1,2 @@
 /schemapg.h
+/oid_symbols.h
diff --git a/src/include/catalog/pg_am.h b/src/include/catalog/pg_am.h
index d6807fa..b067ec1 100644
--- a/src/include/catalog/pg_am.h
+++ b/src/include/catalog/pg_am.h
@@ -20,6 +20,7 @@
 #define PG_AM_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /* ----------------
  *		pg_am definition.  cpp turns this into
@@ -57,11 +58,4 @@ typedef FormData_pg_am *Form_pg_am;
  */
 #define AMTYPE_INDEX					'i' /* index access method */
 
-#define BTREE_AM_OID 403
-#define HASH_AM_OID 405
-#define GIST_AM_OID 783
-#define GIN_AM_OID 2742
-#define SPGIST_AM_OID 4000
-#define BRIN_AM_OID 3580
-
 #endif							/* PG_AM_H */
diff --git a/src/include/catalog/pg_authid.h b/src/include/catalog/pg_authid.h
index ec31c93..18bd4c6 100644
--- a/src/include/catalog/pg_authid.h
+++ b/src/include/catalog/pg_authid.h
@@ -22,6 +22,7 @@
 #define PG_AUTHID_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /*
  * The CATALOG definition has to refer to the type of rolvaliduntil as
@@ -88,11 +89,4 @@ typedef FormData_pg_authid *Form_pg_authid;
 #define Anum_pg_authid_rolpassword		10
 #define Anum_pg_authid_rolvaliduntil	11
 
-#define BOOTSTRAP_SUPERUSERID			10
-#define DEFAULT_ROLE_MONITOR		3373
-#define DEFAULT_ROLE_READ_ALL_SETTINGS	3374
-#define DEFAULT_ROLE_READ_ALL_STATS 3375
-#define DEFAULT_ROLE_STAT_SCAN_TABLES	3377
-#define DEFAULT_ROLE_SIGNAL_BACKENDID	4200
-
 #endif							/* PG_AUTHID_H */
diff --git a/src/include/catalog/pg_collation.h b/src/include/catalog/pg_collation.h
index a02ef82..98aaf30 100644
--- a/src/include/catalog/pg_collation.h
+++ b/src/include/catalog/pg_collation.h
@@ -21,6 +21,7 @@
 #define PG_COLLATION_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /* ----------------
  *		pg_collation definition.  cpp turns this into
@@ -65,10 +66,6 @@ typedef FormData_pg_collation *Form_pg_collation;
 #define Anum_pg_collation_collctype		7
 #define Anum_pg_collation_collversion	8
 
-#define DEFAULT_COLLATION_OID	100
-#define C_COLLATION_OID			950
-#define POSIX_COLLATION_OID		951
-
 #define COLLPROVIDER_DEFAULT	'd'
 #define COLLPROVIDER_ICU		'i'
 #define COLLPROVIDER_LIBC		'c'
diff --git a/src/include/catalog/pg_database.h b/src/include/catalog/pg_database.h
index 159c6ec..9617a8a 100644
--- a/src/include/catalog/pg_database.h
+++ b/src/include/catalog/pg_database.h
@@ -20,6 +20,7 @@
 #define PG_DATABASE_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /* ----------------
  *		pg_database definition.  cpp turns this into
@@ -75,6 +76,4 @@ typedef FormData_pg_database *Form_pg_database;
 #define Anum_pg_database_dattablespace	12
 #define Anum_pg_database_datacl			13
 
-#define TemplateDbOid			1
-
 #endif							/* PG_DATABASE_H */
diff --git a/src/include/catalog/pg_language.h b/src/include/catalog/pg_language.h
index 055cddc..02de79d 100644
--- a/src/include/catalog/pg_language.h
+++ b/src/include/catalog/pg_language.h
@@ -20,6 +20,7 @@
 #define PG_LANGUAGE_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /* ----------------
  *		pg_language definition.  cpp turns this into
@@ -64,8 +65,4 @@ typedef FormData_pg_language *Form_pg_language;
 #define Anum_pg_language_lanvalidator	7
 #define Anum_pg_language_lanacl			8
 
-#define INTERNALlanguageId 12
-#define ClanguageId 13
-#define SQLlanguageId 14
-
 #endif							/* PG_LANGUAGE_H */
diff --git a/src/include/catalog/pg_namespace.h b/src/include/catalog/pg_namespace.h
index 9fa6418..c3a0737 100644
--- a/src/include/catalog/pg_namespace.h
+++ b/src/include/catalog/pg_namespace.h
@@ -20,6 +20,7 @@
 #define PG_NAMESPACE_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /* ----------------------------------------------------------------
  *		pg_namespace definition.
@@ -60,10 +61,6 @@ typedef FormData_pg_namespace *Form_pg_namespace;
 #define Anum_pg_namespace_nspowner		2
 #define Anum_pg_namespace_nspacl		3
 
-#define PG_CATALOG_NAMESPACE 11
-#define PG_TOAST_NAMESPACE 99
-#define PG_PUBLIC_NAMESPACE 2200
-
 /*
  * prototypes for functions in pg_namespace.c
  */
diff --git a/src/include/catalog/pg_opclass.h b/src/include/catalog/pg_opclass.h
index f37675a..51d58f2 100644
--- a/src/include/catalog/pg_opclass.h
+++ b/src/include/catalog/pg_opclass.h
@@ -40,6 +40,7 @@
 #define PG_OPCLASS_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /* ----------------
  *		pg_opclass definition.  cpp turns this into
@@ -81,15 +82,4 @@ typedef FormData_pg_opclass *Form_pg_opclass;
 #define Anum_pg_opclass_opcdefault		7
 #define Anum_pg_opclass_opckeytype		8
 
-#define DATE_BTREE_OPS_OID 3122
-#define FLOAT8_BTREE_OPS_OID 3123
-#define INT2_BTREE_OPS_OID 1979
-#define INT4_BTREE_OPS_OID 1978
-#define INT8_BTREE_OPS_OID 3124
-#define NUMERIC_BTREE_OPS_OID 3125
-#define OID_BTREE_OPS_OID 1981
-#define TEXT_BTREE_OPS_OID 3126
-#define TIMESTAMPTZ_BTREE_OPS_OID 3127
-#define TIMESTAMP_BTREE_OPS_OID 3128
-
 #endif							/* PG_OPCLASS_H */
diff --git a/src/include/catalog/pg_operator.h b/src/include/catalog/pg_operator.h
index 3b1ff2c..3f630d8 100644
--- a/src/include/catalog/pg_operator.h
+++ b/src/include/catalog/pg_operator.h
@@ -20,6 +20,7 @@
 #define PG_OPERATOR_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /* ----------------
  *		pg_operator definition.  cpp turns this into
@@ -74,54 +75,4 @@ typedef FormData_pg_operator *Form_pg_operator;
 #define Anum_pg_operator_oprrest		13
 #define Anum_pg_operator_oprjoin		14
 
-#define BooleanNotEqualOperator   85
-#define BooleanEqualOperator   91
-#define Int4EqualOperator	96
-#define Int4LessOperator	97
-#define TextEqualOperator	98
-#define TIDEqualOperator   387
-#define TIDLessOperator    2799
-#define Int8LessOperator	412
-#define OID_NAME_REGEXEQ_OP		639
-#define OID_TEXT_REGEXEQ_OP		641
-#define Float8LessOperator	672
-#define OID_BPCHAR_REGEXEQ_OP		1055
-#define ARRAY_EQ_OP 1070
-#define ARRAY_LT_OP 1072
-#define ARRAY_GT_OP 1073
-#define OID_NAME_LIKE_OP		1207
-#define OID_TEXT_LIKE_OP		1209
-#define OID_BPCHAR_LIKE_OP		1211
-#define OID_NAME_ICREGEXEQ_OP		1226
-#define OID_TEXT_ICREGEXEQ_OP		1228
-#define OID_BPCHAR_ICREGEXEQ_OP		1234
-#define OID_INET_SUB_OP			931
-#define OID_INET_SUBEQ_OP		932
-#define OID_INET_SUP_OP			933
-#define OID_INET_SUPEQ_OP		934
-#define OID_INET_OVERLAP_OP		3552
-#define OID_NAME_ICLIKE_OP		1625
-#define OID_TEXT_ICLIKE_OP		1627
-#define OID_BPCHAR_ICLIKE_OP	1629
-#define OID_BYTEA_LIKE_OP		2016
-#define OID_ARRAY_OVERLAP_OP	2750
-#define OID_ARRAY_CONTAINS_OP	2751
-#define OID_ARRAY_CONTAINED_OP	2752
-#define RECORD_EQ_OP 2988
-#define RECORD_LT_OP 2990
-#define RECORD_GT_OP 2991
-#define OID_RANGE_LESS_OP 3884
-#define OID_RANGE_LESS_EQUAL_OP 3885
-#define OID_RANGE_GREATER_EQUAL_OP 3886
-#define OID_RANGE_GREATER_OP 3887
-#define OID_RANGE_OVERLAP_OP 3888
-#define OID_RANGE_CONTAINS_ELEM_OP 3889
-#define OID_RANGE_CONTAINS_OP 3890
-#define OID_RANGE_ELEM_CONTAINED_OP 3891
-#define OID_RANGE_CONTAINED_OP 3892
-#define OID_RANGE_LEFT_OP 3893
-#define OID_RANGE_RIGHT_OP 3894
-#define OID_RANGE_OVERLAPS_LEFT_OP 3895
-#define OID_RANGE_OVERLAPS_RIGHT_OP 3896
-
 #endif							/* PG_OPERATOR_H */
diff --git a/src/include/catalog/pg_opfamily.h b/src/include/catalog/pg_opfamily.h
index 500abab..b988bc5 100644
--- a/src/include/catalog/pg_opfamily.h
+++ b/src/include/catalog/pg_opfamily.h
@@ -20,6 +20,7 @@
 #define PG_OPFAMILY_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /* ----------------
  *		pg_opfamily definition. cpp turns this into
@@ -53,17 +54,4 @@ typedef FormData_pg_opfamily *Form_pg_opfamily;
 #define Anum_pg_opfamily_opfnamespace	3
 #define Anum_pg_opfamily_opfowner		4
 
-#define BOOL_BTREE_FAM_OID 424
-#define BPCHAR_BTREE_FAM_OID 426
-#define BYTEA_BTREE_FAM_OID 428
-#define NETWORK_BTREE_FAM_OID 1974
-#define INTEGER_BTREE_FAM_OID 1976
-#define NAME_BTREE_FAM_OID 1986
-#define OID_BTREE_FAM_OID 1989
-#define TEXT_BTREE_FAM_OID 1994
-#define TEXT_PATTERN_BTREE_FAM_OID 2095
-#define BPCHAR_PATTERN_BTREE_FAM_OID 2097
-#define BOOL_HASH_FAM_OID 2222
-#define TEXT_SPGIST_FAM_OID 4017
-
 #endif							/* PG_OPFAMILY_H */
diff --git a/src/include/catalog/pg_tablespace.h b/src/include/catalog/pg_tablespace.h
index cff69bd..0cf894a 100644
--- a/src/include/catalog/pg_tablespace.h
+++ b/src/include/catalog/pg_tablespace.h
@@ -20,6 +20,7 @@
 #define PG_TABLESPACE_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /* ----------------
  *		pg_tablespace definition.  cpp turns this into
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 213efa9..e2d4626 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -20,6 +20,7 @@
 #define PG_TYPE_H
 
 #include "catalog/genbki.h"
+#include "catalog/oid_symbols.h"
 
 /* ----------------
  *		pg_type definition.  cpp turns this into
@@ -268,100 +269,6 @@ typedef FormData_pg_type *Form_pg_type;
 #define Anum_pg_type_typdefault			29
 #define Anum_pg_type_typacl				30
 
-#define BOOLOID			16
-#define BYTEAOID		17
-#define CHAROID			18
-#define NAMEOID			19
-#define INT8OID			20
-#define INT2OID			21
-#define INT2VECTOROID	22
-#define INT4OID			23
-#define REGPROCOID		24
-#define TEXTOID			25
-#define OIDOID			26
-#define TIDOID		27
-#define XIDOID 28
-#define CIDOID 29
-#define OIDVECTOROID	30
-#define JSONOID 114
-#define XMLOID 142
-#define PGNODETREEOID	194
-#define PGNDISTINCTOID	3361
-#define PGDEPENDENCIESOID	3402
-#define PGDDLCOMMANDOID 32
-#define POINTOID		600
-#define LSEGOID			601
-#define PATHOID			602
-#define BOXOID			603
-#define POLYGONOID		604
-#define LINEOID			628
-#define FLOAT4OID 700
-#define FLOAT8OID 701
-#define ABSTIMEOID		702
-#define RELTIMEOID		703
-#define TINTERVALOID	704
-#define UNKNOWNOID		705
-#define CIRCLEOID		718
-#define CASHOID 790
-#define MACADDROID 829
-#define INETOID 869
-#define CIDROID 650
-#define MACADDR8OID 774
-#define INT2ARRAYOID		1005
-#define INT4ARRAYOID		1007
-#define TEXTARRAYOID		1009
-#define OIDARRAYOID			1028
-#define FLOAT4ARRAYOID 1021
-#define ACLITEMOID		1033
-#define CSTRINGARRAYOID		1263
-#define BPCHAROID		1042
-#define VARCHAROID		1043
-#define DATEOID			1082
-#define TIMEOID			1083
-#define TIMESTAMPOID	1114
-#define TIMESTAMPTZOID	1184
-#define INTERVALOID		1186
-#define TIMETZOID		1266
-#define BITOID	 1560
-#define VARBITOID	  1562
-#define NUMERICOID		1700
-#define REFCURSOROID	1790
-#define REGPROCEDUREOID 2202
-#define REGOPEROID		2203
-#define REGOPERATOROID	2204
-#define REGCLASSOID		2205
-#define REGTYPEOID		2206
-#define REGROLEOID		4096
-#define REGNAMESPACEOID		4089
-#define REGTYPEARRAYOID 2211
-#define UUIDOID 2950
-#define LSNOID			3220
-#define TSVECTOROID		3614
-#define GTSVECTOROID	3642
-#define TSQUERYOID		3615
-#define REGCONFIGOID	3734
-#define REGDICTIONARYOID	3769
-#define JSONBOID 3802
-#define INT4RANGEOID		3904
-#define RECORDOID		2249
-#define RECORDARRAYOID	2287
-#define CSTRINGOID		2275
-#define ANYOID			2276
-#define ANYARRAYOID		2277
-#define VOIDOID			2278
-#define TRIGGEROID		2279
-#define EVTTRIGGEROID		3838
-#define LANGUAGE_HANDLEROID		2280
-#define INTERNALOID		2281
-#define OPAQUEOID		2282
-#define ANYELEMENTOID	2283
-#define ANYNONARRAYOID	2776
-#define ANYENUMOID		3500
-#define FDW_HANDLEROID	3115
-#define INDEX_AM_HANDLEROID 325
-#define TSM_HANDLEROID	3310
-#define ANYRANGEOID		3831
-
 /*
  * macros
  */
diff --git a/src/interfaces/ecpg/ecpglib/execute.c b/src/interfaces/ecpg/ecpglib/execute.c
index 7d6d7d0..0404385 100644
--- a/src/interfaces/ecpg/ecpglib/execute.c
+++ b/src/interfaces/ecpg/ecpglib/execute.c
@@ -255,7 +255,7 @@ ecpg_is_type_an_array(int type, const struct statement *stmt, const struct varia
 			return ECPG_ARRAY_ERROR;
 		if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), TIMETZOID, ECPG_ARRAY_NONE, stmt->lineno))
 			return ECPG_ARRAY_ERROR;
-		if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), ZPBITOID, ECPG_ARRAY_NONE, stmt->lineno))
+		if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), BITOID, ECPG_ARRAY_NONE, stmt->lineno))
 			return ECPG_ARRAY_ERROR;
 		if (!ecpg_type_infocache_push(&(stmt->connection->cache_head), VARBITOID, ECPG_ARRAY_NONE, stmt->lineno))
 			return ECPG_ARRAY_ERROR;
diff --git a/src/interfaces/ecpg/ecpglib/pg_type.h b/src/interfaces/ecpg/ecpglib/pg_type.h
index 94d2d92..970dfe3 100644
--- a/src/interfaces/ecpg/ecpglib/pg_type.h
+++ b/src/interfaces/ecpg/ecpglib/pg_type.h
@@ -1,9 +1,7 @@
 /*-------------------------------------------------------------------------
  *
  * pg_type.h
- *	  Hard-wired knowledge about some standard type OIDs.
- *
- * XXX keep this in sync with src/include/catalog/pg_type.h
+ *	  Reference of defined symbols for type OIDs.
  *
  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
@@ -15,65 +13,6 @@
 #ifndef PG_TYPE_H
 #define PG_TYPE_H
 
-#define BOOLOID			16
-#define BYTEAOID		17
-#define CHAROID			18
-#define NAMEOID			19
-#define INT8OID			20
-#define INT2OID			21
-#define INT2VECTOROID	22
-#define INT4OID			23
-#define REGPROCOID		24
-#define TEXTOID			25
-#define OIDOID			26
-#define TIDOID		27
-#define XIDOID 28
-#define CIDOID 29
-#define OIDVECTOROID	30
-#define POINTOID		600
-#define LSEGOID			601
-#define PATHOID			602
-#define BOXOID			603
-#define POLYGONOID		604
-#define LINEOID			628
-#define FLOAT4OID 700
-#define FLOAT8OID 701
-#define ABSTIMEOID		702
-#define RELTIMEOID		703
-#define TINTERVALOID	704
-#define UNKNOWNOID		705
-#define CIRCLEOID		718
-#define CASHOID 790
-#define INETOID 869
-#define CIDROID 650
-#define BPCHAROID		1042
-#define VARCHAROID		1043
-#define DATEOID			1082
-#define TIMEOID			1083
-#define TIMESTAMPOID	1114
-#define TIMESTAMPTZOID	1184
-#define INTERVALOID		1186
-#define TIMETZOID		1266
-#define ZPBITOID	 1560
-#define VARBITOID	  1562
-#define NUMERICOID		1700
-#define REFCURSOROID	1790
-#define REGPROCEDUREOID 2202
-#define REGOPEROID		2203
-#define REGOPERATOROID	2204
-#define REGCLASSOID		2205
-#define REGTYPEOID		2206
-#define REGROLEOID		4096
-#define REGNAMESPACEOID		4089
-#define REGTYPEARRAYOID 2211
-#define UUIDOID 2950
-#define LSNOID			3220
-#define TSVECTOROID		3614
-#define GTSVECTOROID	3642
-#define TSQUERYOID		3615
-#define REGCONFIGOID	3734
-#define REGDICTIONARYOID	3769
-#define JSONBOID 3802
-#define INT4RANGEOID		3904
+#include "catalog/oid_symbols.h"
 
 #endif							/* PG_TYPE_H */
diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm
index 6dcdd29..cdd3c1c 100644
--- a/src/tools/msvc/Solution.pm
+++ b/src/tools/msvc/Solution.pm
@@ -465,7 +465,7 @@ EOF
 				'src/backend/catalog/postgres.bki',
 				"src/include/catalog/$bki"))
 		{
-			print "Generating postgres.bki and schemapg.h...\n";
+			print "Generating postgres.bki, oid_symbols.h, schemapg.h...\n";
 			chdir('src/backend/catalog');
 			my $bki_srcs = join(' ../../../src/include/catalog/', @allbki);
 			system(
@@ -473,6 +473,9 @@ EOF
 			);
 			chdir('../../..');
 			copyFile(
+				'src/backend/catalog/oid_symbols.h',
+				'src/include/catalog/oid_symbols.h');
+			copyFile(
 				'src/backend/catalog/schemapg.h',
 				'src/include/catalog/schemapg.h');
 			last;
diff --git a/src/tools/msvc/clean.bat b/src/tools/msvc/clean.bat
index 0a88b52..ff99c0f 100755
--- a/src/tools/msvc/clean.bat
+++ b/src/tools/msvc/clean.bat
@@ -47,6 +47,7 @@ if exist src\include\utils\fmgroids.h del /q src\include\utils\fmgroids.h
 if exist src\include\utils\fmgrprotos.h del /q src\include\utils\fmgrprotos.h
 if exist src\include\storage\lwlocknames.h del /q src\include\storage\lwlocknames.h
 if exist src\include\utils\probes.h del /q src\include\utils\probes.h
+if exist src\include\catalog\oid_symbols.h del /q src\include\catalog\oid_symbols.h
 if exist src\include\catalog\schemapg.h del /q src\include\catalog\schemapg.h
 if exist doc\src\sgml\version.sgml del /q doc\src\sgml\version.sgml
 
@@ -66,6 +67,7 @@ if %DIST%==1 if exist src\interfaces\ecpg\preproc\preproc.y del /q src\interface
 if %DIST%==1 if exist src\backend\catalog\postgres.bki del /q src\backend\catalog\postgres.bki
 if %DIST%==1 if exist src\backend\catalog\postgres.description del /q src\backend\catalog\postgres.description
 if %DIST%==1 if exist src\backend\catalog\postgres.shdescription del /q src\backend\catalog\postgres.shdescription
+if %DIST%==1 if exist src\backend\catalog\oid_symbols.h del /q src\backend\catalog\oid_symbols.h
 if %DIST%==1 if exist src\backend\catalog\schemapg.h del /q src\backend\catalog\schemapg.h
 if %DIST%==1 if exist src\backend\parser\scan.c del /q src\backend\parser\scan.c
 if %DIST%==1 if exist src\backend\parser\gram.c del /q src\backend\parser\gram.c
-- 
2.7.4

