diff --git a/doc/src/sgml/catalogs.sgml b/doc/src/sgml/catalogs.sgml
new file mode 100644
index b8cc16f..a436aeb
*** a/doc/src/sgml/catalogs.sgml
--- b/doc/src/sgml/catalogs.sgml
***************
*** 3652,3657 ****
--- 3652,3669 ----
       </row>
  
       <row>
+       <entry><structfield>lanchecker</structfield></entry>
+       <entry><type>oid</type></entry>
+       <entry><literal><link linkend="catalog-pg-proc"><structname>pg_proc</structname></link>.oid</literal></entry>
+       <entry>
+        This references a correctness check function that is used by
+        <command>CHECK FUNCTION</> and <command>CHECK TRIGGER</> for in-depth
+        checks of function bodies.
+        Zero if no such function is provided.
+       </entry>
+      </row>
+ 
+      <row>
        <entry><structfield>lanacl</structfield></entry>
        <entry><type>aclitem[]</type></entry>
        <entry></entry>
***************
*** 4262,4267 ****
--- 4274,4285 ----
       </row>
  
       <row>
+       <entry><structfield>tmplchecker</structfield></entry>
+       <entry><type>text</type></entry>
+       <entry>Name of correctness check function, or null if none</entry>
+      </row>
+ 
+      <row>
        <entry><structfield>tmpllibrary</structfield></entry>
        <entry><type>text</type></entry>
        <entry>Path of shared library that implements language</entry>
diff --git a/doc/src/sgml/plhandler.sgml b/doc/src/sgml/plhandler.sgml
new file mode 100644
index 54b88ef..21d043b
*** a/doc/src/sgml/plhandler.sgml
--- b/doc/src/sgml/plhandler.sgml
*************** CREATE LANGUAGE plsample
*** 161,170 ****
      Although providing a call handler is sufficient to create a minimal
      procedural language, there are two other functions that can optionally
      be provided to make the language more convenient to use.  These
!     are a <firstterm>validator</firstterm> and an
!     <firstterm>inline handler</firstterm>.  A validator can be provided
!     to allow language-specific checking to be done during
!     <xref linkend="sql-createfunction">.
      An inline handler can be provided to allow the language to support
      anonymous code blocks executed via the <xref linkend="sql-do"> command.
     </para>
--- 161,173 ----
      Although providing a call handler is sufficient to create a minimal
      procedural language, there are two other functions that can optionally
      be provided to make the language more convenient to use.  These
!     are a <firstterm>validator</firstterm>, a <firstterm>checker</firstterm>
!     and an <firstterm>inline handler</firstterm>.
!     A validator can be provided to allow language-specific checking to be
!     done during <xref linkend="sql-createfunction">.
!     A checker performs in-depth checks of function bodies via the
!     commands <xref linkend="sql-checkfunction"> and
!     <xref linkend="sql-checktrigger">.
      An inline handler can be provided to allow the language to support
      anonymous code blocks executed via the <xref linkend="sql-do"> command.
     </para>
*************** CREATE LANGUAGE plsample
*** 203,208 ****
--- 206,232 ----
     </para>
  
     <para>
+     If a checker is provided by a procedural language, it must be declared
+     as a function taking two arguments, one of type <type>oid</> and one of
+     type <type>regclass</>.  The checker's result is ignored, so it is customarily
+     declared to return <type>void</>.
+     The checker will be called whenever a function is checked with
+     <command>CHECK FUNCTION</> or <command>CHECK TRIGGER</>.
+     The passed-in OID is the OID of the function's <classname>pg_proc</>
+     row.  The passed-in <type>regclass</> is the OID of the
+     <classname>pg_class</> row of the table on which the trigger is defined,
+     or <symbol>InvalidOid</symbol> in the case of <command>CHECK FUNCTION</>.
+     The checker must fetch these rows in the usual way, and do
+     whatever checking is appropriate.
+     Typical checks include verifying that all referenced database objects
+     actually exist or style checks like verifying that all declared
+     variables are actually used.  If the checker finds the function to be okay,
+     it should just return.  If it finds a problem, it should report a
+     <literal>WARNING</> via the normal <function>ereport()</> error reporting
+     mechanism.
+    </para>
+ 
+    <para>
      If an inline handler is provided by a procedural language, it
      must be declared as a function taking a single parameter of type
      <type>internal</>.  The inline handler's result is ignored, so it is
diff --git a/doc/src/sgml/ref/allfiles.sgml b/doc/src/sgml/ref/allfiles.sgml
new file mode 100644
index 382d297..ef75780
*** a/doc/src/sgml/ref/allfiles.sgml
--- b/doc/src/sgml/ref/allfiles.sgml
*************** Complete list of usable sgml source file
*** 40,45 ****
--- 40,47 ----
  <!ENTITY alterView          SYSTEM "alter_view.sgml">
  <!ENTITY analyze            SYSTEM "analyze.sgml">
  <!ENTITY begin              SYSTEM "begin.sgml">
+ <!ENTITY checkFunction      SYSTEM "check_function.sgml">
+ <!ENTITY checkTrigger       SYSTEM "check_trigger.sgml">
  <!ENTITY checkpoint         SYSTEM "checkpoint.sgml">
  <!ENTITY close              SYSTEM "close.sgml">
  <!ENTITY cluster            SYSTEM "cluster.sgml">
diff --git a/doc/src/sgml/ref/check_function.sgml b/doc/src/sgml/ref/check_function.sgml
new file mode 100644
index ...6549846
*** a/doc/src/sgml/ref/check_function.sgml
--- b/doc/src/sgml/ref/check_function.sgml
***************
*** 0 ****
--- 1,138 ----
+ <!--
+ doc/src/sgml/ref/check_function.sgml
+ -->
+ 
+ <refentry id="SQL-CHECKFUNCTION">
+  <refmeta>
+   <refentrytitle>CHECK FUNCTION</refentrytitle>
+   <manvolnum>7</manvolnum>
+   <refmiscinfo>SQL - Language Statements</refmiscinfo>
+  </refmeta>
+ 
+  <refnamediv>
+   <refname>CHECK FUNCTION</refname>
+   <refpurpose>perform an in-depth check of an existing function</refpurpose>
+  </refnamediv>
+ 
+  <indexterm zone="sql-checkfunction">
+   <primary>CHECK FUNCTION</primary>
+  </indexterm>
+ 
+  <refsynopsisdiv>
+ <synopsis>
+ CHECK FUNCTION <replaceable class="parameter">name</replaceable> ( [ [ <replaceable class="parameter">argmode</replaceable> ] [ <replaceable class="parameter">argname</replaceable> ] <replaceable class="parameter">argtype</replaceable> [, ...] ] )
+  | CHECK FUNCTION ALL [ IN LANGUAGE <replaceable class="parameter">lang_name</replaceable> ] [ IN SCHEMA <replaceable class="parameter">schema_name</replaceable> ] [ FOR ROLE <replaceable class="parameter">owner_name</replaceable> ]
+ </synopsis>
+  </refsynopsisdiv>
+ 
+  <refsect1 id="sql-checkfunction-description">
+   <title>Description</title>
+ 
+   <para>
+    <command>CHECK FUNCTION</command> performs an in-depth check of existing
+    functions if the procedural language supports it (currently only
+    <link linkend="plpgsql">PL/pgSQL</link> is defined with a check function).
+    The checks performed depend on the language, but typically include checks
+    for the existence of database objects referenced by the function or style
+    checks like defined but unused variables.
+   </para>
+ 
+   <para>
+    If a problem is found with a function, a <literal>WARNING</> will be raised.
+   </para>
+ 
+   <para>The form <command>CHECK FUNCTION ALL</command> will check all functions
+    matching the specified criteria.  If no criteria are specified, functions in
+    the schemas <literal>pg_catalog</literal> and <literal>information_schema</literal>
+    will be excluded from the check.
+   </para>
+  </refsect1>
+ 
+  <refsect1>
+   <title>Parameters</title>
+ 
+   <variablelist>
+    <varlistentry>
+     <term><replaceable class="parameter">name</replaceable></term>
+ 
+     <listitem>
+      <para>
+       The name (optionally schema-qualified) of an existing function.
+      </para>
+     </listitem>
+    </varlistentry>
+ 
+    <varlistentry>
+     <term><replaceable class="parameter">argmode</replaceable></term>
+ 
+     <listitem>
+      <para>
+       The mode of an argument: <literal>IN</>, <literal>OUT</>,
+       <literal>INOUT</>, or <literal>VARIADIC</>.
+       If omitted, the default is <literal>IN</>.
+       Note that <command>CHECK FUNCTION</command> does not actually pay
+       any attention to <literal>OUT</> arguments, since only the input
+       arguments are needed to determine the function's identity.
+       So it is sufficient to list the <literal>IN</>, <literal>INOUT</>,
+       and <literal>VARIADIC</> arguments.
+      </para>
+     </listitem>
+    </varlistentry>
+ 
+    <varlistentry>
+     <term><replaceable class="parameter">argname</replaceable></term>
+ 
+     <listitem>
+      <para>
+       The name of an argument.
+       Note that <command>CHECK FUNCTION</command> does not actually pay
+       any attention to argument names, since only the argument data
+       types are needed to determine the function's identity.
+      </para>
+     </listitem>
+    </varlistentry>
+ 
+    <varlistentry>
+     <term><replaceable class="parameter">lang_name</replaceable></term>
+ 
+     <listitem>
+      <para>
+       The name of a procedural language.
+       Specifies that only functions written in this language should
+       be checked.
+      </para>
+     </listitem>
+    </varlistentry>
+ 
+    <varlistentry>
+     <term><replaceable class="parameter">schema_name</replaceable></term>
+ 
+     <listitem>
+      <para>
+       Specifies that only functions in this schema should be checked.
+      </para>
+     </listitem>
+    </varlistentry>
+ 
+    <varlistentry>
+     <term><replaceable class="parameter">owner_name</replaceable></term>
+ 
+     <listitem>
+      <para>
+       Specifies that only functions owned by this role should be checked.
+      </para>
+     </listitem>
+    </varlistentry>
+   </variablelist>
+  </refsect1>
+ 
+  <refsect1 id="sql-checkfunction-compat">
+   <title>Compatibility</title>
+ 
+   <para>
+    The <command>CHECK FUNCTION</command> statement is a
+    <productname>PostgreSQL</productname> extension.
+   </para>
+  </refsect1>
+ 
+ </refentry>
diff --git a/doc/src/sgml/ref/check_trigger.sgml b/doc/src/sgml/ref/check_trigger.sgml
new file mode 100644
index ...d97b396
*** a/doc/src/sgml/ref/check_trigger.sgml
--- b/doc/src/sgml/ref/check_trigger.sgml
***************
*** 0 ****
--- 1,79 ----
+ <!--
+ doc/src/sgml/ref/check_trigger.sgml
+ -->
+ 
+ <refentry id="SQL-CHECKTRIGGER">
+  <refmeta>
+   <refentrytitle>CHECK TRIGGER</refentrytitle>
+   <manvolnum>7</manvolnum>
+   <refmiscinfo>SQL - Language Statements</refmiscinfo>
+  </refmeta>
+ 
+  <refnamediv>
+   <refname>CHECK TRIGGER</refname>
+   <refpurpose>perform an in-depth check of an existing trigger function</refpurpose>
+  </refnamediv>
+ 
+  <indexterm zone="sql-checktrigger">
+   <primary>CHECK TRIGGER</primary>
+  </indexterm>
+ 
+  <refsynopsisdiv>
+ <synopsis>
+ CHECK TRIGGER <replaceable class="parameter">name</replaceable> ON <replaceable class="parameter">tablename</replaceable>
+ </synopsis>
+  </refsynopsisdiv>
+ 
+  <refsect1 id="sql-checktrigger-description">
+   <title>Description</title>
+ 
+   <para>
+    <command>CHECK FUNCTION</command> performs an in-depth check of a trigger
+    function if the procedural language supports it (currently only
+    <link linkend="plpgsql">PL/pgSQL</link> is defined with a check function).
+    The checks performed depend on the language, but typically include checks
+    for the existence of database objects referenced by the function or style
+    checks like defined but unused variables.
+   </para>
+ 
+   <para>
+    If a problem is found with the function, a <literal>WARNING</> will be raised.
+   </para>
+  </refsect1>
+ 
+  <refsect1>
+   <title>Parameters</title>
+ 
+   <variablelist>
+    <varlistentry>
+     <term><replaceable class="parameter">name</replaceable></term>
+     <listitem>
+      <para>
+       The name of a trigger.  The trigger function for this trigger will
+       be checked.
+      </para>
+     </listitem>
+    </varlistentry>
+ 
+    <varlistentry>
+     <term><replaceable class="parameter">table</replaceable></term>
+     <listitem>
+      <para>
+       The name (optionally schema-qualified) of the table or view the trigger
+       is for.
+      </para>
+     </listitem>
+    </varlistentry>
+   </variablelist>
+  </refsect1>
+ 
+  <refsect1 id="sql-checktrigger-compat">
+   <title>Compatibility</title>
+ 
+   <para>
+    The <command>CHECK TRIGGER</command> statement is a
+    <productname>PostgreSQL</productname> extension.
+   </para>
+  </refsect1>
+ 
+ </refentry>
diff --git a/doc/src/sgml/ref/create_language.sgml b/doc/src/sgml/ref/create_language.sgml
new file mode 100644
index 0995b13..34fc36e
*** a/doc/src/sgml/ref/create_language.sgml
--- b/doc/src/sgml/ref/create_language.sgml
*************** PostgreSQL documentation
*** 23,29 ****
  <synopsis>
  CREATE [ OR REPLACE ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</replaceable>
  CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</replaceable>
!     HANDLER <replaceable class="parameter">call_handler</replaceable> [ INLINE <replaceable class="parameter">inline_handler</replaceable> ] [ VALIDATOR <replaceable>valfunction</replaceable> ]
  </synopsis>
   </refsynopsisdiv>
  
--- 23,29 ----
  <synopsis>
  CREATE [ OR REPLACE ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</replaceable>
  CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE <replaceable class="parameter">name</replaceable>
!     HANDLER <replaceable class="parameter">call_handler</replaceable> [ INLINE <replaceable class="parameter">inline_handler</replaceable> ] [ VALIDATOR <replaceable>valfunction</replaceable> ] [ CHECK <replaceable>checkfunction</replaceable> ]
  </synopsis>
   </refsynopsisdiv>
  
*************** CREATE [ OR REPLACE ] [ TRUSTED ] [ PROC
*** 217,222 ****
--- 217,249 ----
        </para>
       </listitem>
      </varlistentry>
+ 
+     <varlistentry>
+      <term><literal>CHECK</literal> <replaceable class="parameter">checkfunction</replaceable></term>
+ 
+      <listitem>
+       <para><replaceable class="parameter">checkfunction</replaceable> is the
+        name of a previously registered function that will be called
+        by <command>CHECK FUNCTION</command> and <command>CHECK TRIGGER</command>
+        to check the bodies of functions defined in the language.
+        If no check function is specified, this kind of check is not available.
+        The check function must take two arguments, one of type <type>oid</type>
+        (the OID of the function to be checked), and one of type <type>regclass</type>
+        (the table with the trigger for <command>CHECK TRIGGER</command>).
+        The check function will typically return <type>void</>.
+       </para>
+ 
+       <para>
+        A check function would typically perform an in-depth check of the function
+        body, for example that all referenced database objects exist, but it could
+        also check for stylistic problems like defined but unreferenced variables.
+        To signal a problem found during the check, the function should use the
+        <function>ereport()</function> to report a <literal>WARNING</>.
+        The return value of the function is ignored.
+       </para>
+      </listitem>
+     </varlistentry>
+ 
     </variablelist>
  
    <para>
diff --git a/doc/src/sgml/reference.sgml b/doc/src/sgml/reference.sgml
new file mode 100644
index 7326519..460794e
*** a/doc/src/sgml/reference.sgml
--- b/doc/src/sgml/reference.sgml
***************
*** 68,73 ****
--- 68,75 ----
     &alterView;
     &analyze;
     &begin;
+    &checkFunction;
+    &checkTrigger;
     &checkpoint;
     &close;
     &cluster;
