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. > >> > >> Seems reasonable offhand ... > > > Here's the patch to make this happen. The first is against 7.2.4, the > > second is against CVS tip. > > You forgot documentation fixes. Certainly the entry in > http://www.ca.postgresql.org/users-lounge/docs/7.3/postgres/monitoring-stats.html#MONITORING-STATS-VIEWS > needs to change; not sure if there are any other places, but that's your > task to look...
Ooops. Okay, the attached patch attached fixes that as well. The only references to pg_stat_get_backend_activity(), pg_stat_activity, or stats_command_string that needed to be changed were those in doc/src/monitoring.sgml. If I missed something let me know. So: the following patch fixes doc/src/monitoring.sgml and src/backend/utils/adt/pgstatfuncs.c to make it possible to see your own queries when looking at pg_stat_activity or when using the pg_stat_get_backend_activity function. The patch is against the current (as of now :-) CVS tip. -- Kevin Brown [EMAIL PROTECTED]
Index: doc/src/sgml/monitoring.sgml =================================================================== RCS file: /projects/cvsroot/pgsql-server/doc/src/sgml/monitoring.sgml,v retrieving revision 1.15 diff -u -d -r1.15 monitoring.sgml --- doc/src/sgml/monitoring.sgml 2002/11/11 20:14:03 1.15 +++ doc/src/sgml/monitoring.sgml 2003/03/07 06:58:05 @@ -204,12 +204,16 @@ <tbody> <row> - <entry><structname>pg_stat_activity</></entry> - <entry>One row per server process, showing process <acronym>ID</>, database, - user, and current query. The current query column is only available - to superusers; for others it reads as null. (Note that because of - the collector's reporting delay, current query will only be up-to-date - for long-running queries.)</entry> + <entry><structname>pg_stat_activity</></entry> <entry>One row + per server process, showing process <acronym>ID</>, database, + user, and current query. Values in the current query column are + only available to superusers, or when the user examining the + view is the same as the user in the row; for others it reads as + null. (Note that because of the collector's reporting delay, + current query will only be up-to-date for long-running + queries.). <varname>STATS_COMMAND_STRING</varname> must be + enabled for anything to show in the current query + column.</entry> </row> <row> @@ -518,7 +522,8 @@ <entry><function>pg_stat_get_backend_activity</function>(<type>integer</type>)</entry> <entry><type>text</type></entry> <entry> - Current query of backend process (NULL if caller is not superuser) + Current query of backend process (NULL unless caller is + superuser or is the same user as that of the backend being queried) </entry> </row> 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 06:58:05 @@ -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 5: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faqs/FAQ.html