diff --git a/contrib/pg_controldata/README.pg_controldata b/contrib/pg_controldata/README.pg_controldata
deleted file mode 100644
index 85ca0e1467a7a81373f3669549a2a2242703de0e..0000000000000000000000000000000000000000
--- a/contrib/pg_controldata/README.pg_controldata
+++ /dev/null
@@ -1,32 +0,0 @@
-I had a need to read such things as the backend locale and the catalog
-version number from the current database, and couldn't find any existing
-program to do that.
-
-The attached utility produces output like this:
-
-$ pg_controldata
-pg_control version number:            71
-Catalog version number:               200101061
-Database state:                       IN_PRODUCTION
-pg_control last modified:             Sat Mar 10 00:07:55 2001
-Current log file id:                  0
-Next log file segment:                9
-Latest checkpoint location:           0/88CAA20
-Prior checkpoint location:            0/70A5D48
-Latest checkpoint's REDO location:    0/88CAA20
-Latest checkpoint's UNDO location:    0/0
-Latest checkpoint's StartUpID:        22
-Latest checkpoint's NextXID:          4711
-Latest checkpoint's NextOID:          444704
-Time of latest checkpoint:            Sat Mar 10 00:07:52 2001
-Database block size:                  8192
-Blocks per segment of large relation: 131072
-LC_COLLATE:                           C
-LC_CTYPE:                             C
-
-
-To access the pg_control file, the program must be run as the Postgres user,
-and PGDATA must be set correctly in its environment.
-
---
-Oliver Elphick                 <olly@lfix.co.uk>
diff --git a/doc/src/sgml/ref/allfiles.sgml b/doc/src/sgml/ref/allfiles.sgml
index 502cdb0e42c713cd508f1a2407af916995bfbdf0..47afe90c9015a52512cb83d4ddf6f794069a181c 100644
--- a/doc/src/sgml/ref/allfiles.sgml
+++ b/doc/src/sgml/ref/allfiles.sgml
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.44 2002/08/04 04:31:44 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/allfiles.sgml,v 1.45 2002/08/16 20:34:06 momjian Exp $
 PostgreSQL documentation
 Complete list of usable sgml source files in this directory.
 -->
@@ -132,6 +132,7 @@ Complete list of usable sgml source files in this directory.
 <!entity ipcclean           system "ipcclean.sgml">
 <!entity pgAccess           system "pgaccess-ref.sgml">
 <!entity pgConfig           system "pg_config-ref.sgml">
+<!entity pgControldata      system "pg_controldata.sgml">
 <!entity pgCtl              system "pg_ctl-ref.sgml">
 <!entity pgDump             system "pg_dump.sgml">
 <!entity pgDumpall          system "pg_dumpall.sgml">
diff --git a/doc/src/sgml/ref/pg_controldata.sgml b/doc/src/sgml/ref/pg_controldata.sgml
new file mode 100644
index 0000000000000000000000000000000000000000..2062c06ba7533d4b33270ca93f9b5bfdc31aa08c
--- /dev/null
+++ b/doc/src/sgml/ref/pg_controldata.sgml
@@ -0,0 +1,74 @@
+<!--
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_controldata.sgml,v 1.1 2002/08/16 20:34:06 momjian Exp $
+PostgreSQL documentation
+-->
+
+<refentry id="APP-PGCONTROLDATA">
+ <refmeta>
+  <refentrytitle id="APP-PGCONTROLDATA-TITLE"><application>pg_controldata</application></refentrytitle>
+  <manvolnum>1</manvolnum>
+  <refmiscinfo>Application</refmiscinfo>
+ </refmeta>
+
+ <refnamediv>
+  <refname>pg_controldata</refname>
+  <refpurpose>display server-wide control information</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv>
+  <cmdsynopsis>
+   <command>pg_controldata</command>
+   <arg><replaceable class="parameter">datadir</replaceable></arg>
+  </cmdsynopsis>
+ </refsynopsisdiv>
+
+ <refsect1 id="R1-APP-PGCONTROLDATA-1">
+  <title>Description</title>
+  <para>
+   <command>pg_controldata</command> returns information initialized during
+   <application>initdb</>. such as the catalog version and server encoding.
+   It also shows information about write-ahead logging and checkpoint 
+   processing.  This information is server-wide, and not specific to any one
+   database.
+  </para>
+
+  <para>
+   You can specify the data directory on the command line, or use 
+   the environment variable <envar>PGDATA</>.
+  </para>
+ </refsect1>
+
+ <refsect1>
+  <title>Environment</title>
+
+  <variablelist>
+   <varlistentry>
+    <term><envar>PGDATA</envar></term>
+
+    <listitem>
+     <para>
+      Default data direction location
+     </para>
+    </listitem>
+   </varlistentry>
+
+  </variablelist>
+ </refsect1>
+</refentry>
+
+<!-- Keep this comment at the end of the file
+Local variables:
+mode: sgml
+sgml-omittag:nil
+sgml-shorttag:t
+sgml-minimize-attributes:nil
+sgml-always-quote-attributes:t
+sgml-indent-step:1
+sgml-indent-data:t
+sgml-parent-document:nil
+sgml-default-dtd-file:"../reference.ced"
+sgml-exposed-tags:nil
+sgml-local-catalogs:"/usr/lib/sgml/catalog"
+sgml-local-ecat-files:nil
+End:
+-->
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 4ddc70d212024da0aee7d5b87e63448edf285be3..553d3e7dac8fbe2280a71d8acf5dc2889bc3321b 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.71 2002/08/10 19:35:00 tgl Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.72 2002/08/16 20:34:06 momjian Exp $
 PostgreSQL documentation
 -->
 
@@ -22,7 +22,7 @@ PostgreSQL documentation
    <command>psql</command>
    <arg><replaceable class="parameter">options</replaceable></arg>
    <arg><replaceable class="parameter">dbname</replaceable>
-     <arg><replaceable class="parameter">user</replaceable></arg></arg>
+   <arg><replaceable class="parameter">user</replaceable></arg></arg>
   </cmdsynopsis>
  </refsynopsisdiv>
 
diff --git a/doc/src/sgml/reference.sgml b/doc/src/sgml/reference.sgml
index 3c6af16730b4d9e41aeaf6b45d80a98fd3f74ce5..b8605220025de44bb5d4d5919f5341f63c1d7ca4 100644
--- a/doc/src/sgml/reference.sgml
+++ b/doc/src/sgml/reference.sgml
@@ -1,5 +1,5 @@
 <!-- reference.sgml
-$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.33 2002/08/04 04:31:44 momjian Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/reference.sgml,v 1.34 2002/08/16 20:34:06 momjian Exp $
 
 PostgreSQL Reference Manual
 -->
@@ -201,6 +201,7 @@ Disable this chapter until we have more functions documented.
    &initlocation;
    &ipcclean;
    &pgCtl;
+   &pgControldata;
    &postgres;
    &postmaster;
 
diff --git a/src/bin/pg_controldata/Makefile b/src/bin/pg_controldata/Makefile
new file mode 100644
index 0000000000000000000000000000000000000000..d1e3d6537f045a43daac59caa1aea14674db4e7e
--- /dev/null
+++ b/src/bin/pg_controldata/Makefile
@@ -0,0 +1,35 @@
+#-------------------------------------------------------------------------
+#
+# Makefile for src/bin/pg_controldata
+#
+# Copyright (c) 1998, PostgreSQL Global Development Group
+#
+# $Header: /cvsroot/pgsql/src/bin/pg_controldata/Makefile,v 1.1 2002/08/16 20:34:06 momjian Exp $
+#
+#-------------------------------------------------------------------------
+
+subdir = src/bin/pg_controldata
+top_builddir = ../../..
+include $(top_builddir)/src/Makefile.global
+
+OBJS= pg_controldata.o pg_crc.o
+
+pg_crc.c: $(top_builddir)/src/backend/utils/hash/pg_crc.c
+	rm -f $@ && $(LN_S) $< .
+
+all: submake-libpq submake-libpgport pg_controldata
+
+pg_controldata: $(OBJS)
+	$(CC) $(CFLAGS) $^ $(libpq) $(LDFLAGS) $(LIBS) -o $@
+
+install: all installdirs
+	$(INSTALL_PROGRAM) pg_controldata$(X) $(DESTDIR)$(bindir)/pg_controldata$(X)
+
+installdirs:
+	$(mkinstalldirs) $(DESTDIR)$(bindir)
+
+uninstall:
+	rm -f $(DESTDIR)$(bindir)/pg_controldata$(X)
+
+clean distclean maintainer-clean:
+	rm -f pg_controldata$(X) pg_controldata.o pg_crc.o pg_crc.c
diff --git a/contrib/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
similarity index 97%
rename from contrib/pg_controldata/pg_controldata.c
rename to src/bin/pg_controldata/pg_controldata.c
index b1ac873d2418d58b9c53eeca7317b6573ccde387..a77c2e22fa6694beaefa2bfb073615ffca711b92 100644
--- a/contrib/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -6,7 +6,7 @@
  * copyright (c) Oliver Elphick <olly@lfix.co.uk>, 2001;
  * licence: BSD
  *
- * $Header: /cvsroot/pgsql/contrib/pg_controldata/Attic/pg_controldata.c,v 1.7 2002/08/14 03:01:43 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_controldata/pg_controldata.c,v 1.1 2002/08/16 20:34:06 momjian Exp $
  */
 #include "postgres.h"