diff --git a/doc/src/sgml/ref/allfiles.sgml b/doc/src/sgml/ref/allfiles.sgml
new file mode 100644
index df84054..a6edacd
*** a/doc/src/sgml/ref/allfiles.sgml
--- b/doc/src/sgml/ref/allfiles.sgml
*************** Complete list of usable sgml source file
*** 175,180 ****
--- 175,181 ----
  <!ENTITY pgCtl              SYSTEM "pg_ctl-ref.sgml">
  <!ENTITY pgDump             SYSTEM "pg_dump.sgml">
  <!ENTITY pgDumpall          SYSTEM "pg_dumpall.sgml">
+ <!ENTITY pgPing             SYSTEM "pg_ping.sgml">
  <!ENTITY pgReceivexlog      SYSTEM "pg_receivexlog.sgml">
  <!ENTITY pgResetxlog        SYSTEM "pg_resetxlog.sgml">
  <!ENTITY pgRestore          SYSTEM "pg_restore.sgml">
diff --git a/doc/src/sgml/ref/pg_ping.sgml b/doc/src/sgml/ref/pg_ping.sgml
new file mode 100644
index ...0e839a7
*** a/doc/src/sgml/ref/pg_ping.sgml
--- b/doc/src/sgml/ref/pg_ping.sgml
***************
*** 0 ****
--- 1,188 ----
+ <!--
+ doc/src/sgml/ref/pg_ping.sgml
+ PostgreSQL documentation
+ -->
+ 
+ <refentry id="app-pg-ping">
+  <refmeta>
+   <refentrytitle><application>pg_ping</application></refentrytitle>
+   <manvolnum>1</manvolnum>
+   <refmiscinfo>Application</refmiscinfo>
+  </refmeta>
+ 
+  <refnamediv>
+   <refname>pg_ping</refname>
+   <refpurpose>checks the connection status of a <productname>PostgreSQL</productname> server</refpurpose>
+  </refnamediv>
+ 
+  <indexterm zone="app-pg-ping">
+   <primary>pg_ping</primary>
+  </indexterm>
+ 
+  <refsynopsisdiv>
+   <cmdsynopsis>
+    <command>pg_ping</command>
+    <arg rep="repeat"><replaceable>connection-option</replaceable></arg>
+    <arg rep="repeat"><replaceable>option</replaceable></arg>
+   </cmdsynopsis>
+  </refsynopsisdiv>
+ 
+ 
+  <refsect1 id="app-pg-ping-description">
+   <title>Description</title>
+   <para>
+    <application>pg_ping</application> is a utility for checking the connection
+    status of a <productname>PostgreSQL</productname> database server. The exit
+    status specifies the result of the connection check.
+   </para>
+  </refsect1>
+ 
+  <refsect1 id="app-pg-ping-options">
+   <title>Options</title>
+ 
+     <variablelist>
+ 
+     <varlistentry>
+       <term><option>-d <replaceable class="parameter">dbname</replaceable></></term>
+       <term><option>--dbname=<replaceable class="parameter">dbname</replaceable></></term>
+       <listitem>
+       <para>
+        Specifies the name of the database to connect to.
+       </para>
+       <para>
+        If this parameter contains an <symbol>=</symbol> sign or starts
+        with a valid <acronym>URI</acronym> prefix
+        (<literal>postgresql://</literal>
+        or <literal>postgres://</literal>), it is treated as a
+        <parameter>conninfo</parameter> string. See <xref linkend="libpq-connect"> for more information.
+       </para>
+       </listitem>
+     </varlistentry>
+ 
+      <varlistentry>
+        <term><option>-h <replaceable class="parameter">hostname</replaceable></></term>
+        <term><option>--host=<replaceable class="parameter">hostname</replaceable></></term>
+        <listitem>
+        <para>
+        Specifies the host name of the machine on which the
+        server is running. If the value begins
+        with a slash, it is used as the directory for the Unix-domain
+        socket.
+        </para>
+        </listitem>
+      </varlistentry>
+ 
+      <varlistentry>
+        <term><option>-p <replaceable class="parameter">port</replaceable></></term>
+        <term><option>--port=<replaceable class="parameter">port</replaceable></></term>
+        <listitem>
+        <para>
+        Specifies the TCP port or the local Unix-domain
+        socket file extension on which the server is listening for
+        connections. Defaults to the value of the <envar>PGPORT</envar>
+        environment variable or, if not set, to the port specified at
+        compile time, usually 5432.
+        </para>
+        </listitem>
+      </varlistentry>
+ 
+      <varlistentry>
+        <term><option>-U <replaceable class="parameter">username</replaceable></></term>
+        <term><option>--username=<replaceable class="parameter">username</replaceable></></term>
+        <listitem>
+        <para>
+        Connect to the database as the user <replaceable
+        class="parameter">username</replaceable> instead of the default.
+        </para>
+        </listitem>
+      </varlistentry>
+ 
+      <varlistentry>
+       <term><option>-v</option></term>
+       <term><option>--verbose</option></term>
+       <listitem>
+        <para>
+         Enables verbose mode. Will output the result of the operation as well as the
+         connection parameters used.
+        </para>
+       </listitem>
+      </varlistentry>
+ 
+      <varlistentry>
+       <term><option>-V</></term>
+       <term><option>--version</></term>
+        <listitem>
+         <para>
+          Print the <application>pg_ping</application> version and exit.
+         </para>
+        </listitem>
+      </varlistentry>
+ 
+      <varlistentry>
+       <term><option>-?</></term>
+       <term><option>--help</></term>
+       <listitem>
+        <para>
+         Show help about <application>pg_ping</application> command line
+         arguments, and exit.
+        </para>
+       </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsect1>
+ 
+  <refsect1>
+   <title>Exit Status</title>
+ 
+   <para>
+    <application>pg_ping</application> returns 0 to the shell if the server
+    is accepting connections normally, 1 if the server is rejecting
+    connections (for example during startup), 2 if there was no response to the
+    connection attempt, and 3 if no attempt was made (for example due to invalid
+    parameters).
+   </para>
+  </refsect1>
+ 
+  <refsect1>
+   <title>Environment</title>
+ 
+   <para>
+    <command>pg_ping</command>, like most other <productname>PostgreSQL</>
+    utilities,
+    also uses the environment variables supported by <application>libpq</>
+    (see <xref linkend="libpq-envars">).
+   </para>
+  </refsect1>
+ 
+  <refsect1 id="app-pg-ping-notes">
+   <title>Notes</title>
+ 
+   <para>
+    The options <option>--dbname</> and <option>--username</> can be used to avoid gratuitous
+    error messages in the logs, but are not necessary for proper functionality.
+   </para>
+  </refsect1>
+ 
+  <refsect1 id="app-pg-ping-examples">
+   <title>Examples</title>
+ 
+   <para>
+    Standard Usage:
+    <screen>
+     <prompt>$</prompt> <userinput>pg_ping</userinput>
+     <prompt>$</prompt> <userinput>echo $?</userinput>
+     <computeroutput>0</computeroutput>
+    </screen>
+   </para>
+ 
+   <para>
+    To run in verbose mode with connection parameters:
+    <screen>
+     <prompt>$ </prompt><userinput>pg_ping -v -h localhost</userinput>
+     <computeroutput>localhost:5432 - Accepting Connections</computeroutput>
+    </screen>
+   </para>
+ 
+  </refsect1>
+ 
+ </refentry>
diff --git a/doc/src/sgml/reference.sgml b/doc/src/sgml/reference.sgml
new file mode 100644
index 0872168..55ac707
*** a/doc/src/sgml/reference.sgml
--- b/doc/src/sgml/reference.sgml
***************
*** 223,228 ****
--- 223,229 ----
     &pgConfig;
     &pgDump;
     &pgDumpall;
+    &pgPing;
     &pgReceivexlog;
     &pgRestore;
     &psqlRef;
diff --git a/src/bin/scripts/.gitignore b/src/bin/scripts/.gitignore
new file mode 100644
index e62f4b0..2cc8f24
*** a/src/bin/scripts/.gitignore
--- b/src/bin/scripts/.gitignore
***************
*** 7,12 ****
--- 7,13 ----
  /dropuser
  /reindexdb
  /vacuumdb
+ /pg_ping
  
  /dumputils.c
  /keywords.c
diff --git a/src/bin/scripts/Makefile b/src/bin/scripts/Makefile
new file mode 100644
index 0980b4c..fc8a12b
*** a/src/bin/scripts/Makefile
--- b/src/bin/scripts/Makefile
*************** subdir = src/bin/scripts
*** 16,22 ****
  top_builddir = ../../..
  include $(top_builddir)/src/Makefile.global
  
! PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb reindexdb
  
  override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)
  
--- 16,22 ----
  top_builddir = ../../..
  include $(top_builddir)/src/Makefile.global
  
! PROGRAMS = createdb createlang createuser dropdb droplang dropuser clusterdb vacuumdb reindexdb pg_ping
  
  override CPPFLAGS := -I$(top_srcdir)/src/bin/pg_dump -I$(top_srcdir)/src/bin/psql -I$(libpq_srcdir) $(CPPFLAGS)
  
*************** dropuser: dropuser.o common.o dumputils.
*** 34,39 ****
--- 34,40 ----
  clusterdb: clusterdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq
  vacuumdb: vacuumdb.o common.o | submake-libpq
  reindexdb: reindexdb.o common.o dumputils.o kwlookup.o keywords.o | submake-libpq
+ pg_ping: pg_ping.o common.o | submake-libpq submake-libpgport
  
  dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/%
  	rm -f $@ && $(LN_S) $< .
*************** install: all installdirs
*** 54,59 ****
--- 55,61 ----
  	$(INSTALL_PROGRAM) clusterdb$(X)  '$(DESTDIR)$(bindir)'/clusterdb$(X)
  	$(INSTALL_PROGRAM) vacuumdb$(X)   '$(DESTDIR)$(bindir)'/vacuumdb$(X)
  	$(INSTALL_PROGRAM) reindexdb$(X)  '$(DESTDIR)$(bindir)'/reindexdb$(X)
+ 	$(INSTALL_PROGRAM) pg_ping$(X)    '$(DESTDIR)$(bindir)'/pg_ping$(X)
  
  installdirs:
  	$(MKDIR_P) '$(DESTDIR)$(bindir)'
diff --git a/src/bin/scripts/pg_ping.c b/src/bin/scripts/pg_ping.c
new file mode 100644
index ...884b245
*** a/src/bin/scripts/pg_ping.c
--- b/src/bin/scripts/pg_ping.c
***************
*** 0 ****
--- 1,178 ----
+ /*-------------------------------------------------------------------------
+  *
+  * pg_ping --- checks the status of the PostgreSQL server
+  *
+  * Copyright (c) 2012, PostgreSQL Global Development Group
+  *
+  * src/bin/scripts/pg_ping.c
+  *
+  *-------------------------------------------------------------------------
+  */
+ 
+ #include "postgres_fe.h"
+ #include "common.h"
+ 
+ void
+ help(const char *progname);
+ 
+ int
+ main(int argc, char **argv)
+ {
+ 	int c,optindex,opt_index = 0;
+ 
+ 	const char *pghost = NULL;
+ 	const char *pgport = NULL;
+ 	const char *pguser = NULL; 
+ 	const char *pgdbname = NULL; 
+ 
+ 	const char *keywords[4], *values[4];
+ 
+ 	bool verbose = false;
+ 
+ 	PGPing rv;
+ 	PQconninfoOption *connect_options, *conn_opt_ptr;
+ 
+ 	static struct option long_options[] = {
+ 			{"dbname", required_argument, NULL, 'd'},
+ 			{"host", required_argument, NULL, 'h'},
+ 			{"port", required_argument, NULL, 'p'},
+ 			{"username", required_argument, NULL, 'U'},
+ 			{"verbose", no_argument, NULL, 'v'},
+ 			{NULL, 0, NULL, 0}
+ 		};
+ 
+ 	handle_help_version_opts(argc, argv, "pg_ping", help);
+ 
+ 	while ((c = getopt_long(argc, argv, "d:h:p:U:vV", long_options, &optindex)) != -1)
+ 	{
+ 		switch (c)
+ 		{
+ 			case 'd':
+ 				pgdbname = pg_strdup(optarg);
+ 				break;
+ 			case 'h':
+ 				pghost = pg_strdup(optarg);
+ 				break;
+ 			case 'p':
+ 				pgport = pg_strdup(optarg);
+ 				break;
+ 			case 'U':
+ 				pguser = pg_strdup(optarg);
+ 				break;
+ 			case 'v':
+ 				verbose = true;
+ 				break;
+ 			default:
+ 				/*
+ 				 * We need to make sure we don't return 1 here because someone
+ 				 * checking the return code might infer unintended meaning
+ 				 */
+ 				exit(PQPING_NO_ATTEMPT);
+ 		}
+ 	}
+ 
+ 	connect_options = PQconndefaults();
+ 	conn_opt_ptr = connect_options;
+ 
+ 	while (conn_opt_ptr->keyword)
+ 	{
+ 		if (strncmp(conn_opt_ptr->keyword, "host", 5) == 0)
+ 		{
+ 			if (pghost)
+ 			{
+ 				keywords[opt_index] = conn_opt_ptr->keyword;
+ 				values[opt_index] = pghost;
+ 				opt_index++;
+ 			}
+ 			else if (conn_opt_ptr->val)
+ 				pghost = conn_opt_ptr->val;
+ 			else
+ 				pghost = DEFAULT_PGSOCKET_DIR;
+ 		}
+ 		else if (strncmp(conn_opt_ptr->keyword, "port", 5) == 0)
+ 		{
+ 			if (pgport)
+ 			{
+ 				keywords[opt_index] = conn_opt_ptr->keyword;
+ 				values[opt_index] = pgport;
+ 				opt_index++;
+ 			}
+ 			else if (conn_opt_ptr->val)
+ 				pgport = conn_opt_ptr->val;
+ 		}
+ 		else if (strncmp(conn_opt_ptr->keyword, "user", 5) == 0)
+ 		{
+ 			if (pguser)
+ 			{
+ 				keywords[opt_index] = conn_opt_ptr->keyword;
+ 				values[opt_index] = pguser;
+ 				opt_index++;
+ 			}
+ 			else if (conn_opt_ptr->val)
+ 				pguser = conn_opt_ptr->val;
+ 		}
+ 		else if (strncmp(conn_opt_ptr->keyword, "dbname", 7) == 0)
+ 		{
+ 			if (pgdbname)
+ 			{
+ 				keywords[opt_index] = conn_opt_ptr->keyword;
+ 				values[opt_index] = pgdbname;
+ 				opt_index++;
+ 			}
+ 			else if (conn_opt_ptr->val)
+ 				pgdbname = conn_opt_ptr->val;
+ 		}
+ 		conn_opt_ptr++;
+ 	}
+ 
+ 	keywords[opt_index] = NULL;
+ 	values[opt_index] = NULL;
+ 
+ 	rv = PQpingParams(keywords, values, 1);
+ 
+ 	if (verbose)
+ 	{
+ 		printf("%s:%s - ", pghost, pgport);
+ 
+ 		switch (rv)
+ 		{
+ 			case PQPING_OK:
+ 				printf("Accepting Connections\n");
+ 				break;
+ 			case PQPING_REJECT:
+ 				printf("Rejecting Connections\n");
+ 				break;
+ 			case PQPING_NO_RESPONSE:
+ 				printf("No Response\n");
+ 				break;
+ 			case PQPING_NO_ATTEMPT:
+ 				printf("No Attempt\n");
+ 				break;
+ 			default:
+ 				printf("Unknown\n");
+ 		}
+ 	}
+ 
+ 	PQconninfoFree(connect_options);
+ 
+ 	exit(rv);
+ }
+ 
+ void
+ help(const char *progname)
+ {
+ 	printf(_("%s issues a connection check to a PostgreSQL database.\n\n"), progname);
+ 	printf(_("Usage:\n"));
+ 	printf(_("  %s [OPTION]...\n"), progname);
+ 
+ 	printf(_("\nOptions:\n"));
+ 	printf(_("  -d, --dbname=DBNAME      database name\n"));
+ 	printf(_("  -U, --username=USERNAME  database username\n"));
+ 	printf(_("  -V, --version            output version information, then exit\n"));
+ 	printf(_("  -v, --verbose            output verbose messages\n"));
+ 	printf(_("  -?, --help               show this help, then exit\n"));
+ 
+ 	printf(_("\nConnection options:\n"));
+ 	printf(_("  -h, --host=HOSTNAME      database server host or socket directory\n"));
+ 	printf(_("  -p, --port=PORT          database server port\n"));
+ }
