diff --git a/GNUmakefile.in b/GNUmakefile.in
index e131e13435aee2e010f8e05386e89f9415b370d6..7cdfb95473843b552baa00845218a7cefbdbde80 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -1,7 +1,7 @@
 #
 # PostgreSQL top level makefile
 #
-# $Header: /cvsroot/pgsql/GNUmakefile.in,v 1.16 2001/01/06 21:24:01 petere Exp $
+# $Header: /cvsroot/pgsql/GNUmakefile.in,v 1.17 2001/02/10 02:31:25 tgl Exp $
 #
 
 subdir =
@@ -22,6 +22,9 @@ installdirs uninstall distprep:
 	$(MAKE) -C doc $@
 	$(MAKE) -C src $@
 
+install-all-headers:
+	$(MAKE) -C src $@
+
 # clean, distclean, etc should apply to contrib too, even though
 # it's not built by default
 clean:
diff --git a/Makefile b/Makefile
index d0cdc303e67fee7bbabe7981a9fe475604388c56..9de7cce18092554aa7590c290111d3a8327479d3 100644
--- a/Makefile
+++ b/Makefile
@@ -11,7 +11,7 @@
 # GNUmakefile won't exist yet, so we catch that case as well.
 
 
-all check install installdirs installcheck uninstall dep depend clean distclean maintainer-clean:
+all check install installdirs install-all-headers installcheck uninstall dep depend clean distclean maintainer-clean:
 	@if [ ! -f GNUmakefile ] ; then \
 	   echo "You need to run the 'configure' program first. See the file"; \
 	   echo "'INSTALL' for installation instructions." ; \
diff --git a/contrib/cube/cubedata.h b/contrib/cube/cubedata.h
index 16495e74a57654e76d8338ec36646100632c6dd3..18bb6485464a4f4ee897c410a0098735e3aea6a5 100644
--- a/contrib/cube/cubedata.h
+++ b/contrib/cube/cubedata.h
@@ -1,5 +1,3 @@
-/*#include "postgres.h"*/
-
 typedef struct NDBOX {
   unsigned int size;			/* required to be a Postgres varlena type */
   unsigned int dim;
diff --git a/contrib/earthdistance/earthdistance.c b/contrib/earthdistance/earthdistance.c
index 7f2826a35b803e5d6eee3343786d5290b5354698..2383256be9b816662580bff03876dce81bd978cf 100644
--- a/contrib/earthdistance/earthdistance.c
+++ b/contrib/earthdistance/earthdistance.c
@@ -1,10 +1,9 @@
+#include "postgres.h"
+
 #include <math.h>
-#include <stdio.h>
-#include <string.h>
 
-#include <postgres.h>
-#include <utils/geo_decls.h>	/* for Pt */
-#include <utils/palloc.h>		/* for palloc */
+#include "utils/geo_decls.h"	/* for Pt */
+
 
 /* Earth's radius is in statute miles. */
 const int	EARTH_RADIUS = 3958.747716;
diff --git a/contrib/fulltextindex/fti.c b/contrib/fulltextindex/fti.c
index 75358958c5bf433df12bd5a81d403dc657bca5ca..1f9c398fea5ca2b2aeba035d8182f1d5b51fd557 100644
--- a/contrib/fulltextindex/fti.c
+++ b/contrib/fulltextindex/fti.c
@@ -1,8 +1,9 @@
 #include "postgres.h"
+
+#include <ctype.h>
+
 #include "executor/spi.h"
 #include "commands/trigger.h"
-#include <ctype.h>
-#include <stdio.h>				/* debugging */
 
 /*
  * Trigger function takes 2 arguments:
diff --git a/contrib/intarray/_int.c b/contrib/intarray/_int.c
index 6bfe2e1ae40f42c72318bc4695f68e72e1e9a875..c81e86237ec2faa1f9c5aa29d011a6da658d03d3 100644
--- a/contrib/intarray/_int.c
+++ b/contrib/intarray/_int.c
@@ -4,11 +4,11 @@
   format for these routines is dictated by Postgres architecture.
 ******************************************************************************/
 
-#include <stdio.h>
+#include "postgres.h"
+
 #include <float.h>
 #include <string.h>
 
-#include "postgres.h"
 #include "access/gist.h"
 #include "access/itup.h"
 #include "access/rtree.h"
diff --git a/contrib/isbn_issn/isbn_issn.c b/contrib/isbn_issn/isbn_issn.c
index 15d96d35db39f0562d0a0a5d33e28feceb4ec0a3..bc21a0622eaf95b72bd8950ee539fc125bdb5fcc 100644
--- a/contrib/isbn_issn/isbn_issn.c
+++ b/contrib/isbn_issn/isbn_issn.c
@@ -1,13 +1,11 @@
 /*
  *	PostgreSQL type definitions for ISBNs.
  *
- *	$Id: isbn_issn.c,v 1.2 2000/06/19 13:53:39 momjian Exp $
+ *	$Id: isbn_issn.c,v 1.3 2001/02/10 02:31:25 tgl Exp $
  */
 
-#include <stdio.h>
+#include "postgres.h"
 
-#include <postgres.h>
-#include <utils/palloc.h>
 
 /*
  *	This is the internal storage format for ISBNs.
diff --git a/contrib/lo/lo.c b/contrib/lo/lo.c
index 6f45394ac60ebe080eb0f79271a27b1e05ce51a1..33fa4cf98dd1d0991406c77d85a64d5bba217d22 100644
--- a/contrib/lo/lo.c
+++ b/contrib/lo/lo.c
@@ -1,16 +1,12 @@
 /*
  *	PostgreSQL type definitions for managed LargeObjects.
  *
- *	$Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.6 2000/11/21 21:51:58 tgl Exp $
+ *	$Header: /cvsroot/pgsql/contrib/lo/lo.c,v 1.7 2001/02/10 02:31:25 tgl Exp $
  *
  */
 
 #include "postgres.h"
 
-#include <stdio.h>
-
-#include "utils/palloc.h"
-
 /* Required for largeobjects */
 #include "libpq/libpq-fs.h"
 #include "libpq/be-fsstubs.h"
diff --git a/contrib/pg_dumplo/main.c b/contrib/pg_dumplo/main.c
index aa8ad104c1fc83ab18ba142d819e78d538bdcb75..e8ff2f72e095b7e9c063744dfd83af475a9e99f4 100644
--- a/contrib/pg_dumplo/main.c
+++ b/contrib/pg_dumplo/main.c
@@ -1,23 +1,23 @@
 /* -------------------------------------------------------------------------
  * pg_dumplo
  *
- * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.5 2001/01/24 19:42:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/contrib/pg_dumplo/Attic/main.c,v 1.6 2001/02/10 02:31:25 tgl Exp $
  *
  *					Karel Zak 1999-2000
  * -------------------------------------------------------------------------
  */
 
+/* We import postgres_fe.h mostly to get the HAVE_GETOPT_LONG configure result. */
+#ifndef OUT_OF_PG
+#include "postgres_fe.h"
+#endif
+
 #include <stdio.h>	
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>                            
 
-/* We import postgres.h mostly to get the HAVE_GETOPT_LONG configure result. */
-#ifndef OUT_OF_PG
-#include "postgres.h"
-#endif
-
 #include <libpq-fe.h>
 #include <libpq/libpq-fs.h>
 
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 866a41487adedb526847f51da8ec3af48caae932..bdbabded5b27bcb42e4c9dbef319a9e396307074 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -1,5 +1,5 @@
 /*
- * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.7 2000/11/01 00:45:46 ishii Exp $
+ * $Header: /cvsroot/pgsql/contrib/pgbench/pgbench.c,v 1.8 2001/02/10 02:31:25 tgl Exp $
  *
  * pgbench: a simple TPC-B like benchmark program for PostgreSQL
  * written by Tatsuo Ishii
@@ -17,11 +17,8 @@
  * suitability of this software for any purpose.  It is provided "as
  * is" without express or implied warranty.
  */
+#include "postgres_fe.h"
 
-#include "config.h"
-
-#include <stdio.h>
-#include "postgres.h"
 #include "libpq-fe.h"
 
 #include <errno.h>
diff --git a/contrib/pgcrypto/encode.c b/contrib/pgcrypto/encode.c
index 8875c41cdf679497d4d1e9fa6355162b677fc764..0ad0a8f56ce60ad34b8f8bd64d87c756ecea0fc0 100644
--- a/contrib/pgcrypto/encode.c
+++ b/contrib/pgcrypto/encode.c
@@ -26,11 +26,12 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: encode.c,v 1.2 2001/02/06 18:05:13 momjian Exp $
+ * $Id: encode.c,v 1.3 2001/02/10 02:31:25 tgl Exp $
  */
 
-#include <postgres.h>
-#include <fmgr.h>
+#include "postgres.h"
+
+#include "fmgr.h"
 
 #include "encode.h"
 
diff --git a/contrib/pgcrypto/internal.c b/contrib/pgcrypto/internal.c
index b1c24b20db993a070273ba330f00afa096dfed19..3c6e6fc80b7bb12ed191524444f41673eebe292a 100644
--- a/contrib/pgcrypto/internal.c
+++ b/contrib/pgcrypto/internal.c
@@ -26,10 +26,10 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: internal.c,v 1.1 2000/10/31 13:11:28 petere Exp $
+ * $Id: internal.c,v 1.2 2001/02/10 02:31:25 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "pgcrypto.h"
 
diff --git a/contrib/pgcrypto/krb.c b/contrib/pgcrypto/krb.c
index ab67f1ced12432f015b53a427ec1cf9ddba8a60c..98b16136a3d0cbdd2a80449ce8015ad365197bde 100644
--- a/contrib/pgcrypto/krb.c
+++ b/contrib/pgcrypto/krb.c
@@ -31,15 +31,15 @@
  *	It is possible that this works with other SHA1/MD5
  *	implementations too.
  *
- * $Id: krb.c,v 1.1 2000/10/31 13:11:28 petere Exp $
+ * $Id: krb.c,v 1.2 2001/02/10 02:31:25 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "pgcrypto.h"
 
-#include <md5.h>
-#include <sha.h>
+#include "md5.h"
+#include "sha.h"
 
 #ifndef MD5_DIGEST_LENGTH
 #define MD5_DIGEST_LENGTH 16
diff --git a/contrib/pgcrypto/md5.c b/contrib/pgcrypto/md5.c
index 9cdfa6e1aca7d027bf557d8c81bd16433eb08f82..d53872023126750dae06a0ffd83c2561fff3cd15 100644
--- a/contrib/pgcrypto/md5.c
+++ b/contrib/pgcrypto/md5.c
@@ -1,4 +1,4 @@
-/*	$Id: md5.c,v 1.3 2001/01/09 16:07:13 momjian Exp $	*/
+/*	$Id: md5.c,v 1.4 2001/02/10 02:31:25 tgl Exp $	*/
 /*     $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $     */
 
 /*
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "md5.h"
 
diff --git a/contrib/pgcrypto/mhash.c b/contrib/pgcrypto/mhash.c
index ed16c124dfc9de108026802531ae6ae61b37cf23..34ac7e9c7ac0073818dc2b0f8de5519ab9b9d289 100644
--- a/contrib/pgcrypto/mhash.c
+++ b/contrib/pgcrypto/mhash.c
@@ -26,10 +26,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: mhash.c,v 1.1 2000/10/31 13:11:28 petere Exp $
+ * $Id: mhash.c,v 1.2 2001/02/10 02:31:26 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
+
 #include "pgcrypto.h"
 
 #include <mhash.h>
diff --git a/contrib/pgcrypto/openssl.c b/contrib/pgcrypto/openssl.c
index 76a2a56b6723c73fa78fee5c919e5f8790c7a737..18fb07548877785e614ad37e0fcfa614061c8900 100644
--- a/contrib/pgcrypto/openssl.c
+++ b/contrib/pgcrypto/openssl.c
@@ -26,10 +26,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: openssl.c,v 1.1 2000/10/31 13:11:28 petere Exp $
+ * $Id: openssl.c,v 1.2 2001/02/10 02:31:26 tgl Exp $
  */
 
-#include <postgres.h>
+#include "postgres.h"
+
 #include "pgcrypto.h"
 
 #include <evp.h>
diff --git a/contrib/pgcrypto/pgcrypto.c b/contrib/pgcrypto/pgcrypto.c
index cfd7237494175917c5624c8768f3b90b5074039c..1feb3e4806aea309dc74e56d32de90963f30cb84 100644
--- a/contrib/pgcrypto/pgcrypto.c
+++ b/contrib/pgcrypto/pgcrypto.c
@@ -26,11 +26,12 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $Id: pgcrypto.c,v 1.5 2001/02/06 18:05:13 momjian Exp $
+ * $Id: pgcrypto.c,v 1.6 2001/02/10 02:31:26 tgl Exp $
  */
 
-#include <postgres.h>
-#include <utils/builtins.h>
+#include "postgres.h"
+
+#include "utils/builtins.h"
 
 #include "pgcrypto.h"
 
diff --git a/contrib/pgcrypto/sha1.c b/contrib/pgcrypto/sha1.c
index eef72325e99273018e1ceb8357b057b6314bc9ce..63c28dc7e945709932647614a52bed1801cc47cb 100644
--- a/contrib/pgcrypto/sha1.c
+++ b/contrib/pgcrypto/sha1.c
@@ -1,4 +1,4 @@
-/*	$Id: sha1.c,v 1.3 2001/01/09 16:07:13 momjian Exp $	*/
+/*	$Id: sha1.c,v 1.4 2001/02/10 02:31:26 tgl Exp $	*/
 /*     $KAME: sha1.c,v 1.3 2000/02/22 14:01:18 itojun Exp $    */
 
 /*
@@ -35,7 +35,7 @@
  * implemented by Jun-ichiro itojun Itoh <itojun@itojun.org>
  */
 
-#include <postgres.h>
+#include "postgres.h"
 
 #include "sha1.h"
 
diff --git a/contrib/soundex/soundex.c b/contrib/soundex/soundex.c
index 165202d5ef538319844ca0be35024780b5bc41c6..5a7e238e3804f611a5c5a1d63a8a1c40d3b3d114 100644
--- a/contrib/soundex/soundex.c
+++ b/contrib/soundex/soundex.c
@@ -1,10 +1,10 @@
-/* $Header: /cvsroot/pgsql/contrib/soundex/Attic/soundex.c,v 1.9 2000/12/03 20:45:31 tgl Exp $ */
+/* $Header: /cvsroot/pgsql/contrib/soundex/Attic/soundex.c,v 1.10 2001/02/10 02:31:26 tgl Exp $ */
 #include "postgres.h"
+
+#include <ctype.h>
+
 #include "fmgr.h"
 #include "utils/builtins.h"
-#include <ctype.h>
-#include <string.h>
-#include <stdio.h>
 
 
 Datum text_soundex(PG_FUNCTION_ARGS);
diff --git a/contrib/string/string_io.c b/contrib/string/string_io.c
index 8c4e5b45e1a9863a967f5654f41486d18b5953fe..840782dd51537d431f40d4e8f56ec97147fbe760 100644
--- a/contrib/string/string_io.c
+++ b/contrib/string/string_io.c
@@ -9,12 +9,10 @@
  * either version 2, or (at your option) any later version.
  */
 
+#include "postgres.h"
+
 #include <ctype.h>
-#include <string.h>
 
-#include "postgres.h"
-#include "utils/elog.h"
-#include "utils/palloc.h"
 #include "utils/builtins.h"
 
 #include "string_io.h"
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index a8a5f196c3c615ac002a6a953d39efca6098cd7b..11d3cb20d5fd7598893208ebbb4153b46f5e1c54 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -1,4 +1,4 @@
-<!-- $Header: /cvsroot/pgsql/doc/src/sgml/installation.sgml,v 1.34 2001/01/15 21:17:27 petere Exp $ -->
+<!-- $Header: /cvsroot/pgsql/doc/src/sgml/installation.sgml,v 1.35 2001/02/10 02:31:26 tgl Exp $ -->
 
 <chapter id="installation">
  <title><![%flattext-install-include[<productname>PostgreSQL</>]]> Installation Instructions</title>
@@ -783,11 +783,26 @@ All of PostgreSQL is successfully made. Ready to install.
     them, but how to do that is left as an exercise.
    </para>
 
+   <para>
+    The standard install installs only the header files needed for client
+    application development.  If you plan to do any server-side program
+    development (such as custom functions or datatypes written in C),
+    then you may want to install the entire <productname>PostgreSQL</>
+    include tree into your target include directory.  To do that, enter
+<screen>
+<userinput>gmake install-all-headers</userinput>
+</screen>
+    This adds a megabyte or two to the install footprint, and is only
+    useful if you don't plan to keep the whole source tree around for
+    reference.  (If you do, you can just use the source's include
+    directory when building server-side software.)
+   </para>
+
    <formalpara>
     <title>Client-only installation</title>
     <para>
      If you want to install only the client applications and
-     interfaces, then you can use these commands:
+     interface libraries, then you can use these commands:
 <screen>
 <userinput>gmake -C src/bin install</>
 <userinput>gmake -C src/interfaces install</>
diff --git a/src/GNUmakefile.in b/src/GNUmakefile.in
index 30322c22bad2b369ce1de8e8f3fb2469bdf12d26..8909a6226c7a94bb4351b9804b2dce47375c82af 100644
--- a/src/GNUmakefile.in
+++ b/src/GNUmakefile.in
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/Attic/GNUmakefile.in,v 1.60 2000/09/29 17:17:32 petere Exp $
+# $Header: /cvsroot/pgsql/src/Attic/GNUmakefile.in,v 1.61 2001/02/10 02:31:26 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -20,6 +20,9 @@ all install installdirs uninstall dep depend distprep:
 	$(MAKE) -C bin $@
 	$(MAKE) -C pl $@
 
+install-all-headers:
+	$(MAKE) -C include $@
+
 clean:
 	$(MAKE) -C backend $@
 	$(MAKE) -C include $@
diff --git a/src/Makefile b/src/Makefile
index d0cdc303e67fee7bbabe7981a9fe475604388c56..9de7cce18092554aa7590c290111d3a8327479d3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -11,7 +11,7 @@
 # GNUmakefile won't exist yet, so we catch that case as well.
 
 
-all check install installdirs installcheck uninstall dep depend clean distclean maintainer-clean:
+all check install installdirs install-all-headers installcheck uninstall dep depend clean distclean maintainer-clean:
 	@if [ ! -f GNUmakefile ] ; then \
 	   echo "You need to run the 'configure' program first. See the file"; \
 	   echo "'INSTALL' for installation instructions." ; \
diff --git a/src/backend/lib/dllist.c b/src/backend/lib/dllist.c
index 431c137d4d358cd4138563b04e830173ab7c4fd5..9f2135cc9ad6e26d980d5af47872417108c3798d 100644
--- a/src/backend/lib/dllist.c
+++ b/src/backend/lib/dllist.c
@@ -9,23 +9,22 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/lib/dllist.c,v 1.20 2001/01/24 19:42:55 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/lib/dllist.c,v 1.21 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
-#include "postgres.h"
-#include "lib/dllist.h"
-
-/* When this file is compiled for inclusion in libpq,
- * it can't use assert checking.  Probably this fix ought to be
- * in c.h or somewhere like that...
- */
+/* can be used in frontend or backend */
 #ifdef FRONTEND
-#undef Assert
+#include "postgres_fe.h"
+/* No assert checks in frontend ... */
 #define Assert(condition)
+#else
+#include "postgres.h"
 #endif
 
+#include "lib/dllist.h"
+
 
 Dllist *
 DLNewList(void)
diff --git a/src/backend/libpq/hba.c b/src/backend/libpq/hba.c
index 5dbf7d61db909bff92e4900c4900657cee21d312..7c847ae354c01d828155d9c31e7e90d5252d0a6d 100644
--- a/src/backend/libpq/hba.c
+++ b/src/backend/libpq/hba.c
@@ -5,7 +5,7 @@
  *	  wherein you authenticate a user by seeing what IP address the system
  *	  says he comes from and possibly using ident).
  *
- *	$Id: hba.c,v 1.54 2000/08/27 21:50:18 tgl Exp $
+ *	$Id: hba.c,v 1.55 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -882,7 +882,7 @@ struct CharsetItem
 	char		Table[MAX_TOKEN];
 };
 
-int
+static bool
 InRange(char *buf, int host)
 {
 	int			valid,
diff --git a/src/backend/libpq/pqsignal.c b/src/backend/libpq/pqsignal.c
index 0783811d4f72dbf4c434e199a21bdb300b14f06c..668d5f996dd2bb5b7f2f744e34c7249967e87115 100644
--- a/src/backend/libpq/pqsignal.c
+++ b/src/backend/libpq/pqsignal.c
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.18 2001/01/24 19:42:56 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/libpq/pqsignal.c,v 1.19 2001/02/10 02:31:26 tgl Exp $
  *
  * NOTES
  *		This shouldn't be in libpq, but the monitor and some other
@@ -38,10 +38,10 @@
  *	is to do signal-handler reinstallation, which doesn't work well
  *	at all.
  * ------------------------------------------------------------------------*/
-#include <signal.h>
-
 #include "postgres.h"
 
+#include <signal.h>
+
 #include "libpq/pqsignal.h"
 
 
diff --git a/src/backend/port/dynloader/aix.h b/src/backend/port/dynloader/aix.h
index 35b3a0d0aa21d23a0ab7dc7cd69bb721c4a7e586..9d8ff105c440f4960b9859182b8d5d7dd692b626 100644
--- a/src/backend/port/dynloader/aix.h
+++ b/src/backend/port/dynloader/aix.h
@@ -1,5 +1,5 @@
 /*
- * $Id: aix.h,v 1.3 2000/09/29 22:00:43 momjian Exp $
+ * $Id: aix.h,v 1.4 2001/02/10 02:31:26 tgl Exp $
  *
  * @(#)dlfcn.h	1.4 revision of 95/04/25  09:36:52
  * This is an unpublished work copyright (c) 1992 HELIOS Software GmbH
@@ -56,7 +56,6 @@ extern		"C"
 
 #endif /* HAVE_DLOPEN */
 
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 #define  pg_dlopen(f)	dlopen(f, RTLD_LAZY)
diff --git a/src/backend/port/dynloader/beos.c b/src/backend/port/dynloader/beos.c
index 23b6d273b424fb040f0f9ede246e585fbdfc2f28..80bdbca037390481b3bb9a14203e7917c721c116 100644
--- a/src/backend/port/dynloader/beos.c
+++ b/src/backend/port/dynloader/beos.c
@@ -8,14 +8,14 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/beos.c,v 1.5 2001/01/24 19:43:03 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/beos.c,v 1.6 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 #include "postgres.h"
+
 #include "utils/dynamic_loader.h"
-#include "utils/elog.h"
 
 
 void	   *
@@ -74,4 +74,4 @@ pg_dlclose(void *handle)
 			elog(NOTICE, "error while unloading add-on");
 		free(handle);
 	}
-}
\ No newline at end of file
+}
diff --git a/src/backend/port/dynloader/bsdi.h b/src/backend/port/dynloader/bsdi.h
index a7925a23e7f5bab4a4a4bcbfdc3d4681486a202e..56f3443665193a7f8d1b988808f2168e6ae3a5ff 100644
--- a/src/backend/port/dynloader/bsdi.h
+++ b/src/backend/port/dynloader/bsdi.h
@@ -14,7 +14,6 @@
 #ifndef PORT_PROTOS_H
 #define PORT_PROTOS_H
 
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 /* dynloader.c */
diff --git a/src/backend/port/dynloader/dgux.h b/src/backend/port/dynloader/dgux.h
index 944bbfe382648f178761eaa8f9ad3be40e368355..7eb676687d027044d1e49ca92b66e5bd55f30484 100644
--- a/src/backend/port/dynloader/dgux.h
+++ b/src/backend/port/dynloader/dgux.h
@@ -5,7 +5,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: dgux.h,v 1.8 2001/01/24 19:43:04 momjian Exp $
+ * $Id: dgux.h,v 1.9 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -13,7 +13,6 @@
 #define PORT_PROTOS_H
 
 #include <dlfcn.h>
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 /*
diff --git a/src/backend/port/dynloader/freebsd.c b/src/backend/port/dynloader/freebsd.c
index d21e27a6c15e303b346989410305069ea177205f..5824b8e4b057349f587274f70c5c29157536dadf 100644
--- a/src/backend/port/dynloader/freebsd.c
+++ b/src/backend/port/dynloader/freebsd.c
@@ -45,6 +45,7 @@ static char sccsid[] = "@(#)dl.c	5.4 (Berkeley) 2/23/91";
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "postgres.h"
 #include "dynloader.h"
 
 static char error_message[BUFSIZ];
diff --git a/src/backend/port/dynloader/freebsd.h b/src/backend/port/dynloader/freebsd.h
index 3e43cb174f5133274e2e094cb5e14e60752c8d51..4b6658583476c9490554c0c69652466b75e0e6fc 100644
--- a/src/backend/port/dynloader/freebsd.h
+++ b/src/backend/port/dynloader/freebsd.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: freebsd.h,v 1.7 2001/01/24 19:43:04 momjian Exp $
+ * $Id: freebsd.h,v 1.8 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,9 +18,6 @@
 #include <nlist.h>
 #include <link.h>
 
-#include "postgres.h"
-
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 /* dynloader.c */
diff --git a/src/backend/port/dynloader/hpux.c b/src/backend/port/dynloader/hpux.c
index 35d22db03a9505417101fc7ee9805d5914b21ac2..73e50b718063fc7e88bea66368253ab913b5ec5f 100644
--- a/src/backend/port/dynloader/hpux.c
+++ b/src/backend/port/dynloader/hpux.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/port/dynloader/hpux.c,v 1.16 2001/02/07 17:59:58 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/port/dynloader/hpux.c,v 1.17 2001/02/10 02:31:26 tgl Exp $
  *
  *	NOTES
  *		all functions are defined here -- it's impossible to trace the
@@ -23,7 +23,6 @@
 
 #include "dl.h"
 #include "dynloader.h"
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 void *
diff --git a/src/backend/port/dynloader/irix5.h b/src/backend/port/dynloader/irix5.h
index 5a66240066032900eb1398cfd37e6174434e74e6..355ce1b87d8b3fb0bf6e399654e3be426f72b117 100644
--- a/src/backend/port/dynloader/irix5.h
+++ b/src/backend/port/dynloader/irix5.h
@@ -15,7 +15,6 @@
 #define PORT_PROTOS_H
 
 #include <dlfcn.h>
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 /* dynloader.c */
diff --git a/src/backend/port/dynloader/linux.h b/src/backend/port/dynloader/linux.h
index 1f325359f89aacd54a9ec33d431524f1826d731d..64807b036fb0e26a7a54bf2778a410111960595f 100644
--- a/src/backend/port/dynloader/linux.h
+++ b/src/backend/port/dynloader/linux.h
@@ -7,14 +7,13 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: linux.h,v 1.10 2001/01/24 19:43:04 momjian Exp $
+ * $Id: linux.h,v 1.11 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef PORT_PROTOS_H
 #define PORT_PROTOS_H
 
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 #ifdef __ELF__
 #include <dlfcn.h>
diff --git a/src/backend/port/dynloader/netbsd.c b/src/backend/port/dynloader/netbsd.c
index adcc555b2f89dac50d6ba31f0e181dc03d48117b..d98c71675ee9584220e807a614aa8e9f4d7ff2e7 100644
--- a/src/backend/port/dynloader/netbsd.c
+++ b/src/backend/port/dynloader/netbsd.c
@@ -45,6 +45,7 @@ static char sccsid[] = "@(#)dl.c	5.4 (Berkeley) 2/23/91";
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "postgres.h"
 #include "dynloader.h"
 
 static char error_message[BUFSIZ];
diff --git a/src/backend/port/dynloader/netbsd.h b/src/backend/port/dynloader/netbsd.h
index a3586b0242e198afa93abeab921d69bb419f383b..a4c13b322cfc66ecc9a4b141bb6978723bae086b 100644
--- a/src/backend/port/dynloader/netbsd.h
+++ b/src/backend/port/dynloader/netbsd.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: netbsd.h,v 1.2 2001/01/24 19:43:04 momjian Exp $
+ * $Id: netbsd.h,v 1.3 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,9 +18,6 @@
 #include <nlist.h>
 #include "link.h"
 
-#include "postgres.h"
-
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 /* dynloader.c */
diff --git a/src/backend/port/dynloader/nextstep.h b/src/backend/port/dynloader/nextstep.h
index dfbbdfaef9fcd6edd8dac9d61a009f7600bf080f..d86c2c5cea1a59090968b36815c7a6c752466201 100644
--- a/src/backend/port/dynloader/nextstep.h
+++ b/src/backend/port/dynloader/nextstep.h
@@ -9,7 +9,6 @@
 #ifndef PORT_PROTOS_H
 #define PORT_PROTOS_H
 
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 void	   *next_dlopen(char *name);
diff --git a/src/backend/port/dynloader/openbsd.c b/src/backend/port/dynloader/openbsd.c
index adcc555b2f89dac50d6ba31f0e181dc03d48117b..d98c71675ee9584220e807a614aa8e9f4d7ff2e7 100644
--- a/src/backend/port/dynloader/openbsd.c
+++ b/src/backend/port/dynloader/openbsd.c
@@ -45,6 +45,7 @@ static char sccsid[] = "@(#)dl.c	5.4 (Berkeley) 2/23/91";
 #include <stdio.h>
 #include <stdlib.h>
 
+#include "postgres.h"
 #include "dynloader.h"
 
 static char error_message[BUFSIZ];
diff --git a/src/backend/port/dynloader/openbsd.h b/src/backend/port/dynloader/openbsd.h
index c8c26559358d673627219561eb90c6590a7d1cef..307edf97cc81b85acf1ca705f4881b1f491a2870 100644
--- a/src/backend/port/dynloader/openbsd.h
+++ b/src/backend/port/dynloader/openbsd.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: openbsd.h,v 1.2 2001/01/24 19:43:04 momjian Exp $
+ * $Id: openbsd.h,v 1.3 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -18,9 +18,6 @@
 #include <nlist.h>
 #include "link.h"
 
-#include "postgres.h"
-
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 /* dynloader.c */
diff --git a/src/backend/port/dynloader/qnx4.c b/src/backend/port/dynloader/qnx4.c
index 60bed57c6321b282e7b4c2d07851548b88791b19..6e6ca0437a70b45a8508078c26bdd8b25ad8c12c 100644
--- a/src/backend/port/dynloader/qnx4.c
+++ b/src/backend/port/dynloader/qnx4.c
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/qnx4.c,v 1.2 2000/05/28 17:56:02 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/port/dynloader/Attic/qnx4.c,v 1.3 2001/02/10 02:31:26 tgl Exp $
  *
  *	NOTES
  *
@@ -20,7 +20,7 @@
 #include <dl.h>
 */
 #include "postgres.h"
-#include "fmgr.h"
+
 #include "utils/dynamic_loader.h"
 #include "dynloader.h"
 
diff --git a/src/backend/port/dynloader/sco.h b/src/backend/port/dynloader/sco.h
index 957f7f561d63add906b148b54d68458c62e36a8a..584799f52b9cf0c12d9a0ac6be4d6c32f29326d7 100644
--- a/src/backend/port/dynloader/sco.h
+++ b/src/backend/port/dynloader/sco.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: sco.h,v 1.6 2001/01/24 19:43:04 momjian Exp $
+ * $Id: sco.h,v 1.7 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -15,7 +15,6 @@
 #define PORT_PROTOS_H
 
 #include <dlfcn.h>
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 /* dynloader.c */
diff --git a/src/backend/port/dynloader/solaris.h b/src/backend/port/dynloader/solaris.h
index 7232418b13ebc8082f963560d19ec5d4bee0134b..3c70b9095241482173ff3cfe37a033e92bac4ed3 100644
--- a/src/backend/port/dynloader/solaris.h
+++ b/src/backend/port/dynloader/solaris.h
@@ -1,11 +1,9 @@
-/* $Header: /cvsroot/pgsql/src/backend/port/dynloader/solaris.h,v 1.1 2000/10/10 21:22:23 petere Exp $ */
+/* $Header: /cvsroot/pgsql/src/backend/port/dynloader/solaris.h,v 1.2 2001/02/10 02:31:26 tgl Exp $ */
 
 #ifndef DYNLOADER_SOLARIS_H
 #define DYNLOADER_SOLARIS_H
 
-#include "config.h"
 #include <dlfcn.h>
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 #define pg_dlopen(f)	dlopen(f,1)
diff --git a/src/backend/port/dynloader/sunos4.h b/src/backend/port/dynloader/sunos4.h
index 636dc85863225114676e30e5faa15dff7f282aa4..e915a85086e739341fcbcf16a8de4bc02364284b 100644
--- a/src/backend/port/dynloader/sunos4.h
+++ b/src/backend/port/dynloader/sunos4.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: sunos4.h,v 1.6 2001/01/24 19:43:04 momjian Exp $
+ * $Id: sunos4.h,v 1.7 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -15,7 +15,6 @@
 #define PORT_PROTOS_H
 
 #include <dlfcn.h>
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 /* dynloader.c */
diff --git a/src/backend/port/dynloader/svr4.h b/src/backend/port/dynloader/svr4.h
index fb9a8e51ed21c83da5ade37bc72d1e09e9fef29f..6e151d2e497ca6b2d31a46c654b3a580944595f7 100644
--- a/src/backend/port/dynloader/svr4.h
+++ b/src/backend/port/dynloader/svr4.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: svr4.h,v 1.6 2001/01/24 19:43:04 momjian Exp $
+ * $Id: svr4.h,v 1.7 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -15,7 +15,6 @@
 #define DYNLOADER_H
 
 #include <dlfcn.h>
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
 /* dynloader.h */
diff --git a/src/backend/port/dynloader/ultrix4.c b/src/backend/port/dynloader/ultrix4.c
index 130d1aeb2dd47e1209910f9b47d04332ea5af703..bc10f940adf04f5615a044d3804801e43ab6c745 100644
--- a/src/backend/port/dynloader/ultrix4.c
+++ b/src/backend/port/dynloader/ultrix4.c
@@ -2,22 +2,19 @@
  *
  * dynloader.c
  *	  This dynamic loader uses Andrew Yu's libdl-1.0 package for Ultrix 4.x.
- *	  (Note that pg_dlsym and pg_dlclose are actually macros defined in
- *	  "port-protos.h".)
  *
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/port/dynloader/ultrix4.c,v 1.12 2001/01/24 19:43:04 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/port/dynloader/ultrix4.c,v 1.13 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
+
 #include "dl.h"
-#include "fmgr.h"
-#include "port-protos.h"
 #include "utils/dynamic_loader.h"
 
 extern char pg_pathname[];
diff --git a/src/backend/port/dynloader/univel.h b/src/backend/port/dynloader/univel.h
index e236fa253f0777ee71958fccc23d23360e9d6db3..d490e25e6b97bd3a74841a406882690307bf02eb 100644
--- a/src/backend/port/dynloader/univel.h
+++ b/src/backend/port/dynloader/univel.h
@@ -15,7 +15,6 @@
 #define PORT_PROTOS_H
 
 #include <dlfcn.h>
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
  /* dynloader.c */
diff --git a/src/backend/port/dynloader/unixware.h b/src/backend/port/dynloader/unixware.h
index 84eaeaf31607b0109092af7f845cf222cc06a9f5..d52842cede0dcbe3f1b6276aa6a9b57e47572ec2 100644
--- a/src/backend/port/dynloader/unixware.h
+++ b/src/backend/port/dynloader/unixware.h
@@ -15,7 +15,6 @@
 #define PORT_PROTOS_H
 
 #include <dlfcn.h>
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
  /* dynloader.c */
diff --git a/src/backend/port/dynloader/win.h b/src/backend/port/dynloader/win.h
index 434beeff86e14fd80fefd9e86a44774c4fe092fe..5cabfab3fa7ea7978ca1d85c4d5b21da106cedb5 100644
--- a/src/backend/port/dynloader/win.h
+++ b/src/backend/port/dynloader/win.h
@@ -15,7 +15,6 @@
 #define PORT_PROTOS_H
 
 #include <dlfcn.h>
-#include "fmgr.h"
 #include "utils/dynamic_loader.h"
 
  /* dynloader.c */
diff --git a/src/backend/port/snprintf.c b/src/backend/port/snprintf.c
index 6cf45ca99202182ba0453938b999d8d9c84db66d..bfd7705a2a8c8d89a713b7be301dc0e86366e3a5 100644
--- a/src/backend/port/snprintf.c
+++ b/src/backend/port/snprintf.c
@@ -32,11 +32,12 @@
  * SUCH DAMAGE.
  */
 
+/* might be in either frontend or backend */
+#include "postgres_fe.h"
+
 #include <sys/ioctl.h>
 #include <sys/param.h>
 
-#include "postgres.h"
-
 
 /*
  * We do all internal arithmetic in the widest available integer type,
@@ -74,7 +75,7 @@ typedef unsigned long ulong_long;
  * causing nast effects.
  **************************************************************/
 
-/*static char _id[] = "$Id: snprintf.c,v 1.29 2000/12/30 19:17:47 tgl Exp $";*/
+/*static char _id[] = "$Id: snprintf.c,v 1.30 2001/02/10 02:31:26 tgl Exp $";*/
 static char *end;
 static int	SnprfOverflow;
 
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c
index 763f482608e6abc23135e2b8691a9598a080b368..0b8e6c6e3ce8c5da677cb02ea66f8f4b914d75cf 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.205 2001/02/08 00:35:10 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.206 2001/02/10 02:31:26 tgl Exp $
  *
  * NOTES
  *
@@ -235,11 +235,6 @@ static void InitSSL(void);
 
 #endif
 
-#ifdef CYR_RECODE
-extern void GetCharSetByHost(char *, int, char *);
-
-#endif
-
 
 static void
 checkDataDir(const char *checkdir)
diff --git a/src/backend/storage/large_object/inv_api.c b/src/backend/storage/large_object/inv_api.c
index c380d96c323ca9b4325972a74e45e0c69e9a4f98..bcf65f6004bdf5339b7155f80d51ba69faf52987 100644
--- a/src/backend/storage/large_object/inv_api.c
+++ b/src/backend/storage/large_object/inv_api.c
@@ -9,7 +9,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.84 2001/01/24 19:43:07 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/storage/large_object/inv_api.c,v 1.85 2001/02/10 02:31:26 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,8 +22,9 @@
 
 #include "access/genam.h"
 #include "access/heapam.h"
-#include "access/nbtree.h"
 #include "access/htup.h"
+#include "access/nbtree.h"
+#include "access/tuptoaster.h"
 #include "catalog/catalog.h"
 #include "catalog/catname.h"
 #include "catalog/heap.h"
diff --git a/src/backend/utils/adt/varchar.c b/src/backend/utils/adt/varchar.c
index e27a12dffe4ba80517f16510706c6a7b7c33e1b3..acec5f0cf24488d873817a419a725915c71e15e4 100644
--- a/src/backend/utils/adt/varchar.c
+++ b/src/backend/utils/adt/varchar.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.73 2001/01/24 19:43:14 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.74 2001/02/10 02:31:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -17,6 +17,7 @@
 
 #include "access/hash.h"
 #include "catalog/pg_type.h"
+#include "miscadmin.h"
 #include "utils/acl.h"
 #include "utils/builtins.h"
 #include "utils/fmgroids.h"
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index ff600152666c0c8198f2b44afe6093aee0ef7c6f..ba1ed5350ed64bfbc55d8fc61144f56d80c1f59d 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -8,15 +8,16 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.67 2001/01/24 19:43:14 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.68 2001/02/10 02:31:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
-#include <ctype.h>
-
 #include "postgres.h"
 
+#include <ctype.h>
+
 #include "mb/pg_wchar.h"
+#include "miscadmin.h"
 #include "utils/builtins.h"
 
 static int	text_cmp(text *arg1, text *arg2);
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c
index 6f503b6d2ddfc51484fe4959e5aa4fe4db3d4262..a0a412cbb6a5906aa5ea808e1ae9a2e07463f80b 100644
--- a/src/backend/utils/fmgr/fmgr.c
+++ b/src/backend/utils/fmgr/fmgr.c
@@ -8,13 +8,14 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.49 2001/01/24 19:43:15 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/fmgr/fmgr.c,v 1.50 2001/02/10 02:31:27 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
 #include "postgres.h"
 
+#include "access/tuptoaster.h"
 #include "catalog/pg_language.h"
 #include "catalog/pg_proc.h"
 #include "executor/functions.h"
diff --git a/src/backend/utils/mb/alt.c b/src/backend/utils/mb/alt.c
index 3d1439a5a3a656551fa04f460b1447fa430d0b6d..984caa8f7f87eb3346f1ae0a8f79c5dda7a2722a 100644
--- a/src/backend/utils/mb/alt.c
+++ b/src/backend/utils/mb/alt.c
@@ -4,10 +4,12 @@
  *
  * Tatsuo Ishii
  *
- * $Id: alt.c,v 1.2 1999/05/25 16:12:38 momjian Exp $
+ * $Id: alt.c,v 1.3 2001/02/10 02:31:27 tgl Exp $
  */
 
 #include <stdio.h>
+
+
 main()
 {
 	int			i;
diff --git a/src/backend/utils/mb/big5.c b/src/backend/utils/mb/big5.c
index 5739a6c5a04bf61654e0fde434dba96de5cbbc01..2546ee4079f6f5d244e7c36ca1de6383ead2904a 100644
--- a/src/backend/utils/mb/big5.c
+++ b/src/backend/utils/mb/big5.c
@@ -7,9 +7,12 @@
  *
  * 1999/1/15 Tatsuo Ishii
  *
- * $Id: big5.c,v 1.6 2000/12/09 04:27:36 ishii Exp $
+ * $Id: big5.c,v 1.7 2001/02/10 02:31:27 tgl Exp $
  */
 
+/* can be used in either frontend or backend */
+#include "postgres_fe.h"
+
 #include "mb/pg_wchar.h"
 
 typedef struct
diff --git a/src/backend/utils/mb/common.c b/src/backend/utils/mb/common.c
index 33773e20505c5df29ffed56fbd59929e2613c275..7c477a706cc42d5de543cc9103060a25f8a44ef0 100644
--- a/src/backend/utils/mb/common.c
+++ b/src/backend/utils/mb/common.c
@@ -2,10 +2,9 @@
  * This file contains some public functions
  * usable for both the backend and the frontend.
  * Tatsuo Ishii
- * $Id: common.c,v 1.10 2000/10/30 10:40:28 ishii Exp $ */
-
-#include <stdlib.h>
-#include <string.h>
+ * $Id: common.c,v 1.11 2001/02/10 02:31:27 tgl Exp $
+ */
+#include "postgres.h"
 
 #ifdef WIN32
 #include "win32.h"
@@ -13,8 +12,6 @@
 #include <unistd.h>
 #endif
 
-#include "postgres.h"
-
 #include "miscadmin.h"
 #include "mb/pg_wchar.h"
 #include "utils/builtins.h"
diff --git a/src/backend/utils/mb/conv.c b/src/backend/utils/mb/conv.c
index b32a4d53d33b469184f2bdf840507608cde11e3a..897ae5e2375ffbc53465f126ea499d5ef9cbd546 100644
--- a/src/backend/utils/mb/conv.c
+++ b/src/backend/utils/mb/conv.c
@@ -6,13 +6,12 @@
  * WIN1250 client encoding support contributed by Pavel Behal
  * SJIS UDC (NEC selection IBM kanji) support contributed by Eiji Tokuya
  *
- * $Id: conv.c,v 1.21 2000/11/17 04:42:10 ishii Exp $
+ * $Id: conv.c,v 1.22 2001/02/10 02:31:27 tgl Exp $
  *
  *
  */
-
-#include <stdio.h>
-#include <string.h>
+/* can be used in either frontend or backend */
+#include "postgres_fe.h"
 
 #include "mb/pg_wchar.h"
 
diff --git a/src/backend/utils/mb/iso.c b/src/backend/utils/mb/iso.c
index a2903895b0c0f0a1b1ed0e81287aa8a1a450445e..8cfa8cf615b278c0c60a0b99f8817af9d861c8ba 100644
--- a/src/backend/utils/mb/iso.c
+++ b/src/backend/utils/mb/iso.c
@@ -4,10 +4,12 @@
  *
  * Tatsuo Ishii
  *
- * $Id: iso.c,v 1.2 1999/05/25 16:12:42 momjian Exp $
+ * $Id: iso.c,v 1.3 2001/02/10 02:31:27 tgl Exp $
  */
 
 #include <stdio.h>
+
+
 main()
 {
 	int			i;
diff --git a/src/backend/utils/mb/liketest.c b/src/backend/utils/mb/liketest.c
index 916166104e503ffba1fe2dc4ea68af6269e6a4ce..3c2e9de75070e349c805e4e99d509470e4880ab8 100644
--- a/src/backend/utils/mb/liketest.c
+++ b/src/backend/utils/mb/liketest.c
@@ -1,5 +1,6 @@
-#include <stdio.h>
-#include <string.h>
+#include "postgres_fe.h"
+
+#include <ctype.h>
 
 #include "mb/pg_wchar.h"
 
diff --git a/src/backend/utils/mb/mbutils.c b/src/backend/utils/mb/mbutils.c
index ad1322fe52b4c5437d2bc84a277234477a4b2822..0d3d8cb69bd175c5e4e47565ffbc92751beafb71 100644
--- a/src/backend/utils/mb/mbutils.c
+++ b/src/backend/utils/mb/mbutils.c
@@ -3,9 +3,8 @@
  * client encoding and server internal encoding.
  * (currently mule internal code (mic) is used)
  * Tatsuo Ishii
- * $Id: mbutils.c,v 1.14 2000/11/14 18:37:44 tgl Exp $ */
-
-
+ * $Id: mbutils.c,v 1.15 2001/02/10 02:31:27 tgl Exp $
+ */
 #include "postgres.h"
 
 #include "miscadmin.h"
diff --git a/src/backend/utils/mb/wchar.c b/src/backend/utils/mb/wchar.c
index 43b4aed0f8f093fd8c7945f43bcd0beae7e53bb6..0e03d90b1d878ccc83f16ae17f90c6cbb410ec24 100644
--- a/src/backend/utils/mb/wchar.c
+++ b/src/backend/utils/mb/wchar.c
@@ -1,11 +1,13 @@
 /*
  * conversion functions between pg_wchar and multi-byte streams.
  * Tatsuo Ishii
- * $Id: wchar.c,v 1.13 2000/10/12 06:06:50 ishii Exp $
+ * $Id: wchar.c,v 1.14 2001/02/10 02:31:27 tgl Exp $
  *
  * WIN1250 client encoding updated by Pavel Behal
  *
  */
+/* can be used in either frontend or backend */
+#include "postgres_fe.h"
 
 #include "mb/pg_wchar.h"
 
diff --git a/src/backend/utils/mb/win.c b/src/backend/utils/mb/win.c
index 8db62b49b3ce251795c8bc165964b79eb895d181..8996c03a48c79c5a62aa7c0e22ee7d1750adf840 100644
--- a/src/backend/utils/mb/win.c
+++ b/src/backend/utils/mb/win.c
@@ -4,10 +4,12 @@
  *
  * Tatsuo Ishii
  *
- * $Id: win.c,v 1.2 1999/05/25 16:12:45 momjian Exp $
+ * $Id: win.c,v 1.3 2001/02/10 02:31:27 tgl Exp $
  */
 
 #include <stdio.h>
+
+
 main()
 {
 	int			i;
diff --git a/src/backend/utils/mb/wstrcmp.c b/src/backend/utils/mb/wstrcmp.c
index 4b6a16b7d14bbb6dd9b15916539b65e42ab27199..13255d7c5e25ec5576e240891604c8db1a27f089 100644
--- a/src/backend/utils/mb/wstrcmp.c
+++ b/src/backend/utils/mb/wstrcmp.c
@@ -33,6 +33,8 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+/* can be used in either frontend or backend */
+#include "postgres_fe.h"
 
 #include "mb/pg_wchar.h"
 
diff --git a/src/backend/utils/mb/wstrncmp.c b/src/backend/utils/mb/wstrncmp.c
index 050a46191b42643a0d39bd72a4a0becdfbdbf8a1..64641478978872ca740d862cac5c3349d1a44513 100644
--- a/src/backend/utils/mb/wstrncmp.c
+++ b/src/backend/utils/mb/wstrncmp.c
@@ -32,6 +32,8 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  */
+/* can be used in either frontend or backend */
+#include "postgres_fe.h"
 
 #include "mb/pg_wchar.h"
 
diff --git a/src/bin/pg_dump/common.c b/src/bin/pg_dump/common.c
index c7658f384e8f7e9613b0364e7d785eca0de107a1..2e7281265fc891a8d7006cd902f965befd1fee97 100644
--- a/src/bin/pg_dump/common.c
+++ b/src/bin/pg_dump/common.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.52 2001/01/28 03:47:49 pjw Exp $
+ *	  $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.53 2001/02/10 02:31:27 tgl Exp $
  *
  * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
  *
@@ -27,18 +27,15 @@
  *-------------------------------------------------------------------------
  */
 
+#include "pg_dump.h"
 
 #include <ctype.h>
 
-#include "postgres.h"
-
 #include "libpq-fe.h"
 #ifndef HAVE_STRDUP
 #include "strdup.h"
 #endif
 
-#include "pg_dump.h"
-
 static char **findParentsByOid(TableInfo *tbinfo, int numTables,
 				 InhInfo *inhinfo, int numInherits,
 				 const char *oid,
diff --git a/src/bin/pg_dump/pg_backup.h b/src/bin/pg_dump/pg_backup.h
index 8fceb26c8e24645bd2c010947e508f1d19b86157..ae04c7c2ea2a3cc11c298a50cd622a0932032135 100644
--- a/src/bin/pg_dump/pg_backup.h
+++ b/src/bin/pg_dump/pg_backup.h
@@ -40,13 +40,10 @@
  */
 
 #ifndef PG_BACKUP__
-
-#include "config.h"
-#include "c.h"
-
 #define PG_BACKUP__
 
-#include "postgres.h"
+#include "postgres_fe.h"
+
 #include "libpq-fe.h"
 
 typedef enum _archiveFormat {
diff --git a/src/bin/pg_dump/pg_backup_archiver.h b/src/bin/pg_dump/pg_backup_archiver.h
index e7f18d1bbff79eff8ae23ee894bd5b0e507a69a0..634c10888b7d9ff1fd5f2c0ad9a21eef97c14333 100644
--- a/src/bin/pg_dump/pg_backup_archiver.h
+++ b/src/bin/pg_dump/pg_backup_archiver.h
@@ -31,10 +31,10 @@
 #ifndef __PG_BACKUP_ARCHIVE__
 #define __PG_BACKUP_ARCHIVE__
 
-#include <stdio.h>
+#include "postgres_fe.h"
+
 #include <time.h>
 
-#include "postgres.h"
 #include "pqexpbuffer.h"
 
 #ifdef HAVE_LIBZ
diff --git a/src/bin/pg_dump/pg_backup_custom.c b/src/bin/pg_dump/pg_backup_custom.c
index 62562577817f7668256ce56e8b812874716582fb..94c598c51b4dc041ccd53bae8c0108f285824aae 100644
--- a/src/bin/pg_dump/pg_backup_custom.c
+++ b/src/bin/pg_dump/pg_backup_custom.c
@@ -31,9 +31,10 @@
  *-------------------------------------------------------------------------
  */
 
-#include <stdlib.h>
 #include "pg_backup.h"
 #include "pg_backup_archiver.h"
+
+#include <stdlib.h>
 #include <errno.h>
 
 /*--------
diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c
index 763d94fa80a4c3d1e158b57dc3a829aa2fe6a2d4..a3de94df810554446d2eba3062cd136017fdfd59 100644
--- a/src/bin/pg_dump/pg_backup_db.c
+++ b/src/bin/pg_dump/pg_backup_db.c
@@ -13,33 +13,24 @@
  *-------------------------------------------------------------------------
  */
 
+#include "pg_dump.h"
+#include "pg_backup.h"
+#include "pg_backup_archiver.h"
+#include "pg_backup_db.h"
+
 #include <unistd.h>				/* for getopt() */
 #include <ctype.h>
 
-#include "postgres.h"
-
 #ifdef HAVE_TERMIOS_H
 #include <termios.h>
 #endif
 
-#include "access/attnum.h"
-#include "access/htup.h"
-#include "catalog/pg_index.h"
-#include "catalog/pg_language.h"
-#include "catalog/pg_trigger.h"
-#include "catalog/pg_type.h"
-
 #include "libpq-fe.h"
-#include <libpq/libpq-fs.h>
+#include "libpq/libpq-fs.h"
 #ifndef HAVE_STRDUP
 #include "strdup.h"
 #endif
 
-#include "pg_dump.h"
-#include "pg_backup.h"
-#include "pg_backup_archiver.h"
-#include "pg_backup_db.h"
-
 static const char	*progname = "Archiver(db)";
 
 static void 	_prompt_for_password(char *username, char *password);
diff --git a/src/bin/pg_dump/pg_backup_files.c b/src/bin/pg_dump/pg_backup_files.c
index 22c5d17dc4d753c30f306c674ebdc8e571d655ca..632004ead4531011c08f6d8a8587e384acf6362e 100644
--- a/src/bin/pg_dump/pg_backup_files.c
+++ b/src/bin/pg_dump/pg_backup_files.c
@@ -32,11 +32,12 @@
  *-------------------------------------------------------------------------
  */
 
-#include <stdlib.h>
-#include <string.h>
 #include "pg_backup.h"
 #include "pg_backup_archiver.h"
 
+#include <stdlib.h>
+#include <string.h>
+
 static void     _ArchiveEntry(ArchiveHandle* AH, TocEntry* te);
 static void	_StartData(ArchiveHandle* AH, TocEntry* te);
 static int	_WriteData(ArchiveHandle* AH, const void* data, int dLen);
diff --git a/src/bin/pg_dump/pg_backup_null.c b/src/bin/pg_dump/pg_backup_null.c
index 26c30bd8ec8c29e0933bd3558666fe76778022a3..761d2ea4460b07487776037008eb449b401bdcba 100644
--- a/src/bin/pg_dump/pg_backup_null.c
+++ b/src/bin/pg_dump/pg_backup_null.c
@@ -30,11 +30,12 @@
  *-------------------------------------------------------------------------
  */
 
+#include "pg_backup.h"
+#include "pg_backup_archiver.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h> /* for dup */
-#include "pg_backup.h"
-#include "pg_backup_archiver.h"
 
 static int	_WriteData(ArchiveHandle* AH, const void* data, int dLen);
 static void     _EndData(ArchiveHandle* AH, TocEntry* te);
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index d9adffb17337dc6cf9fbda7e05f124c17b9b4d7e..40d90ac865233f789ca7eaa5b74c99e94f457b90 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -28,13 +28,14 @@
  *-------------------------------------------------------------------------
  */
 
+#include "pg_backup.h"
+#include "pg_backup_archiver.h"
+#include "pg_backup_tar.h"
+
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
-#include "pg_backup.h"
-#include "pg_backup_archiver.h"
-#include "pg_backup_tar.h"
 
 static void     _ArchiveEntry(ArchiveHandle* AH, TocEntry* te);
 static void		_StartData(ArchiveHandle* AH, TocEntry* te);
diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c
index 1822b4200d4359be8e6a31a47d2b11cb2ce97cc9..77447f403b107dfba23785f28c909b15a12e7b42 100644
--- a/src/bin/pg_dump/pg_dump.c
+++ b/src/bin/pg_dump/pg_dump.c
@@ -22,7 +22,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.190 2001/01/28 03:47:49 pjw Exp $
+ *	  $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.191 2001/02/10 02:31:27 tgl Exp $
  *
  * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
  *
@@ -104,13 +104,18 @@
  *-------------------------------------------------------------------------
  */
 
+/*
+ * Although this is not a backend module, we must include postgres.h anyway
+ * so that we can include a bunch of backend include files.  pg_dump has
+ * never pretended to be very independent of the backend anyhow ...
+ */
+#include "postgres.h"
+
 #include <unistd.h>				/* for getopt() */
 #include <ctype.h>
 
 #include "pg_backup.h"
 
-#include "postgres.h"
-
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
 #endif
@@ -120,13 +125,12 @@
 
 #include "access/attnum.h"
 #include "access/htup.h"
-#include "catalog/pg_index.h"
-#include "catalog/pg_language.h"
+#include "catalog/pg_class.h"
 #include "catalog/pg_trigger.h"
 #include "catalog/pg_type.h"
 
 #include "libpq-fe.h"
-#include <libpq/libpq-fs.h>
+#include "libpq/libpq-fs.h"
 #ifndef HAVE_STRDUP
 #include "strdup.h"
 #endif
diff --git a/src/bin/pg_dump/pg_dump.h b/src/bin/pg_dump/pg_dump.h
index db5de3b2e2b8efca2e273e5b23c31773a06262f8..74882213464e9fd937cf985043e4e8c2c526ec9b 100644
--- a/src/bin/pg_dump/pg_dump.h
+++ b/src/bin/pg_dump/pg_dump.h
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pg_dump.h,v 1.57 2001/01/24 19:43:18 momjian Exp $
+ * $Id: pg_dump.h,v 1.58 2001/02/10 02:31:27 tgl Exp $
  *
  * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
  *
@@ -29,9 +29,8 @@
 #ifndef PG_DUMP_H
 #define PG_DUMP_H
 
-#include "pqexpbuffer.h"
-#include "catalog/pg_index.h"
 #include "pg_backup.h"
+#include "pqexpbuffer.h"
 
 /* The data structures used to store system catalog information */
 
diff --git a/src/bin/pg_dump/pg_restore.c b/src/bin/pg_dump/pg_restore.c
index 7d701c90fa1c401bbf740c4fb4c14be204cc4c2f..851688ef1e578575c8f181ab8e30641c96ec76d5 100644
--- a/src/bin/pg_dump/pg_restore.c
+++ b/src/bin/pg_dump/pg_restore.c
@@ -50,24 +50,13 @@
  *-------------------------------------------------------------------------
  */
 
+#include "pg_backup.h"
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 
-
-/*
-#include "postgres.h"
-#include "access/htup.h"
-#include "catalog/pg_type.h"
-#include "catalog/pg_language.h"
-#include "catalog/pg_index.h"
-#include "catalog/pg_trigger.h"
-#include "libpq-fe.h"
-*/
-
-#include "pg_backup.h"
-
 #ifndef HAVE_STRDUP
 #include "strdup.h"
 #endif
diff --git a/src/bin/pg_id/pg_id.c b/src/bin/pg_id/pg_id.c
index fb52e9ba46d3f8c16168b1cd64acc6404ffe68f7..e5a3ec3fd6b869c688020fe1f3aadf163016d9c6 100644
--- a/src/bin/pg_id/pg_id.c
+++ b/src/bin/pg_id/pg_id.c
@@ -6,9 +6,9 @@
  *
  * Copyright (C) 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/pg_id/Attic/pg_id.c,v 1.16 2000/10/07 14:39:15 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_id/Attic/pg_id.c,v 1.17 2001/02/10 02:31:27 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 
 #ifdef HAVE_GETOPT_H
 #include <getopt.h>
diff --git a/src/bin/pg_passwd/pg_passwd.c b/src/bin/pg_passwd/pg_passwd.c
index 0f7a0adf16a88890c60bb7a030d40ea7ee7adaa6..022a394670857ebd23072fd6b04fdaf38c43e560 100644
--- a/src/bin/pg_passwd/pg_passwd.c
+++ b/src/bin/pg_passwd/pg_passwd.c
@@ -1,7 +1,8 @@
 /*
  * @(#) pg_passwd.c 1.8 09:13:16 97/07/02		Y. Ichikawa
  */
-#include "postgres.h"
+#include "postgres_fe.h"
+
 #include <unistd.h>
 #include <errno.h>
 #include <time.h>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index a46106d1d064221bc5d422d58d7cc7cd07a06be5..34a05fa6b1c8d3c7820b38793352cb0f0ca13fa1 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.45 2001/01/27 21:49:58 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.46 2001/02/10 02:31:27 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "command.h"
 
 #include <errno.h>
@@ -37,7 +37,6 @@
 #include "variables.h"
 
 #ifdef MULTIBYTE
-#include "miscadmin.h"
 #include "mb/pg_wchar.h"
 #else
 /* Grand unified hard-coded badness */
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index ccbbb6c144312e2b665392bc1393a7a21b137617..9d3323a2ac34d5ce50e8d8dcbb9b4580ae3cc601 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -3,9 +3,10 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.29 2000/12/18 17:33:42 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.30 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
+
 #include "common.h"
 
 #include <errno.h>
@@ -26,7 +27,6 @@
 #endif
 
 #include "libpq-fe.h"
-#include "postgres_ext.h"
 #include "pqsignal.h"
 
 #include "settings.h"
diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h
index 5ef88e5271ca627a8141099656d35e6ec89991f8..04c91fdd66e52c439c909ad5074d940ed2a34c2f 100644
--- a/src/bin/psql/common.h
+++ b/src/bin/psql/common.h
@@ -3,12 +3,12 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.12 2000/08/29 09:36:48 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.h,v 1.13 2001/02/10 02:31:28 tgl Exp $
  */
 #ifndef COMMON_H
 #define COMMON_H
 
-#include "postgres.h"
+#include "postgres_fe.h"
 #include <signal.h>
 #include "pqsignal.h"
 #include "libpq-fe.h"
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index 0f318d3f6e6b5b715b355a20755a9e11badf71fc..5ea17a8ab803f4d937f76625f2a349a7ae3272ae 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.16 2000/12/03 15:39:38 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.17 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "copy.h"
 
 #include <errno.h>
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 0e2453086ef7725f2496f99bda079cd896250864..3e53bb5d353bf945d2dcabca459395ec3d755dae 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.26 2000/10/25 20:36:52 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.27 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "describe.h"
 
 #include "libpq-fe.h"
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index 0251e31cd9775fd2d3d6bde1e3d2b824bd2fe667..5454210c02cb7f9342a857688df7906a634eab1d 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.35 2001/01/24 19:43:18 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.36 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "help.h"
 
 #include <signal.h>
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index 78e2ae3568a198e120eb1940f3c5e79216c50815..b3fdd55c132d885bf0b5a8a606f77b9712b3b6ad 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.14 2000/11/27 02:20:36 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/input.c,v 1.15 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "input.h"
 
 #include <errno.h>
diff --git a/src/bin/psql/large_obj.c b/src/bin/psql/large_obj.c
index f97fab1a6c91596e79746c2b00ded7cd39bddbe3..fdf1d4085e388653c51b6da7893c426deca084e7 100644
--- a/src/bin/psql/large_obj.c
+++ b/src/bin/psql/large_obj.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.12 2000/10/24 04:13:28 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.13 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "large_obj.h"
 
 #include "libpq-fe.h"
diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c
index 1b456fb63f9807cc06fcbaa624fc8b4c518588d4..4049a4d185d107356d4806074c93e2db7a735f19 100644
--- a/src/bin/psql/mainloop.c
+++ b/src/bin/psql/mainloop.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.34 2000/07/17 18:24:33 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.35 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "mainloop.h"
 
 #include "pqexpbuffer.h"
diff --git a/src/bin/psql/mainloop.h b/src/bin/psql/mainloop.h
index d8bdf3087cd99cf7ebc4f356697d9dd1e45dcc81..cc832f194b096502c8e11fdc2bc5b52cbd96fc68 100644
--- a/src/bin/psql/mainloop.h
+++ b/src/bin/psql/mainloop.h
@@ -3,12 +3,12 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.h,v 1.9 2000/04/12 17:16:22 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.h,v 1.10 2001/02/10 02:31:28 tgl Exp $
  */
 #ifndef MAINLOOP_H
 #define MAINLOOP_H
 
-#include "postgres.h"
+#include "postgres_fe.h"
 #include <stdio.h>
 #ifndef WIN32
 #include <setjmp.h>
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index a94ac19909160ed39563a31ea5369eb671a61343..681d47b14b0e449b84dac3c53496988e5ef0cfbb 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.14 2000/11/16 05:51:03 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.15 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "print.h"
 
 #include <math.h>
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index 7927a9caa29cc2114b57f3d4084ccb78d7208cac..a59ecde628e9e4b7317def5da937273ece7b8664 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.16 2000/11/27 02:20:36 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/prompt.c,v 1.17 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "prompt.h"
 
 #include "libpq-fe.h"
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index 44acce4a025050abe8fbbb15b1629a6be5a09858..3852edbbab1b1e11e22aeff05e5032a8b4dde693 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.43 2001/01/24 19:43:18 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.44 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 
 #include <sys/types.h>
 
@@ -34,7 +34,6 @@
 #include "variables.h"
 
 #ifdef MULTIBYTE
-#include "miscadmin.h"
 #include "mb/pg_wchar.h"
 #else
 /* XXX Grand unified hard-coded badness; this should go into libpq */
diff --git a/src/bin/psql/stringutils.c b/src/bin/psql/stringutils.c
index 215572e5f1f740c1832f8516a17d37558d81d360..083b582c274a4a78e69541fecb475d770728c785 100644
--- a/src/bin/psql/stringutils.c
+++ b/src/bin/psql/stringutils.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.26 2000/04/12 17:16:23 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/stringutils.c,v 1.27 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "stringutils.h"
 
 #include <ctype.h>
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index f8c19191932931534b43f9cd580714eaf42185a6..8e73b57b667ba8e5d11d86e678a90586f5b870d2 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.25 2000/12/31 11:57:58 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.26 2001/02/10 02:31:28 tgl Exp $
  */
 
 /*----------------------------------------------------------------------
@@ -42,7 +42,7 @@
  *----------------------------------------------------------------------
  */
 
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "tab-complete.h"
 
 #include "input.h"
diff --git a/src/bin/psql/tab-complete.h b/src/bin/psql/tab-complete.h
index 98f3e9546f105743582bfcf569c6ff1fad2dc597..81182eae5346b8c49febf9c678aa7be48e0102d0 100644
--- a/src/bin/psql/tab-complete.h
+++ b/src/bin/psql/tab-complete.h
@@ -3,12 +3,12 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.h,v 1.5 2000/04/12 17:16:23 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.h,v 1.6 2001/02/10 02:31:28 tgl Exp $
  */
 #ifndef TAB_COMPLETE_H
 #define TAB_COMPLETE_H
 
-#include "postgres.h"
+#include "postgres_fe.h"
 
 void		initialize_readline(void);
 
diff --git a/src/bin/psql/variables.c b/src/bin/psql/variables.c
index c8d8760b7854d2710dab1ec546be4a5911aabc1d..b65ce38bd68e0b13a5b4b69da4c23bf6b47ee74b 100644
--- a/src/bin/psql/variables.c
+++ b/src/bin/psql/variables.c
@@ -3,9 +3,9 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/variables.c,v 1.8 2000/04/12 17:16:23 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/variables.c,v 1.9 2001/02/10 02:31:28 tgl Exp $
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "variables.h"
 
 #include <assert.h>
diff --git a/src/include/Makefile b/src/include/Makefile
index 2b78e9ef627a8726b9ae45078dd67655cdc33858..df3c9a2f89ca07f533ddfb4630ec51b2d2b1845f 100644
--- a/src/include/Makefile
+++ b/src/include/Makefile
@@ -2,10 +2,11 @@
 #
 # Makefile for src/include
 #
-# Install exported headers to the include directory (these headers are
-# the minimal ones needed to build loadable backend extensions).
+# 'make install' installs only those headers needed for client-side
+# programming.  'make install-all-headers' installs the whole contents
+# of src/include.
 #
-# $Header: /cvsroot/pgsql/src/include/Makefile,v 1.5 2000/10/20 21:04:03 petere Exp $
+# $Header: /cvsroot/pgsql/src/include/Makefile,v 1.6 2001/02/10 02:31:28 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -13,30 +14,23 @@ subdir = src/include
 top_builddir = ../..
 include $(top_builddir)/src/Makefile.global
 
+# Headers needed by clients
+srcdir_headers := c.h postgres_ext.h postgres_fe.h \
+	libpq/pqcomm.h libpq/libpq-fs.h lib/dllist.h
 
-srcdir_headers := c.h postgres.h postgres_ext.h fmgr.h \
-	libpq/pqcomm.h libpq/libpq-fs.h lib/dllist.h \
-	utils/geo_decls.h utils/elog.h utils/palloc.h \
-	access/attnum.h executor/spi.h commands/trigger.h
-
-builddir_headers := os.h config.h utils/fmgroids.h
+builddir_headers := os.h config.h
 
 HEADERS = $(srcdir_headers) $(builddir_headers)
 
-
-all: $(HEADERS)
+# Subdirectories containing headers that install-all-headers should install
+SUBDIRS = access bootstrap catalog commands executor lib libpq mb \
+	nodes optimizer parser port regex rewrite storage tcop utils
 
 
-# These rules are necessary in case someone installs the include tree
-# before building the backend tree. Very messy.
-utils/fmgroids.h: $(top_builddir)/src/backend/utils/fmgroids.h
-	cd utils && rm -f fmgroids.h && $(LN_S) ../$(top_builddir)/src/backend/utils/fmgroids.h .
+all: $(HEADERS)
 
-# This file is built in the backend tree, but we need to keep track of
-# the dependencies here.
-$(top_builddir)/src/backend/utils/fmgroids.h: $(top_srcdir)/src/backend/utils/Gen_fmgrtab.sh catalog/pg_proc.h
-	$(MAKE) -C $(dir $@) fmgroids.h
 
+# Install only selected headers
 
 install: all installdirs
 	for file in $(srcdir_headers); do \
@@ -46,13 +40,34 @@ install: all installdirs
 	  $(INSTALL_DATA) $$file $(DESTDIR)$(includedir)/$$file || exit; \
 	done
 
-# Automatically pick out the needed subdirectories for the include
-# tree.
+# Automatically pick out the needed subdirectories for the include tree.
 installdirs:
 	$(mkinstalldirs) $(addprefix $(DESTDIR)$(includedir)/, $(sort $(dir $(HEADERS))))
 
+
+# Install all headers
+
+install-all-headers: all install-all-dirs
+	for file in $(srcdir)/*.h; do \
+	  $(INSTALL_DATA) $$file $(DESTDIR)$(includedir)/`basename $$file` || exit; \
+	done
+	for dir in $(SUBDIRS); do \
+	  for file in $(srcdir)/$$dir/*.h; do \
+	    $(INSTALL_DATA) $$file $(DESTDIR)$(includedir)/$$dir/`basename $$file` || exit; \
+	  done \
+	done
+	for file in $(builddir_headers); do \
+	  $(INSTALL_DATA) $$file $(DESTDIR)$(includedir)/$$file || exit; \
+	done
+
+install-all-dirs:
+	$(mkinstalldirs) $(addprefix $(DESTDIR)$(includedir)/, $(SUBDIRS))
+
+
+# This isn't a complete uninstall, but rm'ing everything under
+# $(DESTDIR)$(includedir) is probably too drastic...
 uninstall:
-	rm -f $(addprefix $(DESTDIR)$(includedir)/, $(HEADERS))
+	rm -rf $(addprefix $(DESTDIR)$(includedir)/, $(HEADERS) $(SUBDIRS))
 
 clean:
 	rm -f utils/fmgroids.h parser/parse.h
diff --git a/src/include/c.h b/src/include/c.h
index dc791d0d545183e7a6ef84149dfcda2f4482c80a..78001289c4d6477511622335c653573ec62ad49a 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -2,17 +2,22 @@
  *
  * c.h
  *	  Fundamental C definitions.  This is included by every .c file in
- *	  postgres.
+ *	  PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate).
+ *
+ *	  Note that the definitions here are not intended to be exposed to clients of
+ *	  the frontend interface libraries --- so we don't worry much about polluting
+ *	  the namespace with lots of stuff...
  *
  *
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: c.h,v 1.89 2001/01/24 19:43:19 momjian Exp $
+ * $Id: c.h,v 1.90 2001/02/10 02:31:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 /*
+ *----------------------------------------------------------------
  *	 TABLE OF CONTENTS
  *
  *		When adding stuff to this file, please try to put stuff
@@ -20,21 +25,21 @@
  *
  *	  section	description
  *	  -------	------------------------------------------------
- *		1)		bool, true, false, TRUE, FALSE, NULL
- *		2)		non-ansi C definitions:
- *				type prefixes: const, signed, volatile, inline
- *				cpp magic macros
+ *		0)		config.h and standard system headers
+ *		1)		hacks to cope with non-ANSI C compilers
+ *		2)		bool, true, false, TRUE, FALSE, NULL
  *		3)		standard system types
- *		4)		datum type
- *		5)		IsValid macros for system types
- *		6)		offsetof, lengthof, endof
- *		7)		exception handling definitions, Assert, Trap, etc macros
- *		8)		Min, Max, Abs, StrNCpy macros
- *		9)		externs
- *		10)		Berkeley-specific defs
- *		11)		system-specific hacks
+ *		4)		IsValid macros for system types
+ *		5)		offsetof, lengthof, endof, alignment
+ *		6)		widely useful macros
+ *		7)		random stuff
+ *		8)		system-specific hacks
  *
- * ----------------------------------------------------------------
+ * NOTE: since this file is included by both frontend and backend modules, it's
+ * almost certainly wrong to put an "extern" declaration here.  typedefs and macros
+ * are the kind of thing that might go here.
+ *
+ *----------------------------------------------------------------
  */
 #ifndef C_H
 #define C_H
@@ -63,56 +68,11 @@
 #include <SupportDefs.h>
 #endif
 
-/* ----------------------------------------------------------------
- *				Section 1:	bool, true, false, TRUE, FALSE, NULL
- * ----------------------------------------------------------------
- */
-/*
- * bool
- *		Boolean value, either true or false.
- *
- */
-
-/* BeOS defines bool already, but the compiler chokes on the
- * #ifndef unless we wrap it in this check.
- */
-#ifndef __BEOS__ 
-#ifndef __cplusplus
-#ifndef bool
-typedef char bool;
-
-#endif	 /* ndef bool */
-#endif	 /* not C++ */
-#ifndef true
-#define true	((bool) 1)
-#endif
-#ifndef false
-#define false	((bool) 0)
-#endif
-#endif /* __BEOS__ */
-typedef bool *BoolPtr;
-
-#ifndef TRUE
-#define TRUE	1
-#endif	 /* TRUE */
-
-#ifndef FALSE
-#define FALSE	0
-#endif	 /* FALSE */
-
-/*
- * NULL
- *		Null pointer.
- */
-#ifndef NULL
-#define NULL	((void *) 0)
-#endif	 /* !defined(NULL) */
 
 /* ----------------------------------------------------------------
- *				Section 2: non-ansi C definitions:
+ *				Section 1: hacks to cope with non-ANSI C compilers
  *
- *				type prefixes: const, signed, volatile, inline
- *				cpp magic macros
+ * type prefixes (const, signed, volatile, inline) are now handled in config.h.
  * ----------------------------------------------------------------
  */
 
@@ -157,6 +117,57 @@ typedef bool *BoolPtr;
 #define dummyret	char
 #endif
 
+
+/* ----------------------------------------------------------------
+ *				Section 2:	bool, true, false, TRUE, FALSE, NULL
+ * ----------------------------------------------------------------
+ */
+/*
+ * bool
+ *		Boolean value, either true or false.
+ *
+ */
+
+/* BeOS defines bool already, but the compiler chokes on the
+ * #ifndef unless we wrap it in this check.
+ */
+#ifndef __BEOS__ 
+
+#ifndef __cplusplus
+#ifndef bool
+typedef char bool;
+#endif	 /* ndef bool */
+#endif	 /* not C++ */
+
+#ifndef true
+#define true	((bool) 1)
+#endif
+
+#ifndef false
+#define false	((bool) 0)
+#endif
+
+#endif /* __BEOS__ */
+
+typedef bool *BoolPtr;
+
+#ifndef TRUE
+#define TRUE	1
+#endif
+
+#ifndef FALSE
+#define FALSE	0
+#endif
+
+/*
+ * NULL
+ *		Null pointer.
+ */
+#ifndef NULL
+#define NULL	((void *) 0)
+#endif
+
+
 /* ----------------------------------------------------------------
  *				Section 3:	standard system types
  * ----------------------------------------------------------------
@@ -182,6 +193,7 @@ typedef signed char int8;		/* == 8 bits */
 typedef signed short int16;		/* == 16 bits */
 typedef signed int int32;		/* == 32 bits */
 #endif /* __BEOS__ */
+
 /*
  * uintN
  *		Unsigned integer, EXACTLY N BITS IN SIZE,
@@ -193,21 +205,6 @@ typedef unsigned char uint8;	/* == 8 bits */
 typedef unsigned short uint16;	/* == 16 bits */
 typedef unsigned int uint32;	/* == 32 bits */
 #endif /* __BEOS__ */
-/*
- * floatN
- *		Floating point number, AT LEAST N BITS IN SIZE,
- *		used for numerical computations.
- *
- *		Since sizeof(floatN) may be > sizeof(char *), always pass
- *		floatN by reference.
- *
- * XXX: these typedefs are now deprecated in favor of float4 and float8.
- * They will eventually go away.
- */
-typedef float float32data;
-typedef double float64data;
-typedef float *float32;
-typedef double *float64;
 
 /*
  * boolN
@@ -235,44 +232,24 @@ typedef uint16 word16;			/* >= 16 bits */
 typedef uint32 word32;			/* >= 32 bits */
 
 /*
- * Size
- *		Size of any memory resident object, as returned by sizeof.
- */
-typedef size_t Size;
-
-/*
- * Index
- *		Index into any memory resident array.
+ * floatN
+ *		Floating point number, AT LEAST N BITS IN SIZE,
+ *		used for numerical computations.
  *
- * Note:
- *		Indices are non negative.
- */
-typedef unsigned int Index;
-
-#define MAXDIM 6
-typedef struct
-{
-	int			indx[MAXDIM];
-} IntArray;
-
-/*
- * Offset
- *		Offset into any memory resident array.
+ *		Since sizeof(floatN) may be > sizeof(char *), always pass
+ *		floatN by reference.
  *
- * Note:
- *		This differs from an Index in that an Index is always
- *		non negative, whereas Offset may be negative.
+ * XXX: these typedefs are now deprecated in favor of float4 and float8.
+ * They will eventually go away.
  */
-typedef signed int Offset;
+typedef float float32data;
+typedef double float64data;
+typedef float *float32;
+typedef double *float64;
 
 /*
- * Common Postgres datatypes.
+ * 64-bit integers
  */
-typedef int16 int2;
-typedef int32 int4;
-typedef float float4;
-typedef double float8;
-
 #ifndef __BEOS__ /* this is already defined on BeOS */
 #ifdef HAVE_LONG_INT_64
 /* Plain "long int" fits, use it */
@@ -292,344 +269,117 @@ typedef unsigned long int uint64;
 #endif
 #endif /* __BEOS__ */
 
-/* ----------------------------------------------------------------
- *				Section 4:	datum type + support macros
- * ----------------------------------------------------------------
- */
-/*
- * datum.h
- *		POSTGRES abstract data type datum representation definitions.
- *
- * Note:
- *
- * Port Notes:
- *	Postgres makes the following assumption about machines:
- *
- *	sizeof(Datum) == sizeof(long) >= sizeof(void *) >= 4
- *
- *	Postgres also assumes that
- *
- *	sizeof(char) == 1
- *
- *	and that
- *
- *	sizeof(short) == 2
- *
- *	If your machine meets these requirements, Datums should also be checked
- *	to see if the positioning is correct.
- */
-
-typedef unsigned long Datum;	/* XXX sizeof(long) >= sizeof(void *) */
-typedef Datum *DatumPtr;
-
-#define GET_1_BYTE(datum)	(((Datum) (datum)) & 0x000000ff)
-#define GET_2_BYTES(datum)	(((Datum) (datum)) & 0x0000ffff)
-#define GET_4_BYTES(datum)	(((Datum) (datum)) & 0xffffffff)
-#define SET_1_BYTE(value)	(((Datum) (value)) & 0x000000ff)
-#define SET_2_BYTES(value)	(((Datum) (value)) & 0x0000ffff)
-#define SET_4_BYTES(value)	(((Datum) (value)) & 0xffffffff)
-
-/*
- * DatumGetBool
- *		Returns boolean value of a datum.
- *
- * Note: any nonzero value will be considered TRUE.
- */
-
-#define DatumGetBool(X) ((bool) (((Datum) (X)) != 0))
-
-/*
- * BoolGetDatum
- *		Returns datum representation for a boolean.
- *
- * Note: any nonzero value will be considered TRUE.
- */
-
-#define BoolGetDatum(X) ((Datum) ((X) ? 1 : 0))
-
-/*
- * DatumGetChar
- *		Returns character value of a datum.
- */
-
-#define DatumGetChar(X) ((char) GET_1_BYTE(X))
-
 /*
- * CharGetDatum
- *		Returns datum representation for a character.
- */
-
-#define CharGetDatum(X) ((Datum) SET_1_BYTE(X))
-
-/*
- * Int8GetDatum
- *		Returns datum representation for an 8-bit integer.
- */
-
-#define Int8GetDatum(X) ((Datum) SET_1_BYTE(X))
-
-/*
- * DatumGetUInt8
- *		Returns 8-bit unsigned integer value of a datum.
- */
-
-#define DatumGetUInt8(X) ((uint8) GET_1_BYTE(X))
-
-/*
- * UInt8GetDatum
- *		Returns datum representation for an 8-bit unsigned integer.
- */
-
-#define UInt8GetDatum(X) ((Datum) SET_1_BYTE(X))
-
-/*
- * DatumGetInt16
- *		Returns 16-bit integer value of a datum.
- */
-
-#define DatumGetInt16(X) ((int16) GET_2_BYTES(X))
-
-/*
- * Int16GetDatum
- *		Returns datum representation for a 16-bit integer.
- */
-
-#define Int16GetDatum(X) ((Datum) SET_2_BYTES(X))
-
-/*
- * DatumGetUInt16
- *		Returns 16-bit unsigned integer value of a datum.
- */
-
-#define DatumGetUInt16(X) ((uint16) GET_2_BYTES(X))
-
-/*
- * UInt16GetDatum
- *		Returns datum representation for a 16-bit unsigned integer.
- */
-
-#define UInt16GetDatum(X) ((Datum) SET_2_BYTES(X))
-
-/*
- * DatumGetInt32
- *		Returns 32-bit integer value of a datum.
- */
-
-#define DatumGetInt32(X) ((int32) GET_4_BYTES(X))
-
-/*
- * Int32GetDatum
- *		Returns datum representation for a 32-bit integer.
- */
-
-#define Int32GetDatum(X) ((Datum) SET_4_BYTES(X))
-
-/*
- * DatumGetUInt32
- *		Returns 32-bit unsigned integer value of a datum.
- */
-
-#define DatumGetUInt32(X) ((uint32) GET_4_BYTES(X))
-
-/*
- * UInt32GetDatum
- *		Returns datum representation for a 32-bit unsigned integer.
- */
-
-#define UInt32GetDatum(X) ((Datum) SET_4_BYTES(X))
-
-/*
- * DatumGetObjectId
- *		Returns object identifier value of a datum.
- */
-
-#define DatumGetObjectId(X) ((Oid) GET_4_BYTES(X))
-
-/*
- * ObjectIdGetDatum
- *		Returns datum representation for an object identifier.
- */
-
-#define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
-
-/*
- * DatumGetPointer
- *		Returns pointer value of a datum.
- */
-
-#define DatumGetPointer(X) ((Pointer) (X))
-
-/*
- * PointerGetDatum
- *		Returns datum representation for a pointer.
- */
-
-#define PointerGetDatum(X) ((Datum) (X))
-
-/*
- * DatumGetCString
- *		Returns C string (null-terminated string) value of a datum.
- *
- * Note: C string is not a full-fledged Postgres type at present,
- * but type input functions use this conversion for their inputs.
- */
-
-#define DatumGetCString(X) ((char *) DatumGetPointer(X))
-
-/*
- * CStringGetDatum
- *		Returns datum representation for a C string (null-terminated string).
- *
- * Note: C string is not a full-fledged Postgres type at present,
- * but type output functions use this conversion for their outputs.
- * Note: CString is pass-by-reference; caller must ensure the pointed-to
- * value has adequate lifetime.
- */
-
-#define CStringGetDatum(X) PointerGetDatum(X)
-
-/*
- * DatumGetName
- *		Returns name value of a datum.
- */
-
-#define DatumGetName(X) ((Name) DatumGetPointer(X))
-
-/*
- * NameGetDatum
- *		Returns datum representation for a name.
- *
- * Note: Name is pass-by-reference; caller must ensure the pointed-to
- * value has adequate lifetime.
+ * Size
+ *		Size of any memory resident object, as returned by sizeof.
  */
-
-#define NameGetDatum(X) PointerGetDatum(X)
+typedef size_t Size;
 
 /*
- * DatumGetInt64
- *		Returns 64-bit integer value of a datum.
+ * Index
+ *		Index into any memory resident array.
  *
- * Note: this macro hides the fact that int64 is currently a
- * pass-by-reference type.  Someday it may be pass-by-value,
- * at least on some platforms.
+ * Note:
+ *		Indices are non negative.
  */
-
-#define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
+typedef unsigned int Index;
 
 /*
- * Int64GetDatum
- *		Returns datum representation for a 64-bit integer.
+ * Offset
+ *		Offset into any memory resident array.
  *
- * Note: this routine returns a reference to palloc'd space.
+ * Note:
+ *		This differs from an Index in that an Index is always
+ *		non negative, whereas Offset may be negative.
  */
-
-extern Datum Int64GetDatum(int64 X);
+typedef signed int Offset;
 
 /*
- * DatumGetFloat4
- *		Returns 4-byte floating point value of a datum.
- *
- * Note: this macro hides the fact that float4 is currently a
- * pass-by-reference type.  Someday it may be pass-by-value.
+ * Common Postgres datatype names (as used in the catalogs)
  */
-
-#define DatumGetFloat4(X) (* ((float4 *) DatumGetPointer(X)))
+typedef int16 int2;
+typedef int32 int4;
+typedef float float4;
+typedef double float8;
 
 /*
- * Float4GetDatum
- *		Returns datum representation for a 4-byte floating point number.
- *
- * Note: this routine returns a reference to palloc'd space.
+ * Oid, RegProcedure, TransactionId, CommandId
  */
 
-extern Datum Float4GetDatum(float4 X);
+/* typedef Oid is in postgres_ext.h */
 
-/*
- * DatumGetFloat8
- *		Returns 8-byte floating point value of a datum.
- *
- * Note: this macro hides the fact that float8 is currently a
- * pass-by-reference type.  Someday it may be pass-by-value,
- * at least on some platforms.
- */
+/* unfortunately, both regproc and RegProcedure are used */
+typedef Oid regproc;
+typedef Oid RegProcedure;
 
-#define DatumGetFloat8(X) (* ((float8 *) DatumGetPointer(X)))
+typedef uint32 TransactionId;
 
-/*
- * Float8GetDatum
- *		Returns datum representation for an 8-byte floating point number.
- *
- * Note: this routine returns a reference to palloc'd space.
- */
+#define InvalidTransactionId	0
 
-extern Datum Float8GetDatum(float8 X);
+typedef uint32 CommandId;
 
+#define FirstCommandId	0
 
 /*
- * DatumGetFloat32
- *		Returns 32-bit floating point value of a datum.
- *		This is really a pointer, of course.
- *
- * XXX: this macro is now deprecated in favor of DatumGetFloat4.
- * It will eventually go away.
+ * Array indexing support
  */
+#define MAXDIM 6
+typedef struct
+{
+	int			indx[MAXDIM];
+} IntArray;
 
-#define DatumGetFloat32(X) ((float32) DatumGetPointer(X))
-
-/*
- * Float32GetDatum
- *		Returns datum representation for a 32-bit floating point number.
- *		This is really a pointer, of course.
+/* ----------------
+ *		Variable-length datatypes all share the 'struct varlena' header.
  *
- * XXX: this macro is now deprecated in favor of Float4GetDatum.
- * It will eventually go away.
+ * NOTE: for TOASTable types, this is an oversimplification, since the value may be
+ * compressed or moved out-of-line.  However datatype-specific routines are mostly
+ * content to deal with de-TOASTed values only, and of course client-side routines
+ * should never see a TOASTed value.  See postgres.h for details of the TOASTed form.
+ * ----------------
  */
+struct varlena
+{
+	int32		vl_len;
+	char		vl_dat[1];
+};
 
-#define Float32GetDatum(X) PointerGetDatum(X)
+#define VARHDRSZ		((int32) sizeof(int32))
 
 /*
- * DatumGetFloat64
- *		Returns 64-bit floating point value of a datum.
- *		This is really a pointer, of course.
- *
- * XXX: this macro is now deprecated in favor of DatumGetFloat8.
- * It will eventually go away.
+ * These widely-used datatypes are just a varlena header and the data bytes.
+ * There is no terminating null or anything like that --- the data length is
+ * always VARSIZE(ptr) - VARHDRSZ.
  */
-
-#define DatumGetFloat64(X) ((float64) DatumGetPointer(X))
+typedef struct varlena bytea;
+typedef struct varlena text;
+typedef struct varlena BpChar;	/* blank-padded char, ie SQL char(n) */
+typedef struct varlena VarChar;	/* var-length char, ie SQL varchar(n) */
 
 /*
- * Float64GetDatum
- *		Returns datum representation for a 64-bit floating point number.
- *		This is really a pointer, of course.
- *
- * XXX: this macro is now deprecated in favor of Float8GetDatum.
- * It will eventually go away.
+ * Fixed-length array types (these are not varlena's!)
  */
 
-#define Float64GetDatum(X) PointerGetDatum(X)
+typedef int2 int2vector[INDEX_MAX_KEYS];
+typedef Oid oidvector[INDEX_MAX_KEYS];
 
 /*
- * Int64GetDatumFast
- * Float4GetDatumFast
- * Float8GetDatumFast
- *
- * These macros are intended to allow writing code that does not depend on
- * whether int64, float4, float8 are pass-by-reference types, while not
- * sacrificing performance when they are.  The argument must be a variable
- * that will exist and have the same value for as long as the Datum is needed.
- * In the pass-by-ref case, the address of the variable is taken to use as
- * the Datum.  In the pass-by-val case, these will be the same as the non-Fast
- * macros.
+ * We want NameData to have length NAMEDATALEN and int alignment,
+ * because that's how the data type 'name' is defined in pg_type.
+ * Use a union to make sure the compiler agrees.
  */
+typedef union nameData
+{
+	char		data[NAMEDATALEN];
+	int			alignmentDummy;
+} NameData;
+typedef NameData *Name;
 
-#define Int64GetDatumFast(X)  PointerGetDatum(&(X))
-#define Float4GetDatumFast(X) PointerGetDatum(&(X))
-#define Float8GetDatumFast(X) PointerGetDatum(&(X))
+#define NameStr(name)	((name).data)
 
 
 /* ----------------------------------------------------------------
- *				Section 5:	IsValid macros for system types
+ *				Section 4:	IsValid macros for system types
  * ----------------------------------------------------------------
  */
 /*
@@ -651,8 +401,13 @@ extern Datum Float8GetDatum(float8 X);
 #define PointerIsAligned(pointer, type) \
 		(((long)(pointer) % (sizeof (type))) == 0)
 
+#define OidIsValid(objectId)  ((bool) ((objectId) != InvalidOid))
+
+#define RegProcedureIsValid(p)	OidIsValid(p)
+
+
 /* ----------------------------------------------------------------
- *				Section 6:	offsetof, lengthof, endof
+ *				Section 5:	offsetof, lengthof, endof, alignment
  * ----------------------------------------------------------------
  */
 /*
@@ -678,125 +433,28 @@ extern Datum Float8GetDatum(float8 X);
  */
 #define endof(array)	(&array[lengthof(array)])
 
-/* ----------------------------------------------------------------
- *				Section 7:	exception handling definitions
- *							Assert, Trap, etc macros
- * ----------------------------------------------------------------
- */
-/*
- * Exception Handling definitions
- */
-
-typedef char *ExcMessage;
-typedef struct Exception
-{
-	ExcMessage	message;
-} Exception;
-
-/*
- * USE_ASSERT_CHECKING, if defined, turns on all the assertions.
- * - plai  9/5/90
- *
- * It should _NOT_ be defined in releases or in benchmark copies
- */
-
-/*
- * Trap
- *		Generates an exception if the given condition is true.
- *
- */
-#define Trap(condition, exception) \
-		do { \
-			if ((assert_enabled) && (condition)) \
-				ExceptionalCondition(CppAsString(condition), &(exception), \
-						(char*)NULL, __FILE__, __LINE__); \
-		} while (0)
-
-/*
- *	TrapMacro is the same as Trap but it's intended for use in macros:
+/* ----------------
+ * Alignment macros: align a length or address appropriately for a given type.
  *
- *		#define foo(x) (AssertM(x != 0) && bar(x))
- *
- *	Isn't CPP fun?
- */
-#define TrapMacro(condition, exception) \
-	((bool) ((! assert_enabled) || ! (condition) || \
-			 (ExceptionalCondition(CppAsString(condition), \
-								  &(exception), \
-								  (char*) NULL, __FILE__, __LINE__))))
-
-#ifndef USE_ASSERT_CHECKING
-#define Assert(condition)
-#define AssertMacro(condition)	((void)true)
-#define AssertArg(condition)
-#define AssertState(condition)
-#define assert_enabled 0
-#else
-#define Assert(condition) \
-		Trap(!(condition), FailedAssertion)
-
-#define AssertMacro(condition) \
-		((void) TrapMacro(!(condition), FailedAssertion))
-
-#define AssertArg(condition) \
-		Trap(!(condition), BadArg)
-
-#define AssertState(condition) \
-		Trap(!(condition), BadState)
-
-extern bool	assert_enabled;
-
-#endif	 /* USE_ASSERT_CHECKING */
-
-/*
- * LogTrap
- *		Generates an exception with a message if the given condition is true.
+ * There used to be some incredibly crufty platform-dependent hackery here,
+ * but now we rely on the configure script to get the info for us. Much nicer.
  *
+ * NOTE: TYPEALIGN will not work if ALIGNVAL is not a power of 2.
+ * That case seems extremely unlikely to occur in practice, however.
+ * ----------------
  */
-#define LogTrap(condition, exception, printArgs) \
-		do { \
-			if ((assert_enabled) && (condition)) \
-				ExceptionalCondition(CppAsString(condition), &(exception), \
-						vararg_format printArgs, __FILE__, __LINE__); \
-		} while (0)
-
-/*
- *	LogTrapMacro is the same as LogTrap but it's intended for use in macros:
- *
- *		#define foo(x) (LogAssertMacro(x != 0, "yow!") && bar(x))
- */
-#define LogTrapMacro(condition, exception, printArgs) \
-	((bool) ((! assert_enabled) || ! (condition) || \
-			 (ExceptionalCondition(CppAsString(condition), \
-								   &(exception), \
-								   vararg_format printArgs, __FILE__, __LINE__))))
-
-#ifndef USE_ASSERT_CHECKING
-#define LogAssert(condition, printArgs)
-#define LogAssertMacro(condition, printArgs) true
-#define LogAssertArg(condition, printArgs)
-#define LogAssertState(condition, printArgs)
-#else
-#define LogAssert(condition, printArgs) \
-		LogTrap(!(condition), FailedAssertion, printArgs)
 
-#define LogAssertMacro(condition, printArgs) \
-		LogTrapMacro(!(condition), FailedAssertion, printArgs)
+#define TYPEALIGN(ALIGNVAL,LEN) (((long)(LEN) + (ALIGNVAL-1)) & ~(ALIGNVAL-1))
 
-#define LogAssertArg(condition, printArgs) \
-		LogTrap(!(condition), BadArg, printArgs)
+#define SHORTALIGN(LEN)			TYPEALIGN(ALIGNOF_SHORT, (LEN))
+#define INTALIGN(LEN)			TYPEALIGN(ALIGNOF_INT, (LEN))
+#define LONGALIGN(LEN)			TYPEALIGN(ALIGNOF_LONG, (LEN))
+#define DOUBLEALIGN(LEN)		TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
+#define MAXALIGN(LEN)			TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
 
-#define LogAssertState(condition, printArgs) \
-		LogTrap(!(condition), BadState, printArgs)
-
-#ifdef ASSERT_CHECKING_TEST
-extern int	assertTest(int val);
-
-#endif
-#endif	 /* USE_ASSERT_CHECKING */
 
 /* ----------------------------------------------------------------
- *				Section 8:	Min, Max, Abs macros
+ *				Section 6:	widely useful macros
  * ----------------------------------------------------------------
  */
 /*
@@ -887,56 +545,30 @@ extern int	assertTest(int val);
 
 
 /* ----------------------------------------------------------------
- *				Section 9: externs
- * ----------------------------------------------------------------
- */
-
-extern Exception FailedAssertion;
-extern Exception BadArg;
-extern Exception BadState;
-
-/* in utils/error/assert.c */
-extern int ExceptionalCondition(char *conditionName,
-					 Exception *exceptionP, char *details,
-					 char *fileName, int lineNumber);
-
-
-/* ----------------
- *		vararg_format is used by assert and the exception handling stuff
- * ----------------
- */
-extern char *vararg_format(const char *fmt,...);
-
-
-
-/* ----------------------------------------------------------------
- *				Section 10: berkeley-specific configuration
- *
- * this section contains settings which are only relevant to the UC Berkeley
- * sites.  Other sites can ignore this
+ *				Section 7:	random stuff
  * ----------------------------------------------------------------
  */
 
-/* ----------------
- *		storage managers
- *
- *		These are experimental and are not supported in the code that
- *		we distribute to other sites.
- * ----------------
- */
-#ifdef NOT_USED
-#define STABLE_MEMORY_STORAGE
-#endif
+/* msb for char */
+#define CSIGNBIT (0x80)
 
+#define STATUS_OK				(0)
+#define STATUS_ERROR			(-1)
+#define STATUS_NOT_FOUND		(-2)
+#define STATUS_INVALID			(-3)
+#define STATUS_UNCATALOGUED		(-4)
+#define STATUS_REPLACED			(-5)
+#define STATUS_NOT_DONE			(-6)
+#define STATUS_BAD_PACKET		(-7)
+#define STATUS_FOUND			(1)
 
 
 /* ----------------------------------------------------------------
- *				Section 11: system-specific hacks
+ *				Section 8: system-specific hacks
  *
  *		This should be limited to things that absolutely have to be
- *		included in every source file.	The changes should be factored
- *		into a separate file so that changes to one port don't require
- *		changes to c.h (and everyone recompiling their whole system).
+ *		included in every source file.  The port-specific header file
+ *		is usually a better place for this sort of thing.
  * ----------------------------------------------------------------
  */
 
@@ -951,7 +583,6 @@ extern char *vararg_format(const char *fmt,...);
 #endif
 
 #if defined(sun) && defined(__sparc__) && !defined(__SVR4)
-#define memmove(d, s, l)		bcopy(s, d, l)
 #include <unistd.h>
 #include <varargs.h>
 #endif
@@ -989,8 +620,8 @@ extern int	vsnprintf(char *str, size_t count, const char *fmt, va_list args);
 
 #endif
 
-#ifndef HAVE_MEMMOVE
-#include <regex/utils.h>
+#if !defined(HAVE_MEMMOVE) && !defined(memmove)
+#define memmove(d, s, c)		bcopy(s, d, c)
 #endif
 
 /* ----------------
diff --git a/src/include/executor/spi.h b/src/include/executor/spi.h
index 2db0c5d5779634fa3ad439878eb7e4b2f6c1d62b..4834ab4dd871a57d98fcca36da24736f7b8521fe 100644
--- a/src/include/executor/spi.h
+++ b/src/include/executor/spi.h
@@ -8,6 +8,10 @@
 #ifndef SPI_H
 #define SPI_H
 
+/*
+ * This file may be used by client modules that haven't already
+ * included postgres.h
+ */
 #include "postgres.h"
 
 /*
diff --git a/src/include/libpq/libpq-fs.h b/src/include/libpq/libpq-fs.h
index 79aa4be80bd59bd869bba3bcf7dfcb051184271c..64ded84dbc1870c56446165f144f5f8d7d49b785 100644
--- a/src/include/libpq/libpq-fs.h
+++ b/src/include/libpq/libpq-fs.h
@@ -1,95 +1,24 @@
 /*-------------------------------------------------------------------------
  *
  * libpq-fs.h
- *	  definitions for using Inversion file system routines
+ *	  definitions for using Inversion file system routines (ie, large objects)
  *
  *
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: libpq-fs.h,v 1.11 2001/01/24 19:43:25 momjian Exp $
+ * $Id: libpq-fs.h,v 1.12 2001/02/10 02:31:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef LIBPQ_FS_H
 #define LIBPQ_FS_H
 
-/* UNIX compatibility junk.  This should be in all systems' include files,
-   but this is not always the case. */
-
-#ifndef MAXNAMLEN
-#define MAXNAMLEN 255
-#endif	 /* MAXNAMLEN */
-
-struct pgdirent
-{
-	unsigned long d_ino;
-	unsigned short d_namlen;
-	char		d_name[MAXNAMLEN + 1];
-};
-
-
-/* for stat(2) */
-#ifndef S_IRUSR
-/* file modes */
-
-#define S_IRWXU 00700			/* read, write, execute: owner */
-#define S_IRUSR 00400			/* read permission: owner */
-#define S_IWUSR 00200			/* write permission: owner */
-#define S_IXUSR 00100			/* execute permission: owner */
-
-#define S_IRWXG 00070			/* read, write, execute: group */
-#define S_IRGRP 00040			/* read permission: group */
-#define S_IWGRP 00020			/* write permission: group */
-#define S_IXGRP 00010			/* execute permission: group */
-
-#define S_IRWXO 00007			/* read, write, execute: other */
-#define S_IROTH 00004			/* read permission: other */
-#define S_IWOTH 00002			/* write permission: other */
-#define S_IXOTH 00001			/* execute permission: other */
-
-#define _S_IFMT  0170000		/* type of file; sync with S_IFMT */
-#define _S_IFBLK 0060000		/* block special; sync with S_IFBLK */
-#define _S_IFCHR 0020000		/* character special sync with S_IFCHR */
-#define _S_IFDIR 0040000		/* directory; sync with S_IFDIR */
-#define _S_IFIFO 0010000		/* FIFO - named pipe; sync with S_IFIFO */
-#define _S_IFREG 0100000		/* regular; sync with S_IFREG */
-
-#define S_IFDIR _S_IFDIR
-#define S_IFREG _S_IFREG
-
-#define S_ISDIR( mode )			(((mode) & _S_IFMT) == _S_IFDIR)
-
-#endif	 /* S_IRUSR */
-
 /*
- * Inversion doesn't have links.
- */
-#ifndef S_ISLNK
-#define S_ISLNK(x) 0
-#endif
-
-/*
- *	Flags for inversion file system large objects.	Normally, creat()
- *	takes mode arguments, but we don't use them in inversion, since
- *	you get postgres protections.  Instead, we use the low sixteen bits
- *	of the integer mode argument to store the number of the storage
- *	manager to be used, and the high sixteen bits for flags.
+ *	Read/write mode flags for inversion (large object) calls
  */
 
 #define INV_WRITE		0x00020000
 #define INV_READ		0x00040000
 
-/* Error values for p_errno */
-#define PEPERM			 1		/* Not owner */
-#define PENOENT			 2		/* No such file or directory */
-#define PEACCES			 13		/* Permission denied */
-#define PEEXIST			 17		/* File exists */
-#define PENOTDIR		 20		/* Not a directory */
-#define PEISDIR			 21		/* Is a directory */
-#define PEINVAL			 22		/* Invalid argument */
-#define PENAMETOOLONG	 63		/* File name too long */
-#define PENOTEMPTY		 66		/* Directory not empty */
-#define PEPGIO			 99		/* postgres backend had problems */
-
 #endif	 /* LIBPQ_FS_H */
diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index d7c6fb9fe4cf457f84c65bd1108bd4fea5db7a38..b952891411b2046ff3af4936835afdea5c7e5b74 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -9,18 +9,16 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pqcomm.h,v 1.53 2001/01/24 19:43:25 momjian Exp $
+ * $Id: pqcomm.h,v 1.54 2001/02/10 02:31:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef PQCOMM_H
 #define PQCOMM_H
 
-#include "postgres.h"
-
 #include <sys/types.h>
 #ifdef WIN32
-# include "winsock.h"
+# include <winsock.h>
 #else /* not WIN32 */
 # include <sys/socket.h>
 # ifdef HAVE_SYS_UN_H
diff --git a/src/include/mb/pg_wchar.h b/src/include/mb/pg_wchar.h
index 0b0c2e31377dd5dffeb1121f38fb0caac6d7b929..b137da7cec47fc94d6e18385f4dc12912c892f9b 100644
--- a/src/include/mb/pg_wchar.h
+++ b/src/include/mb/pg_wchar.h
@@ -1,9 +1,8 @@
-/* $Id: pg_wchar.h,v 1.23 2000/11/14 18:37:48 tgl Exp $ */
+/* $Id: pg_wchar.h,v 1.24 2001/02/10 02:31:28 tgl Exp $ */
 
 #ifndef PG_WCHAR_H
 #define PG_WCHAR_H
 
-#include "postgres.h"
 #include <sys/types.h>
 
 #ifdef FRONTEND
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
index fa73145787bc4bb3f8044bd102e25fc4da0199df..46d7ab534ea18e53058132bd3ad518ddd655b7c2 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: miscadmin.h,v 1.80 2001/01/27 00:05:31 tgl Exp $
+ * $Id: miscadmin.h,v 1.81 2001/02/10 02:31:28 tgl Exp $
  *
  * NOTES
  *	  some of the information in this file should be moved to
@@ -216,6 +216,8 @@ extern int	FindExec(char *full_path, const char *argv0,
 extern int	CheckPathAccess(char *path, char *name, int open_mode);
 
 #ifdef CYR_RECODE
+extern void GetCharSetByHost(char *TableName, int host, const char *DataDir);
+extern void SetCharSet(void);
 extern char *convertstr(unsigned char *buff, int len, int dest);
 #endif
 
diff --git a/src/include/postgres.h b/src/include/postgres.h
index 5ff6446e6f014c14955efb524e7bdfbfb20b5749..fbc38197d724f795ada944d1b9b7fd7e2f1e46cb 100644
--- a/src/include/postgres.h
+++ b/src/include/postgres.h
@@ -1,37 +1,45 @@
 /*-------------------------------------------------------------------------
  *
  * postgres.h
- *	  definition of (and support for) postgres system types.
- * this file is included by almost every .c in the system
+ *	  Primary include file for PostgreSQL server .c files
+ *
+ * This should be the first file included by PostgreSQL backend modules.
+ * Client-side code should include postgres_fe.h instead.
+ *
  *
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1995, Regents of the University of California
  *
- * $Id: postgres.h,v 1.45 2001/01/24 19:43:19 momjian Exp $
+ * $Id: postgres.h,v 1.46 2001/02/10 02:31:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 /*
- *	 NOTES
- *		this file will eventually contain the definitions for the
- *		following (and perhaps other) system types:
+ *----------------------------------------------------------------
+ *	 TABLE OF CONTENTS
  *
- *				int2	   int4		  float4	   float8
- *				Oid		   regproc	  RegProcedure
- *				aclitem
- *				struct varlena
- *				int2vector	  oidvector
- *				bytea	   text
- *				NameData   Name
+ *		When adding stuff to this file, please try to put stuff
+ *		into the relevant section, or add new sections as appropriate.
  *
- *	 TABLE OF CONTENTS
- *		1)		simple type definitions
- *		2)		varlena and array types
- *		3)		TransactionId and CommandId
+ *	  section	description
+ *	  -------	------------------------------------------------
+ *		1)		variable-length datatypes (TOAST support)
+ *		2)		datum type + support macros
+ *		3)		exception handling definitions
  *		4)		genbki macros used by catalog/pg_xxx.h files
- *		5)		random stuff
  *
- * ----------------------------------------------------------------
+ *	 NOTES
+ *
+ *	In general, this file should contain declarations that are widely needed in the
+ *	backend environment, but are of no interest outside the backend.
+ *
+ *	Simple type definitions live in c.h, where they are shared with postgres_fe.h.
+ *	We do that since those type definitions are needed by frontend modules that want
+ *	to deal with binary data transmission to or from the backend.  Type definitions
+ *	in this file should be for representations that never escape the backend, such
+ *	as Datum or TOASTed varlena objects.
+ *
+ *----------------------------------------------------------------
  */
 #ifndef POSTGRES_H
 #define POSTGRES_H
@@ -42,59 +50,16 @@
 #include "utils/palloc.h"
 
 /* ----------------------------------------------------------------
- *				Section 1:	simple type definitions
+ *				Section 1:	variable-length datatypes (TOAST support)
  * ----------------------------------------------------------------
  */
 
-#define InvalidOid		((Oid) 0)
-#define OidIsValid(objectId)  ((bool) ((objectId) != InvalidOid))
-
-/* unfortunately, both regproc and RegProcedure are used */
-typedef Oid regproc;
-typedef Oid RegProcedure;
-
-#define RegProcedureIsValid(p)	OidIsValid(p)
-
-typedef int4 aclitem;			/* PHONY definition for catalog use only */
-
-/* ----------------------------------------------------------------
- *				Section 2:	variable length and array types
- * ----------------------------------------------------------------
- */
 /* ----------------
- *		struct varlena
+ *		struct varattrib is the header of a varlena object that may have been TOASTed.
  * ----------------
  */
-struct varlena
-{
-	int32		vl_len;
-	char		vl_dat[1];
-};
-
 #define TUPLE_TOASTER_ACTIVE
 
-#ifndef TUPLE_TOASTER_ACTIVE
-#define VARSIZE(PTR)	(((struct varlena *)(PTR))->vl_len)
-#define VARDATA(PTR)	(((struct varlena *)(PTR))->vl_dat)
-#endif
-#define VARHDRSZ		((int32) sizeof(int32))
-
-/*
- * These widely-used datatypes are just a varlena header and the data bytes.
- * There is no terminating null or anything like that --- the data length is
- * always VARSIZE(ptr) - VARHDRSZ.
- */
-typedef struct varlena bytea;
-typedef struct varlena text;
-typedef struct varlena BpChar;	/* blank-padded char, ie SQL char(n) */
-typedef struct varlena VarChar;	/* var-length char, ie SQL varchar(n) */
-
-/*
- * Proposed new layout for variable length attributes
- * DO NOT USE YET - Jan
- */
-
-#ifdef TUPLE_TOASTER_ACTIVE
 typedef struct varattrib
 {
 	int32		va_header;		/* External/compressed storage */
@@ -142,64 +107,466 @@ typedef struct varattrib
 #define VARATT_IS_COMPRESSED(PTR)	\
 				((VARATT_SIZEP(PTR) & VARATT_FLAG_COMPRESSED) != 0)
 
-/* ----------
- * This is regularly declared in access/tuptoaster.h,
- * but we don't want to include that into every source,
- * so we (evil evil evil) declare it here once more.
- * ----------
+
+/* ----------------------------------------------------------------
+ *				Section 2:	datum type + support macros
+ * ----------------------------------------------------------------
+ */
+
+/*
+ * Port Notes:
+ *	Postgres makes the following assumption about machines:
+ *
+ *	sizeof(Datum) == sizeof(long) >= sizeof(void *) >= 4
+ *
+ *	Postgres also assumes that
+ *
+ *	sizeof(char) == 1
+ *
+ *	and that
+ *
+ *	sizeof(short) == 2
+ *
+ *	If your machine meets these requirements, Datums should also be checked
+ *	to see if the positioning is correct.
+ */
+
+typedef unsigned long Datum;	/* XXX sizeof(long) >= sizeof(void *) */
+typedef Datum *DatumPtr;
+
+#define GET_1_BYTE(datum)	(((Datum) (datum)) & 0x000000ff)
+#define GET_2_BYTES(datum)	(((Datum) (datum)) & 0x0000ffff)
+#define GET_4_BYTES(datum)	(((Datum) (datum)) & 0xffffffff)
+#define SET_1_BYTE(value)	(((Datum) (value)) & 0x000000ff)
+#define SET_2_BYTES(value)	(((Datum) (value)) & 0x0000ffff)
+#define SET_4_BYTES(value)	(((Datum) (value)) & 0xffffffff)
+
+/*
+ * DatumGetBool
+ *		Returns boolean value of a datum.
+ *
+ * Note: any nonzero value will be considered TRUE.
  */
-extern varattrib *heap_tuple_untoast_attr(varattrib * attr);
 
-#define VARATT_GETPLAIN(_ARG,_VAR) {								\
-				if (VARATT_IS_EXTENDED(_ARG))						\
-					(_VAR) = (void *)heap_tuple_untoast_attr(_ARG); \
-				else												\
-					(_VAR) = (void *)(_ARG);						\
-			}
-#define VARATT_FREE(_ARG,_VAR) do {									\
-				if ((void *)(_VAR) != (void *)(_ARG))				\
-					pfree((void *)(_VAR));							\
-			} while (0)
-#else							/* TUPLE_TOASTER_ACTIVE */
-#define VARATT_SIZE(__PTR) VARSIZE(__PTR)
-#define VARATT_SIZEP(__PTR) VARSIZE(__PTR)
-#endif	 /* TUPLE_TOASTER_ACTIVE */
+#define DatumGetBool(X) ((bool) (((Datum) (X)) != 0))
+
+/*
+ * BoolGetDatum
+ *		Returns datum representation for a boolean.
+ *
+ * Note: any nonzero value will be considered TRUE.
+ */
 
+#define BoolGetDatum(X) ((Datum) ((X) ? 1 : 0))
 
-/* fixed-length array types (these are not varlena's!) */
+/*
+ * DatumGetChar
+ *		Returns character value of a datum.
+ */
 
-typedef int2 int2vector[INDEX_MAX_KEYS];
-typedef Oid oidvector[INDEX_MAX_KEYS];
+#define DatumGetChar(X) ((char) GET_1_BYTE(X))
 
-/* We want NameData to have length NAMEDATALEN and int alignment,
- * because that's how the data type 'name' is defined in pg_type.
- * Use a union to make sure the compiler agrees.
+/*
+ * CharGetDatum
+ *		Returns datum representation for a character.
+ */
+
+#define CharGetDatum(X) ((Datum) SET_1_BYTE(X))
+
+/*
+ * Int8GetDatum
+ *		Returns datum representation for an 8-bit integer.
+ */
+
+#define Int8GetDatum(X) ((Datum) SET_1_BYTE(X))
+
+/*
+ * DatumGetUInt8
+ *		Returns 8-bit unsigned integer value of a datum.
+ */
+
+#define DatumGetUInt8(X) ((uint8) GET_1_BYTE(X))
+
+/*
+ * UInt8GetDatum
+ *		Returns datum representation for an 8-bit unsigned integer.
+ */
+
+#define UInt8GetDatum(X) ((Datum) SET_1_BYTE(X))
+
+/*
+ * DatumGetInt16
+ *		Returns 16-bit integer value of a datum.
+ */
+
+#define DatumGetInt16(X) ((int16) GET_2_BYTES(X))
+
+/*
+ * Int16GetDatum
+ *		Returns datum representation for a 16-bit integer.
+ */
+
+#define Int16GetDatum(X) ((Datum) SET_2_BYTES(X))
+
+/*
+ * DatumGetUInt16
+ *		Returns 16-bit unsigned integer value of a datum.
+ */
+
+#define DatumGetUInt16(X) ((uint16) GET_2_BYTES(X))
+
+/*
+ * UInt16GetDatum
+ *		Returns datum representation for a 16-bit unsigned integer.
+ */
+
+#define UInt16GetDatum(X) ((Datum) SET_2_BYTES(X))
+
+/*
+ * DatumGetInt32
+ *		Returns 32-bit integer value of a datum.
+ */
+
+#define DatumGetInt32(X) ((int32) GET_4_BYTES(X))
+
+/*
+ * Int32GetDatum
+ *		Returns datum representation for a 32-bit integer.
+ */
+
+#define Int32GetDatum(X) ((Datum) SET_4_BYTES(X))
+
+/*
+ * DatumGetUInt32
+ *		Returns 32-bit unsigned integer value of a datum.
+ */
+
+#define DatumGetUInt32(X) ((uint32) GET_4_BYTES(X))
+
+/*
+ * UInt32GetDatum
+ *		Returns datum representation for a 32-bit unsigned integer.
+ */
+
+#define UInt32GetDatum(X) ((Datum) SET_4_BYTES(X))
+
+/*
+ * DatumGetObjectId
+ *		Returns object identifier value of a datum.
+ */
+
+#define DatumGetObjectId(X) ((Oid) GET_4_BYTES(X))
+
+/*
+ * ObjectIdGetDatum
+ *		Returns datum representation for an object identifier.
+ */
+
+#define ObjectIdGetDatum(X) ((Datum) SET_4_BYTES(X))
+
+/*
+ * DatumGetPointer
+ *		Returns pointer value of a datum.
+ */
+
+#define DatumGetPointer(X) ((Pointer) (X))
+
+/*
+ * PointerGetDatum
+ *		Returns datum representation for a pointer.
  */
-typedef union nameData
-{
-	char		data[NAMEDATALEN];
-	int			alignmentDummy;
-} NameData;
-typedef NameData *Name;
 
-#define NameStr(name)	((name).data)
+#define PointerGetDatum(X) ((Datum) (X))
+
+/*
+ * DatumGetCString
+ *		Returns C string (null-terminated string) value of a datum.
+ *
+ * Note: C string is not a full-fledged Postgres type at present,
+ * but type input functions use this conversion for their inputs.
+ */
+
+#define DatumGetCString(X) ((char *) DatumGetPointer(X))
+
+/*
+ * CStringGetDatum
+ *		Returns datum representation for a C string (null-terminated string).
+ *
+ * Note: C string is not a full-fledged Postgres type at present,
+ * but type output functions use this conversion for their outputs.
+ * Note: CString is pass-by-reference; caller must ensure the pointed-to
+ * value has adequate lifetime.
+ */
+
+#define CStringGetDatum(X) PointerGetDatum(X)
+
+/*
+ * DatumGetName
+ *		Returns name value of a datum.
+ */
+
+#define DatumGetName(X) ((Name) DatumGetPointer(X))
+
+/*
+ * NameGetDatum
+ *		Returns datum representation for a name.
+ *
+ * Note: Name is pass-by-reference; caller must ensure the pointed-to
+ * value has adequate lifetime.
+ */
+
+#define NameGetDatum(X) PointerGetDatum(X)
+
+/*
+ * DatumGetInt64
+ *		Returns 64-bit integer value of a datum.
+ *
+ * Note: this macro hides the fact that int64 is currently a
+ * pass-by-reference type.  Someday it may be pass-by-value,
+ * at least on some platforms.
+ */
+
+#define DatumGetInt64(X) (* ((int64 *) DatumGetPointer(X)))
+
+/*
+ * Int64GetDatum
+ *		Returns datum representation for a 64-bit integer.
+ *
+ * Note: this routine returns a reference to palloc'd space.
+ */
+
+extern Datum Int64GetDatum(int64 X);
+
+/*
+ * DatumGetFloat4
+ *		Returns 4-byte floating point value of a datum.
+ *
+ * Note: this macro hides the fact that float4 is currently a
+ * pass-by-reference type.  Someday it may be pass-by-value.
+ */
+
+#define DatumGetFloat4(X) (* ((float4 *) DatumGetPointer(X)))
+
+/*
+ * Float4GetDatum
+ *		Returns datum representation for a 4-byte floating point number.
+ *
+ * Note: this routine returns a reference to palloc'd space.
+ */
+
+extern Datum Float4GetDatum(float4 X);
+
+/*
+ * DatumGetFloat8
+ *		Returns 8-byte floating point value of a datum.
+ *
+ * Note: this macro hides the fact that float8 is currently a
+ * pass-by-reference type.  Someday it may be pass-by-value,
+ * at least on some platforms.
+ */
+
+#define DatumGetFloat8(X) (* ((float8 *) DatumGetPointer(X)))
+
+/*
+ * Float8GetDatum
+ *		Returns datum representation for an 8-byte floating point number.
+ *
+ * Note: this routine returns a reference to palloc'd space.
+ */
+
+extern Datum Float8GetDatum(float8 X);
+
+
+/*
+ * DatumGetFloat32
+ *		Returns 32-bit floating point value of a datum.
+ *		This is really a pointer, of course.
+ *
+ * XXX: this macro is now deprecated in favor of DatumGetFloat4.
+ * It will eventually go away.
+ */
+
+#define DatumGetFloat32(X) ((float32) DatumGetPointer(X))
+
+/*
+ * Float32GetDatum
+ *		Returns datum representation for a 32-bit floating point number.
+ *		This is really a pointer, of course.
+ *
+ * XXX: this macro is now deprecated in favor of Float4GetDatum.
+ * It will eventually go away.
+ */
+
+#define Float32GetDatum(X) PointerGetDatum(X)
+
+/*
+ * DatumGetFloat64
+ *		Returns 64-bit floating point value of a datum.
+ *		This is really a pointer, of course.
+ *
+ * XXX: this macro is now deprecated in favor of DatumGetFloat8.
+ * It will eventually go away.
+ */
+
+#define DatumGetFloat64(X) ((float64) DatumGetPointer(X))
+
+/*
+ * Float64GetDatum
+ *		Returns datum representation for a 64-bit floating point number.
+ *		This is really a pointer, of course.
+ *
+ * XXX: this macro is now deprecated in favor of Float8GetDatum.
+ * It will eventually go away.
+ */
+
+#define Float64GetDatum(X) PointerGetDatum(X)
+
+/*
+ * Int64GetDatumFast
+ * Float4GetDatumFast
+ * Float8GetDatumFast
+ *
+ * These macros are intended to allow writing code that does not depend on
+ * whether int64, float4, float8 are pass-by-reference types, while not
+ * sacrificing performance when they are.  The argument must be a variable
+ * that will exist and have the same value for as long as the Datum is needed.
+ * In the pass-by-ref case, the address of the variable is taken to use as
+ * the Datum.  In the pass-by-val case, these will be the same as the non-Fast
+ * macros.
+ */
+
+#define Int64GetDatumFast(X)  PointerGetDatum(&(X))
+#define Float4GetDatumFast(X) PointerGetDatum(&(X))
+#define Float8GetDatumFast(X) PointerGetDatum(&(X))
+
 
 /* ----------------------------------------------------------------
- *				Section 3: TransactionId and CommandId
+ *				Section 3:	exception handling definitions
+ *							Assert, Trap, etc macros
  * ----------------------------------------------------------------
  */
 
-typedef uint32 TransactionId;
+typedef char *ExcMessage;
+
+typedef struct Exception
+{
+	ExcMessage	message;
+} Exception;
+
+extern Exception FailedAssertion;
+extern Exception BadArg;
+extern Exception BadState;
 
-#define InvalidTransactionId	0
+extern bool	assert_enabled;
 
-typedef uint32 CommandId;
+/*
+ * USE_ASSERT_CHECKING, if defined, turns on all the assertions.
+ * - plai  9/5/90
+ *
+ * It should _NOT_ be defined in releases or in benchmark copies
+ */
 
-#define FirstCommandId	0
+/*
+ * Trap
+ *		Generates an exception if the given condition is true.
+ *
+ */
+#define Trap(condition, exception) \
+		do { \
+			if ((assert_enabled) && (condition)) \
+				ExceptionalCondition(CppAsString(condition), &(exception), \
+						(char*)NULL, __FILE__, __LINE__); \
+		} while (0)
+
+/*
+ *	TrapMacro is the same as Trap but it's intended for use in macros:
+ *
+ *		#define foo(x) (AssertM(x != 0) && bar(x))
+ *
+ *	Isn't CPP fun?
+ */
+#define TrapMacro(condition, exception) \
+	((bool) ((! assert_enabled) || ! (condition) || \
+			 (ExceptionalCondition(CppAsString(condition), \
+								  &(exception), \
+								  (char*) NULL, __FILE__, __LINE__))))
+
+#ifndef USE_ASSERT_CHECKING
+#define Assert(condition)
+#define AssertMacro(condition)	((void)true)
+#define AssertArg(condition)
+#define AssertState(condition)
+#define assert_enabled 0
+#else
+#define Assert(condition) \
+		Trap(!(condition), FailedAssertion)
+
+#define AssertMacro(condition) \
+		((void) TrapMacro(!(condition), FailedAssertion))
+
+#define AssertArg(condition) \
+		Trap(!(condition), BadArg)
+
+#define AssertState(condition) \
+		Trap(!(condition), BadState)
+
+#endif	 /* USE_ASSERT_CHECKING */
+
+/*
+ * LogTrap
+ *		Generates an exception with a message if the given condition is true.
+ *
+ */
+#define LogTrap(condition, exception, printArgs) \
+		do { \
+			if ((assert_enabled) && (condition)) \
+				ExceptionalCondition(CppAsString(condition), &(exception), \
+						vararg_format printArgs, __FILE__, __LINE__); \
+		} while (0)
+
+/*
+ *	LogTrapMacro is the same as LogTrap but it's intended for use in macros:
+ *
+ *		#define foo(x) (LogAssertMacro(x != 0, "yow!") && bar(x))
+ */
+#define LogTrapMacro(condition, exception, printArgs) \
+	((bool) ((! assert_enabled) || ! (condition) || \
+			 (ExceptionalCondition(CppAsString(condition), \
+								   &(exception), \
+								   vararg_format printArgs, __FILE__, __LINE__))))
+
+extern int ExceptionalCondition(char *conditionName,
+					 Exception *exceptionP, char *details,
+					 char *fileName, int lineNumber);
+extern char *vararg_format(const char *fmt, ...);
+
+#ifndef USE_ASSERT_CHECKING
+#define LogAssert(condition, printArgs)
+#define LogAssertMacro(condition, printArgs) true
+#define LogAssertArg(condition, printArgs)
+#define LogAssertState(condition, printArgs)
+#else
+#define LogAssert(condition, printArgs) \
+		LogTrap(!(condition), FailedAssertion, printArgs)
+
+#define LogAssertMacro(condition, printArgs) \
+		LogTrapMacro(!(condition), FailedAssertion, printArgs)
+
+#define LogAssertArg(condition, printArgs) \
+		LogTrap(!(condition), BadArg, printArgs)
+
+#define LogAssertState(condition, printArgs) \
+		LogTrap(!(condition), BadState, printArgs)
+
+#ifdef ASSERT_CHECKING_TEST
+extern int	assertTest(int val);
+
+#endif
+
+#endif	 /* USE_ASSERT_CHECKING */
 
 /* ----------------------------------------------------------------
- *				Section 4: genbki macros used by the
- *						   catalog/pg_xxx.h files
+ *				Section 4: genbki macros used by catalog/pg_xxx.h files
  * ----------------------------------------------------------------
  */
 #define CATALOG(x) \
@@ -217,35 +584,7 @@ typedef uint32 CommandId;
 #define BKI_BEGIN
 #define BKI_END
 
-/* ----------------------------------------------------------------
- *				Section 5:	random stuff
- *							CSIGNBIT, STATUS...
- * ----------------------------------------------------------------
- */
-
-/* msb for int/unsigned */
-#define ISIGNBIT (0x80000000)
-#define WSIGNBIT (0x8000)
-
-/* msb for char */
-#define CSIGNBIT (0x80)
-
-#define STATUS_OK				(0)
-#define STATUS_ERROR			(-1)
-#define STATUS_NOT_FOUND		(-2)
-#define STATUS_INVALID			(-3)
-#define STATUS_UNCATALOGUED		(-4)
-#define STATUS_REPLACED			(-5)
-#define STATUS_NOT_DONE			(-6)
-#define STATUS_BAD_PACKET		(-7)
-#define STATUS_FOUND			(1)
+typedef int4 aclitem;			/* PHONY definition for catalog use only */
 
-/* ---------------
- * Cyrillic on the fly charsets recode
- * ---------------
- */
-#ifdef CYR_RECODE
-extern void SetCharSet(void);
-#endif	 /* CYR_RECODE */
 
 #endif	 /* POSTGRES_H */
diff --git a/src/include/postgres_ext.h b/src/include/postgres_ext.h
index 18be70ea922cc263a05806f7b45e872eaf718400..a5696f2a0207503d4546c027627bcb7c49761956 100644
--- a/src/include/postgres_ext.h
+++ b/src/include/postgres_ext.h
@@ -2,10 +2,9 @@
  *
  * postgres_ext.h
  *
- *	   This file contains declarations of things that are visible
- *	external to Postgres.  For example, the Oid type is part of a
- *	structure that is passed to the front end via libpq, and is
- *	accordingly referenced in libpq-fe.h.
+ *	   This file contains declarations of things that are visible everywhere
+ *  in PostgreSQL *and* are visible to clients of frontend interface libraries.
+ *	For example, the Oid type is part of the API of libpq and other libraries.
  *
  *	   Declarations which are specific to a particular interface should
  *	go in the header file for that interface (such as libpq-fe.h).	This
@@ -16,7 +15,7 @@
  *	use header files that are otherwise internal to Postgres to interface
  *	with the backend.
  *
- * $Id: postgres_ext.h,v 1.5 2000/12/22 21:36:09 tgl Exp $
+ * $Id: postgres_ext.h,v 1.6 2001/02/10 02:31:28 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -29,6 +28,8 @@
  */
 typedef unsigned int Oid;
 
+#define InvalidOid		((Oid) 0)
+
 #define OID_MAX  UINT_MAX
 /* you will need to include <limits.h> to use the above #define */
 
diff --git a/src/include/postgres_fe.h b/src/include/postgres_fe.h
new file mode 100644
index 0000000000000000000000000000000000000000..b76d43d7a367ac6fdbdf6f261598147edc701a0d
--- /dev/null
+++ b/src/include/postgres_fe.h
@@ -0,0 +1,24 @@
+/*-------------------------------------------------------------------------
+ *
+ * postgres_fe.h
+ *	  Primary include file for PostgreSQL client-side .c files
+ *
+ * This should be the first file included by PostgreSQL client libraries and
+ * application programs --- but not by backend modules, which should include
+ * postgres.h.
+ *
+ *
+ * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1995, Regents of the University of California
+ *
+ * $Id: postgres_fe.h,v 1.1 2001/02/10 02:31:28 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef POSTGRES_FE_H
+#define POSTGRES_FE_H
+
+#include "postgres_ext.h"
+#include "c.h"
+
+#endif	 /* POSTGRES_FE_H */
diff --git a/src/include/regex/regex.h b/src/include/regex/regex.h
index 677f5ca9a24a9a755c23b53a5d2e823e22d237d0..b0b86f3cb6d0ff1c5e27d83eaf8f98aa09197812 100644
--- a/src/include/regex/regex.h
+++ b/src/include/regex/regex.h
@@ -40,7 +40,6 @@
 #ifndef _REGEX_H_
 #define _REGEX_H_
 
-#include "postgres.h"
 #include <sys/types.h>
 #include "mb/pg_wchar.h"
 
diff --git a/src/include/regex/regex2.h b/src/include/regex/regex2.h
index f655a1f2a271614d28d79b94e9360f12d86ac1d9..b885ff4318263bd12b059cd67b44ff9ce4ba43c9 100644
--- a/src/include/regex/regex2.h
+++ b/src/include/regex/regex2.h
@@ -37,9 +37,7 @@
  *		@(#)regex2.h	8.4 (Berkeley) 3/20/94
  */
 
-#include "postgres.h"
-
-#include "limits.h"
+#include <limits.h>
 
 /*
  * First, the stuff that ends up in the outside-world include file
diff --git a/src/include/regex/utils.h b/src/include/regex/utils.h
index 461e7ad6b0eef71b59ede2675a37582b0fded0b5..72f89dcafc25070ed309ce424fc91379214a7f0c 100644
--- a/src/include/regex/utils.h
+++ b/src/include/regex/utils.h
@@ -37,9 +37,7 @@
  *		@(#)utils.h		8.3 (Berkeley) 3/20/94
  */
 
-#include "postgres.h"
-
-#include "limits.h"
+#include <limits.h>
 
 /* utility definitions */
 #define DUPMAX			100000000		/* xxx is this right? */
@@ -50,6 +48,7 @@
 #else
 #define NC				(CHAR_MAX - CHAR_MIN + 1)
 #endif
+
 typedef unsigned char uch;
 
 /* switch off assertions (if not already off) if no REDEBUG */
@@ -58,8 +57,3 @@ typedef unsigned char uch;
 #define NDEBUG					/* no assertions please */
 #endif
 #endif
-
-/* for old systems with bcopy() but no memmove() */
-#if !defined(HAVE_MEMMOVE) && !defined(memmove)
-#define memmove(d, s, c)		bcopy(s, d, c)
-#endif
diff --git a/src/include/storage/ipc.h b/src/include/storage/ipc.h
index 49ca90ad85707dcebf1c8d9521dab2124e0f064c..3173121850ddba1d2f1c38a48784d743bf4dbca6 100644
--- a/src/include/storage/ipc.h
+++ b/src/include/storage/ipc.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: ipc.h,v 1.46 2001/01/24 19:43:27 momjian Exp $
+ * $Id: ipc.h,v 1.47 2001/02/10 02:31:28 tgl Exp $
  *
  * Some files that would normally need to include only sys/ipc.h must
  * instead include this file because on Ultrix, sys/ipc.h is not designed
@@ -18,8 +18,6 @@
 #ifndef IPC_H
 #define IPC_H
 
-#include "config.h"
-
 #include <sys/types.h>
 #ifdef HAVE_SYS_IPC_H
 #include <sys/ipc.h>
diff --git a/src/include/utils/dynamic_loader.h b/src/include/utils/dynamic_loader.h
index 953495251b8f8d60527e301c8a8e9ccdcdd1ebce..569aba644f96d2003d90b12d98cfe7d936c63bd6 100644
--- a/src/include/utils/dynamic_loader.h
+++ b/src/include/utils/dynamic_loader.h
@@ -7,19 +7,13 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: dynamic_loader.h,v 1.16 2001/01/24 19:43:28 momjian Exp $
+ * $Id: dynamic_loader.h,v 1.17 2001/02/10 02:31:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef DYNAMIC_LOADER_H
 #define DYNAMIC_LOADER_H
 
-#include <sys/types.h>
-
-/* we need this include because port files use them */
-#include "postgres.h"
-
-/* and this one for typedef PGFunction */
 #include "fmgr.h"
 
 
diff --git a/src/include/utils/exc.h b/src/include/utils/exc.h
index e44f9b46d9d935662beb5a9348a687c61a394bc7..09b4179097361e1c166bb343991cec40345be9e3 100644
--- a/src/include/utils/exc.h
+++ b/src/include/utils/exc.h
@@ -7,15 +7,13 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: exc.h,v 1.18 2001/01/24 19:43:28 momjian Exp $
+ * $Id: exc.h,v 1.19 2001/02/10 02:31:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #ifndef EXC_H
 #define EXC_H
 
-#include "config.h"
-
 #include <setjmp.h>
 
 extern char *ExcFileName;
diff --git a/src/include/utils/geo_decls.h b/src/include/utils/geo_decls.h
index 67ab1cd4fb2e3a2e673c2dcdb70cff280b656ea7..27b0dc7fac8d5b0a58872dd785be160c95f625b3 100644
--- a/src/include/utils/geo_decls.h
+++ b/src/include/utils/geo_decls.h
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: geo_decls.h,v 1.32 2001/01/24 19:43:28 momjian Exp $
+ * $Id: geo_decls.h,v 1.33 2001/02/10 02:31:29 tgl Exp $
  *
  * NOTE
  *	  These routines do *not* use the float types from adt/.
@@ -21,7 +21,6 @@
 #ifndef GEO_DECLS_H
 #define GEO_DECLS_H
 
-#include "access/attnum.h"
 #include "fmgr.h"
 
 /*--------------------------------------------------------------------
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index 0d8661442f17cfd400f5d031153da9a719381557..7953e5a8e7a610f89689059c51105f661359a5f2 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -4,13 +4,11 @@
  * External declarations pertaining to backend/utils/misc/guc.c and
  * backend/utils/misc/guc-file.l
  *
- * $Header: /cvsroot/pgsql/src/include/utils/guc.h,v 1.4 2000/07/27 19:49:24 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/include/utils/guc.h,v 1.5 2001/02/10 02:31:29 tgl Exp $
  */
 #ifndef GUC_H
 #define GUC_H
 
-#include "postgres.h"
-
 /*
  * Certain options can only be set at certain times. The rules are
  * like this:
diff --git a/src/include/utils/palloc.h b/src/include/utils/palloc.h
index c1613c05091e3365cfbb0ce06a77bd19c83c7da0..cb86616d80f5463c303d2edb257b4630e109f23d 100644
--- a/src/include/utils/palloc.h
+++ b/src/include/utils/palloc.h
@@ -21,7 +21,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: palloc.h,v 1.14 2001/01/24 19:43:28 momjian Exp $
+ * $Id: palloc.h,v 1.15 2001/02/10 02:31:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -64,24 +64,4 @@ extern char *MemoryContextStrdup(MemoryContext context, const char *string);
 #define pstrdup(str)  MemoryContextStrdup(CurrentMemoryContext, (str))
 
 
-/* ----------------
- * Alignment macros: align a length or address appropriately for a given type.
- *
- * There used to be some incredibly crufty platform-dependent hackery here,
- * but now we rely on the configure script to get the info for us. Much nicer.
- *
- * NOTE: TYPEALIGN will not work if ALIGNVAL is not a power of 2.
- * That case seems extremely unlikely to occur in practice, however.
- * ----------------
- */
-
-#define TYPEALIGN(ALIGNVAL,LEN) (((long)(LEN) + (ALIGNVAL-1)) & ~(ALIGNVAL-1))
-
-#define SHORTALIGN(LEN)			TYPEALIGN(ALIGNOF_SHORT, (LEN))
-#define INTALIGN(LEN)			TYPEALIGN(ALIGNOF_INT, (LEN))
-#define LONGALIGN(LEN)			TYPEALIGN(ALIGNOF_LONG, (LEN))
-#define DOUBLEALIGN(LEN)		TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
-#define MAXALIGN(LEN)			TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
-
-
 #endif	 /* PALLOC_H */
diff --git a/src/interfaces/ecpg/lib/extern.h b/src/interfaces/ecpg/lib/extern.h
index 780fc933bb8253750a497d33f59bf149552fa1d8..3278b0d079c30bdf2e2da2acebc6835c7e3d1a0c 100644
--- a/src/interfaces/ecpg/lib/extern.h
+++ b/src/interfaces/ecpg/lib/extern.h
@@ -1,4 +1,4 @@
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "libpq-fe.h"
 
 /* Here are some methods used by the lib. */
diff --git a/src/interfaces/ecpg/preproc/c_keywords.c b/src/interfaces/ecpg/preproc/c_keywords.c
index 15e1494eea5fe1c414e5248ded28dbc4b193fe9e..2dd941f61827143afa8cfaa5c40de6e10dd31469 100644
--- a/src/interfaces/ecpg/preproc/c_keywords.c
+++ b/src/interfaces/ecpg/preproc/c_keywords.c
@@ -5,9 +5,10 @@
  *
  *-------------------------------------------------------------------------
  */
+#include "postgres_fe.h"
+
 #include <ctype.h>
 
-#include "postgres.h"
 #include "extern.h"
 #include "preproc.h"
 
diff --git a/src/interfaces/ecpg/preproc/descriptor.c b/src/interfaces/ecpg/preproc/descriptor.c
index f3d08484b660c24bc556905029280ffe629f9a0d..7d4992251345847f030fc8d8aa84cdd95b2bdd8c 100644
--- a/src/interfaces/ecpg/preproc/descriptor.c
+++ b/src/interfaces/ecpg/preproc/descriptor.c
@@ -2,7 +2,8 @@
  * functions needed for descriptor handling
  */
 
-#include "postgres.h"
+#include "postgres_fe.h"
+
 #include "extern.h"
 
 /*
diff --git a/src/interfaces/ecpg/preproc/ecpg.c b/src/interfaces/ecpg/preproc/ecpg.c
index 5c76e3eed791e7aec2e18c200119c41c900ac89e..cfd71f32e6bf8e34f3a3a1a3b1518f964b0fbb1a 100644
--- a/src/interfaces/ecpg/preproc/ecpg.c
+++ b/src/interfaces/ecpg/preproc/ecpg.c
@@ -2,8 +2,9 @@
 /* (C) Michael Meskes <meskes@postgresql.org> Feb 5th, 1998 */
 /* Placed under the same copyright as PostgresSQL */
 
+#include "postgres_fe.h"
+
 #include <unistd.h>
-#include "postgres.h"
 
 #ifdef HAVE_GETOPT_H
 #include "getopt.h"
diff --git a/src/interfaces/ecpg/preproc/ecpg_keywords.c b/src/interfaces/ecpg/preproc/ecpg_keywords.c
index 89a5e58c7485b02b0f0c3b4662ef43b2516677e8..740b7d9cd3ecca339a637e3407986d79d9da1187 100644
--- a/src/interfaces/ecpg/preproc/ecpg_keywords.c
+++ b/src/interfaces/ecpg/preproc/ecpg_keywords.c
@@ -5,9 +5,10 @@
  *
  *-------------------------------------------------------------------------
  */
+#include "postgres_fe.h"
+
 #include <ctype.h>
 
-#include "postgres.h"
 #include "extern.h"
 #include "preproc.h"
 
diff --git a/src/interfaces/ecpg/preproc/extern.h b/src/interfaces/ecpg/preproc/extern.h
index f94ab94976478902873dc71fa9f884c786908370..3274515ff638928bf1610eff54c47be7427cdaa7 100644
--- a/src/interfaces/ecpg/preproc/extern.h
+++ b/src/interfaces/ecpg/preproc/extern.h
@@ -1,5 +1,5 @@
-#include "parser/keywords.h"
 #include "type.h"
+
 #include <errno.h>
 
 /* defines */
@@ -74,6 +74,7 @@ extern void reset_variables(void);
 extern void check_indicator(struct ECPGtype *);
 extern void remove_variables(int);
 extern struct variable *new_variable(const char *, struct ECPGtype *);
+extern ScanKeyword *ScanKeywordLookup(char *text);
 
 /* return codes */
 
diff --git a/src/interfaces/ecpg/preproc/keywords.c b/src/interfaces/ecpg/preproc/keywords.c
index 402ca4e30c3ad8a17e3748a2078b9c86b6a6da96..ed7c418d73b56aed099b4386d4548320b8eb453e 100644
--- a/src/interfaces/ecpg/preproc/keywords.c
+++ b/src/interfaces/ecpg/preproc/keywords.c
@@ -8,18 +8,16 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.36 2001/01/24 19:43:29 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/keywords.c,v 1.37 2001/02/10 02:31:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
+#include "postgres_fe.h"
+
 #include <ctype.h>
 
-#include "postgres.h"
-#include "nodes/parsenodes.h"
-#include "nodes/pg_list.h"
-#include "type.h"
+#include "extern.h"
 #include "preproc.h"
-#include "parser/keywords.h"
 
 /*
  * List of (keyword-name, keyword-token-value) pairs.
diff --git a/src/interfaces/ecpg/preproc/output.c b/src/interfaces/ecpg/preproc/output.c
index 7fe282586f62efc869c590e687a6d8f5a8588b77..cfd703d0db53f9d279d8e93b2733398e915a36e8 100644
--- a/src/interfaces/ecpg/preproc/output.c
+++ b/src/interfaces/ecpg/preproc/output.c
@@ -1,6 +1,5 @@
-#include <stdarg.h>
+#include "postgres_fe.h"
 
-#include "postgres.h"
 #include "extern.h"
 
 void
diff --git a/src/interfaces/ecpg/preproc/pgc.l b/src/interfaces/ecpg/preproc/pgc.l
index 091c60b96e0cc80570db30c0a05ada099316fb41..5f4be6e4bebfa9e77e0821d8483caec5f839bde3 100644
--- a/src/interfaces/ecpg/preproc/pgc.l
+++ b/src/interfaces/ecpg/preproc/pgc.l
@@ -12,23 +12,19 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.75 2001/02/09 15:13:49 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/ecpg/preproc/pgc.l,v 1.76 2001/02/10 02:31:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
+#include "postgres_fe.h"
+
 #include <ctype.h>
 #include <sys/types.h>
 #include <limits.h>
 #include <errno.h>
 
-#include "postgres.h"
-#include "miscadmin.h"
-#include "nodes/parsenodes.h"
-#include "nodes/pg_list.h"
-#include "parser/scansup.h"
 #include "extern.h"
 #include "preproc.h"
-#include "utils/builtins.h"
 
 /* some versions of lex define this as a macro */
 #if defined(yywrap)
diff --git a/src/interfaces/ecpg/preproc/preproc.y b/src/interfaces/ecpg/preproc/preproc.y
index 4d27ba34db6d472dc7923241f2aaaca9e1d3e361..4ed5ece1c799770047cb3db98df818a16f9559cf 100644
--- a/src/interfaces/ecpg/preproc/preproc.y
+++ b/src/interfaces/ecpg/preproc/preproc.y
@@ -1,13 +1,6 @@
 /* Copyright comment */
 %{
-#include <stdarg.h>
-
-#include "postgres.h"
-#include "access/htup.h"
-#include "catalog/catname.h"
-#include "utils/numeric.h"
-#include "utils/memutils.h"
-#include "storage/bufpage.h"
+#include "postgres_fe.h"
 
 #include "extern.h"
 
@@ -2976,10 +2969,6 @@ Geometric:  PATH_P 	{ $$ = make_str("path"); };
 
 opt_float:  '(' PosIntConst ')'
 				{
-					if (atol($2) < 1)
-						mmerror(ET_ERROR, "precision for FLOAT must be at least 1");
-					else if (atol($2) >= 16)
-						mmerror(ET_ERROR, "precision for FLOAT must be less than 16");
 					$$ = cat_str(3, make_str("("), $2, make_str(")"));
 				}
 		| /*EMPTY*/
@@ -2990,22 +2979,10 @@ opt_float:  '(' PosIntConst ')'
 
 opt_numeric:  '(' PosIntConst ',' PosIntConst ')'
 				{
-					if (atol($2) < 1 || atol($2) > NUMERIC_MAX_PRECISION) {
-						sprintf(errortext, "NUMERIC precision %s must be between 1 and %d", $2, NUMERIC_MAX_PRECISION);
-						mmerror(ET_ERROR, errortext);
-					}
-					if (atol($4) < 0 || atol($4) > atol($2)) {
-						sprintf(errortext, "NUMERIC scale %s must be between 0 and precision %s", $4, $2);
-						mmerror(ET_ERROR, errortext);
-					}
 					$$ = cat_str(5, make_str("("), $2, make_str(","), $4, make_str(")"));
 				}
 		| '(' PosIntConst ')'
 				{
-					if (atol($2) < 1 || atol($2) > NUMERIC_MAX_PRECISION) {
-						sprintf(errortext, "NUMERIC precision %s must be between 1 and %d", $2, NUMERIC_MAX_PRECISION);
-						mmerror(ET_ERROR, errortext);
-					}
 					$$ = cat_str(3, make_str("("), $2, make_str(")"));
 				}
 		| /*EMPTY*/
@@ -3016,22 +2993,10 @@ opt_numeric:  '(' PosIntConst ',' PosIntConst ')'
 
 opt_decimal:  '(' PosIntConst ',' PosIntConst ')'
 				{
-					if (atol($2) < 1 || atol($2) > NUMERIC_MAX_PRECISION) {
-						sprintf(errortext, "NUMERIC precision %s must be between 1 and %d", $2, NUMERIC_MAX_PRECISION);
-						mmerror(ET_ERROR, errortext);
-					}
-					if (atol($4) < 0 || atol($4) > atol($2)) {
-						sprintf(errortext, "NUMERIC scale %s must be between 0 and precision %s", $4, $2);
-						mmerror(ET_ERROR, errortext);
-					}
 					$$ = cat_str(5, make_str("("), $2, make_str(","), $4, make_str(")"));
 				}
 		| '(' PosIntConst ')'
 				{
-					if (atol($2) < 1 || atol($2) > NUMERIC_MAX_PRECISION) {
-						sprintf(errortext, "NUMERIC precision %s must be between 1 and %d", $2, NUMERIC_MAX_PRECISION);
-						mmerror(ET_ERROR, errortext);
-					}
 					$$ = cat_str(3, make_str("("), $2, make_str(")"));
 				}
 		| /*EMPTY*/
@@ -3045,23 +3010,12 @@ opt_decimal:  '(' PosIntConst ',' PosIntConst ')'
  * The following implements BIT() and BIT VARYING().
  */
 Bit:  bit '(' PosIntConst ')'
-                                {
-                                        $$ = cat_str(4, $1, make_str("("), $3, make_str(")"));
-                                        if (atol($3) < 1)
-					{
-                                                sprintf(errortext,"length for type '%s' must be at least 1",$1);  
-												mmerror(ET_ERROR, errortext);
-					}
-                                        else if (atol($3) > (MaxAttrSize * BITS_PER_BYTE))
-					{
-                                                sprintf(errortext, "length for type '%s' cannot exceed %d", $1,
-                                                         (MaxAttrSize * BITS_PER_BYTE));
-												mmerror(ET_ERROR, errortext);
-					}
-                                }
+				{
+					$$ = cat_str(4, $1, make_str("("), $3, make_str(")"));
+				}
                 | bit
-                                {
-                                        $$ = $1;
+				{
+					$$ = $1;
 				}
 		;
 
@@ -3077,17 +3031,6 @@ bit:  BIT opt_varying
  */
 Character:  character '(' PosIntConst ')'
 				{
-					if (atol($3) < 1)
-					{
-						sprintf(errortext, "length for type '%s' type must be at least 1",$1);
-						mmerror(ET_ERROR, errortext);
-					}
-					else if (atol($3) > MaxAttrSize)
-					{
-						sprintf(errortext, "length for type '%s' cannot exceed %d", $1, MaxAttrSize);
-						mmerror(ET_ERROR, errortext);
-					}
-
 					$$ = cat_str(4, $1, make_str("("), $3, make_str(")"));
 				}
 		| character
@@ -3730,14 +3673,7 @@ relation_name:	SpecialRuleRelation
 				}
 		| ColId
 				{
-					/* disallow refs to variable system tables */
-					if (strcmp(LogRelationName, $1) == 0
-					   || strcmp(VariableRelationName, $1) == 0) {
-						sprintf(errortext, make_str("%s cannot be accessed by users"),$1);
-						mmerror(ET_ERROR, errortext);
-					}
-					else
-						$$ = $1;
+					$$ = $1;
 				}
 		;
 
diff --git a/src/interfaces/ecpg/preproc/type.c b/src/interfaces/ecpg/preproc/type.c
index 29899b72598f441d052356606262b43b0a681135..5a1a7d1fa02d3675fa184961a3748bfffeb46f56 100644
--- a/src/interfaces/ecpg/preproc/type.c
+++ b/src/interfaces/ecpg/preproc/type.c
@@ -1,8 +1,5 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
+#include "postgres_fe.h"
 
-#include "postgres.h"
 #include "extern.h"
 
 /* malloc + error check */
diff --git a/src/interfaces/ecpg/preproc/type.h b/src/interfaces/ecpg/preproc/type.h
index dd844cb12b03f56c9b347277a3af6166bf6f7827..12e45ab43ac263181ac5b1175c03e0f7f97a9c17 100644
--- a/src/interfaces/ecpg/preproc/type.h
+++ b/src/interfaces/ecpg/preproc/type.h
@@ -163,3 +163,9 @@ struct fetch_desc
 	char	   *str;
 	char	   *name;
 };
+
+typedef struct ScanKeyword
+{
+	char	   *name;
+	int			value;
+} ScanKeyword;
diff --git a/src/interfaces/ecpg/preproc/variable.c b/src/interfaces/ecpg/preproc/variable.c
index afdc0335513b7e9e81a981128c61c7b6615252ca..d97ef59f4460ada08a6a3be1ba89504fb56e5b35 100644
--- a/src/interfaces/ecpg/preproc/variable.c
+++ b/src/interfaces/ecpg/preproc/variable.c
@@ -1,4 +1,4 @@
-#include "postgres.h"
+#include "postgres_fe.h"
 
 #include "extern.h"
 
diff --git a/src/interfaces/libpgtcl/pgtcl.c b/src/interfaces/libpgtcl/pgtcl.c
index 1590c60ed00aef0272d8a3270ab9e246eb344ae8..bf3548e839ca15a57e36dcf78aded26140750bbb 100644
--- a/src/interfaces/libpgtcl/pgtcl.c
+++ b/src/interfaces/libpgtcl/pgtcl.c
@@ -10,12 +10,12 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.19 2001/01/24 19:43:29 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtcl.c,v 1.20 2001/02/10 02:31:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "libpgtcl.h"
 #include "pgtclCmds.h"
 #include "pgtclId.h"
diff --git a/src/interfaces/libpgtcl/pgtclCmds.c b/src/interfaces/libpgtcl/pgtclCmds.c
index ec8a27eaa64294b629002650825cf6bcd5fb4fd6..d4626f8869970a362e21fbeb66b0c4d27bbc9324 100644
--- a/src/interfaces/libpgtcl/pgtclCmds.c
+++ b/src/interfaces/libpgtcl/pgtclCmds.c
@@ -8,14 +8,14 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.53 2001/01/24 19:43:29 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclCmds.c,v 1.54 2001/02/10 02:31:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
+#include "postgres_fe.h"
 
 #include <ctype.h>
 
-#include "postgres.h"
 #include "pgtclCmds.h"
 #include "pgtclId.h"
 #include "libpq/libpq-fs.h"		/* large-object interface */
diff --git a/src/interfaces/libpgtcl/pgtclId.c b/src/interfaces/libpgtcl/pgtclId.c
index 9f1354390a314f5d8b5fb8c3d4cfa0af45b36e72..f4acde2fc47531d345ee51883bdaa5806b4b3cb6 100644
--- a/src/interfaces/libpgtcl/pgtclId.c
+++ b/src/interfaces/libpgtcl/pgtclId.c
@@ -13,14 +13,14 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.24 2001/01/24 19:43:29 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.25 2001/02/10 02:31:29 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
+#include "postgres_fe.h"
 
 #include <errno.h>
 
-#include "postgres.h"
 #include "pgtclCmds.h"
 #include "pgtclId.h"
 
diff --git a/src/interfaces/libpq++/pgconnection.h b/src/interfaces/libpq++/pgconnection.h
index 5ca7afca9cc0f6bb81298a5ee659f2eca0e0e29e..4310dac61db3b823ab951a82c01359e28093b5ee 100644
--- a/src/interfaces/libpq++/pgconnection.h
+++ b/src/interfaces/libpq++/pgconnection.h
@@ -13,7 +13,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  * 
- * $Id: pgconnection.h,v 1.9 2001/01/24 19:43:32 momjian Exp $
+ * $Id: pgconnection.h,v 1.10 2001/02/10 02:31:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -38,7 +38,7 @@ extern "C" {
 #endif
 
 extern "C" {
-#include "postgres.h"
+#include "postgres_fe.h"
 #include "libpq-fe.h"
 }
 
diff --git a/src/interfaces/libpq/fe-auth.c b/src/interfaces/libpq/fe-auth.c
index 6439827360510bb9978f9ccfea73adb7a4946214..dce3b5c90b965aa69d5470b86e8bcf15e071a200 100644
--- a/src/interfaces/libpq/fe-auth.c
+++ b/src/interfaces/libpq/fe-auth.c
@@ -10,7 +10,7 @@
  * exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.45 2001/01/24 19:43:29 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.46 2001/02/10 02:31:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -28,9 +28,8 @@
  *
  */
 
-#ifndef WIN32
-#include "postgres.h"
-#endif
+#include "postgres_fe.h"
+
 #include "libpq-fe.h"
 #include "libpq-int.h"
 #include "fe-auth.h"
diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c
index 3d7733b2fa5860da81b2f6e51728ca1ce91597be..4486e3cf72a015564d93b362e34a23f3bb40809e 100644
--- a/src/interfaces/libpq/fe-connect.c
+++ b/src/interfaces/libpq/fe-connect.c
@@ -8,12 +8,12 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.159 2001/01/24 19:43:30 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.160 2001/02/10 02:31:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
-#include "postgres.h"
+#include "postgres_fe.h"
 
 #include <sys/types.h>
 #include <fcntl.h>
@@ -45,7 +45,6 @@
 #endif
 
 #ifdef MULTIBYTE
-#include "miscadmin.h"
 #include "mb/pg_wchar.h"
 #endif
 
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 6e03222a0d6dab519fd8b49f2ecc6c5f80149220..e7838315eca7026276a5fbe5dfd881182c9a8fa5 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -8,15 +8,16 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.100 2001/02/06 02:02:27 tgl Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.101 2001/02/10 02:31:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
+#include "postgres_fe.h"
+
 #include <errno.h>
 #include <ctype.h>
 #include <fcntl.h>
 
-#include "postgres.h"
 #include "libpq-fe.h"
 #include "libpq-int.h"
 
diff --git a/src/interfaces/libpq/fe-lobj.c b/src/interfaces/libpq/fe-lobj.c
index e8d0794693540f3d50e8c27108c4d28fa52ad859..9231c052432a995ac62dbda8786ed8a9fe6d88d8 100644
--- a/src/interfaces/libpq/fe-lobj.c
+++ b/src/interfaces/libpq/fe-lobj.c
@@ -8,15 +8,15 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.32 2001/01/24 19:43:30 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.33 2001/02/10 02:31:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
+#include "postgres_fe.h"
 
 #include <fcntl.h>
 #include <sys/stat.h>
 
-#include "postgres.h"
 #include "libpq-fe.h"
 #include "libpq-int.h"
 
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index cf3867896036a768a647f171db314c201ae8b805..910f705f6e300710d5fdc97195542317a3ba5c38 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -25,12 +25,12 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.43 2001/01/24 19:43:30 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.44 2001/02/10 02:31:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
-#include "postgres.h"
+#include "postgres_fe.h"
 
 #ifdef WIN32
 #include "win32.h"
@@ -52,7 +52,6 @@
 #include "pqsignal.h"
 
 #ifdef MULTIBYTE
-#include "miscadmin.h"
 #include "mb/pg_wchar.h"
 #endif
 
diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c
index 574ca0602274da90cfe4c666fc17cdb1dfdcfaf2..bd5e4e29a125e65f28d7d9a5287d7dfb980be672 100644
--- a/src/interfaces/libpq/fe-print.c
+++ b/src/interfaces/libpq/fe-print.c
@@ -10,11 +10,11 @@
  * didn't really belong there.
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.40 2001/01/24 19:43:31 momjian Exp $
+ *	  $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.41 2001/02/10 02:31:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
-#include "postgres.h"
+#include "postgres_fe.h"
 
 #include <signal.h>
 
diff --git a/src/interfaces/libpq/libpq-int.h b/src/interfaces/libpq/libpq-int.h
index 023f0d6fd0ba7e5de0aeaec7fdbe7b22ba731986..09ffcb137ad9f65e71119e01ebcc810b2151c928 100644
--- a/src/interfaces/libpq/libpq-int.h
+++ b/src/interfaces/libpq/libpq-int.h
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: libpq-int.h,v 1.31 2001/01/24 19:43:31 momjian Exp $
+ * $Id: libpq-int.h,v 1.32 2001/02/10 02:31:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -21,6 +21,7 @@
 #define LIBPQ_INT_H
 
 /* We assume libpq-fe.h has already been included. */
+#include "postgres_fe.h"
 
 /* include stuff common to fe and be */
 #include "libpq/pqcomm.h"
diff --git a/src/interfaces/libpq/pqexpbuffer.c b/src/interfaces/libpq/pqexpbuffer.c
index b510eab2be03d51c2231e0d05e4c4d6b8ee62d01..eac5f41ddc6ea62a4da94757ffb8aa0ba6c79ba5 100644
--- a/src/interfaces/libpq/pqexpbuffer.c
+++ b/src/interfaces/libpq/pqexpbuffer.c
@@ -17,17 +17,16 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.8 2001/01/24 19:43:31 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.9 2001/02/10 02:31:30 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 
-#include "postgres.h"
+#include "postgres_fe.h"
+
 #include "pqexpbuffer.h"
 
 #ifdef WIN32
-#include <stdarg.h>
-#include <stdio.h>
 #include "win32.h"
 #endif
 
diff --git a/src/interfaces/libpq/pqsignal.h b/src/interfaces/libpq/pqsignal.h
index 58f343ec8a2cc42d78e5d806908929354fe66071..3444bfb70e5d85dd58abcc6a4388c4c1a56eeb54 100644
--- a/src/interfaces/libpq/pqsignal.h
+++ b/src/interfaces/libpq/pqsignal.h
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: pqsignal.h,v 1.9 2001/01/24 19:43:31 momjian Exp $
+ * $Id: pqsignal.h,v 1.10 2001/02/10 02:31:30 tgl Exp $
  *
  * NOTES
  *	  This shouldn't be in libpq, but the monitor and some other
@@ -18,7 +18,7 @@
 #ifndef PQSIGNAL_H
 #define PQSIGNAL_H
 
-#include "postgres.h"
+#include "postgres_fe.h"
 
 typedef void (*pqsigfunc) (int);
 
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c
index bd65c4233da2922223d689393f47101c40b97954..d8777e916ac49d32af1b602b02240abbf345a273 100644
--- a/src/test/regress/regress.c
+++ b/src/test/regress/regress.c
@@ -1,11 +1,11 @@
 /*
- * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.45 2000/11/20 20:36:53 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/test/regress/regress.c,v 1.46 2001/02/10 02:31:30 tgl Exp $
  */
 
-#include <float.h>				/* faked on sunos */
-
 #include "postgres.h"
 
+#include <float.h>				/* faked on sunos */
+
 #include "utils/geo_decls.h"	/* includes <math.h> */
 #include "executor/executor.h"	/* For GetAttributeByName */
 #include "commands/sequence.h"	/* for nextval() */
diff --git a/src/tutorial/funcs.c b/src/tutorial/funcs.c
index 621503a421c785a246ccb3569b7fd7b88b873fcc..58ede56cc88432317b7fc068da2751f0d7095755 100644
--- a/src/tutorial/funcs.c
+++ b/src/tutorial/funcs.c
@@ -9,8 +9,6 @@
   See funcs_new.c for examples of "new style".
 *****************************************************************************/
 
-#include <string.h>
-
 #include "postgres.h"			/* general Postgres declarations */
 
 #include "executor/executor.h"	/* for GetAttributeByName() */
diff --git a/src/tutorial/funcs_new.c b/src/tutorial/funcs_new.c
index 20f609d5d2d88c7d84d05f990ad535bba827d90f..b8972688330cdad8b4e96954ceb913d99290439e 100644
--- a/src/tutorial/funcs_new.c
+++ b/src/tutorial/funcs_new.c
@@ -9,8 +9,6 @@
   See funcs.c for examples of "old style".
 *****************************************************************************/
 
-#include <string.h>
-
 #include "postgres.h"			/* general Postgres declarations */
 
 #include "fmgr.h"               /* for argument/result macros */