Added hints about the reason, why the command string in
authorJan Wieck <JanWieck@Yahoo.com>
Thu, 12 Feb 2004 01:44:22 +0000 (01:44 +0000)
committerJan Wieck <JanWieck@Yahoo.com>
Thu, 12 Feb 2004 01:44:22 +0000 (01:44 +0000)
the view pg_stat_activity is missing, as per Bruces suggestion.

Jan

src/backend/utils/adt/pgstatfuncs.c

index 440783764ae2969eb8d28e59cd5670d9ac3b6676..03166eac482829ddfbb73e4e1415fbdccc2b75c1 100644 (file)
@@ -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();
-
-   if (!superuser() && beentry->userid != GetUserId())
-       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;
 
-   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);
 }