From 1ecd035b318f949090be59d1e1826b3d0c8f03e9 Mon Sep 17 00:00:00 2001
From: Jan Wieck <JanWieck@Yahoo.com>
Date: Thu, 12 Feb 2004 01:44:22 +0000
Subject: [PATCH] Added hints about the reason, why the command string in the
 view pg_stat_activity is missing, as per Bruces suggestion.

Jan
---
 src/backend/utils/adt/pgstatfuncs.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index 440783764a..03166eac48 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -286,20 +286,24 @@ pg_stat_get_backend_activity(PG_FUNCTION_ARGS)
 	PgStat_StatBeEntry *beentry;
 	int32		beid;
 	int			len;
+	char	   *activity;
 	text	   *result;
 
 	beid = PG_GETARG_INT32(0);
 
 	if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
-		PG_RETURN_NULL();
+		activity = "<backend information not available>";
+	else if (!superuser() && beentry->userid != GetUserId())
+		activity = "<insufficient privilege>";
+	else if (*(beentry->activity) == '\0')
+		activity = "<command string not enabled>";
+	else
+		activity = beentry->activity;
 
-	if (!superuser() && beentry->userid != GetUserId())
-		PG_RETURN_NULL();
-
-	len = strlen(beentry->activity);
+	len = strlen(activity);
 	result = palloc(VARHDRSZ + len);
 	VARATT_SIZEP(result) = VARHDRSZ + len;
-	memcpy(VARDATA(result), beentry->activity, len);
+	memcpy(VARDATA(result), activity, len);
 
 	PG_RETURN_TEXT_P(result);
 }