diff --git a/src/tools/pginclude/headerscheck b/src/tools/pginclude/headerscheck
index abbba7aa63..69897092b2 100755
--- a/src/tools/pginclude/headerscheck
+++ b/src/tools/pginclude/headerscheck
@@ -142,7 +142,14 @@ do
 
 	# OK, create .c file to include this .h file.
 	{
-	    test "$f" != src/include/postgres_fe.h && echo '#include "postgres.h"'
+	    # Ideally we'd pre-include only the appropriate one of
+	    # postgres.h, postgres_fe.h, or c.h, but we don't have enough
+	    # info here to guess what to do in most cases.
+	    if test "$f" != src/include/postgres_fe.h -a \
+		    "$f" != src/interfaces/libpq/libpq-fe.h
+	    then
+		echo '#include "postgres.h"'
+	    fi
 	    echo "#include \"$f\""
 	} >$tmp/test.c
 
