Tom Lane wrote:
> Kevin Brown <[EMAIL PROTECTED]> writes:

[...]

> > It would also be handy if users could see their own queries while the
> > rest remain blank.  That would require changing
> > pg_stat_get_backend_activity() so that it returns a value if the user
> > is the superuser or if the user asking for the answer is the same as
> > the user who owns the backend entry being looked up.  Are there any
> > pitfalls to implementing that?
> 
> Seems reasonable offhand ...

Here's the patch to make this happen.  The first is against 7.2.4, the
second is against CVS tip.


If I got it wrong and need to use something other than GetUserId(),
please let me know.



-- 
Kevin Brown                                           [EMAIL PROTECTED]
--- ../postgresql-7.2.4/src/backend/utils/adt/pgstatfuncs.c     Wed Oct 24 22:49:45 
2001
+++ src/backend/utils/adt/pgstatfuncs.c Thu Mar  6 20:04:26 2003
@@ -264,12 +264,12 @@
        int                     len;
        text       *result;
 
-       if (!superuser())
-               PG_RETURN_NULL();
-
        beid = PG_GETARG_INT32(0);
 
        if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
+               PG_RETURN_NULL();
+
+       if (!superuser() && beentry->userid != GetUserId())
                PG_RETURN_NULL();
 
        len = strlen(beentry->activity);
Index: src/backend/utils/adt/pgstatfuncs.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/pgstatfuncs.c,v
retrieving revision 1.9
diff -u -d -r1.9 pgstatfuncs.c
--- src/backend/utils/adt/pgstatfuncs.c 2002/12/04 05:18:34     1.9
+++ src/backend/utils/adt/pgstatfuncs.c 2003/03/07 04:09:01
@@ -284,12 +284,12 @@
        int                     len;
        text       *result;
 
-       if (!superuser())
-               PG_RETURN_NULL();
-
        beid = PG_GETARG_INT32(0);
 
        if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
+               PG_RETURN_NULL();
+
+       if (!superuser() && beentry->userid != GetUserId())
                PG_RETURN_NULL();
 
        len = strlen(beentry->activity);
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Reply via email to