diff --git a/src/backend/tcop/fastpath.c b/src/backend/tcop/fastpath.c
index c9fa715600fee72620692f6eb29162c0eb558260..3f769d9a9ad60b644299a55e2e3e307ea4f1481d 100644
--- a/src/backend/tcop/fastpath.c
+++ b/src/backend/tcop/fastpath.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.86 2006/04/04 19:35:35 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/backend/tcop/fastpath.c,v 1.87 2006/06/11 15:49:28 tgl Exp $
  *
  * NOTES
  *	  This cruft is the server side of PQfn.
@@ -26,6 +26,7 @@
 #include "miscadmin.h"
 #include "mb/pg_wchar.h"
 #include "tcop/fastpath.h"
+#include "tcop/tcopprot.h"
 #include "utils/acl.h"
 #include "utils/lsyscache.h"
 #include "utils/syscache.h"
@@ -299,14 +300,25 @@ HandleFunctionRequest(StringInfo msgBuf)
 				 errmsg("current transaction is aborted, "
 						"commands ignored until end of transaction block")));
 
+	/*
+	 * Now that we know we are in a valid transaction, set snapshot in
+	 * case needed by function itself or one of the datatype I/O routines.
+	 */
+	ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
+
 	/*
 	 * Begin parsing the buffer contents.
 	 */
 	if (PG_PROTOCOL_MAJOR(FrontendProtocol) < 3)
-		(void) pq_getmsgstring(msgBuf); /* dummy string */
+		(void) pq_getmsgstring(msgBuf);			/* dummy string */
 
 	fid = (Oid) pq_getmsgint(msgBuf, 4);		/* function oid */
 
+	if (log_statement == LOGSTMT_ALL)
+		ereport(LOG,
+				(errmsg("fastpath function call: function OID %u",
+						fid)));
+
 	/*
 	 * There used to be a lame attempt at caching lookup info here. Now we
 	 * just do the lookups on every call.
diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c
index 2135c92fd807dc7120c939dc2c094bb3dd0eb1cd..a43478088f9ac8092c8a4988bc6528a96ea40288 100644
--- a/src/backend/tcop/postgres.c
+++ b/src/backend/tcop/postgres.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.486 2006/04/25 00:25:18 momjian Exp $
+ *	  $PostgreSQL: pgsql/src/backend/tcop/postgres.c,v 1.487 2006/06/11 15:49:28 tgl Exp $
  *
  * NOTES
  *	  this is the "main" module of the postgres backend and
@@ -3344,12 +3344,18 @@ PostgresMain(int argc, char *argv[], const char *username)
 				/* start an xact for this function invocation */
 				initialize_command();
 
+				/*
+				 * Note: we may at this point be inside an aborted
+				 * transaction.  We can't throw error for that until
+				 * we've finished reading the function-call message, so
+				 * HandleFunctionRequest() must check for it after doing so.
+				 * Be careful not to do anything that assumes we're inside a
+				 * valid transaction here.
+				 */
+
 				/* switch back to message context */
 				MemoryContextSwitchTo(MessageContext);
 
-				/* set snapshot in case function needs one */
-				ActiveSnapshot = CopySnapshot(GetTransactionSnapshot());
-
 				if (HandleFunctionRequest(&input_message) == EOF)
 				{
 					/* lost frontend connection during F message input */