diff --git a/doc/src/sgml/monitoring.sgml b/doc/src/sgml/monitoring.sgml index 231a099cd1..90a77d0a2c 100644 --- a/doc/src/sgml/monitoring.sgml +++ b/doc/src/sgml/monitoring.sgml @@ -1,5 +1,5 @@ @@ -208,9 +208,9 @@ postgres: user database host stats_command_string has been turned on. - Furthermore, these columns can only be accessed by - 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 + Furthermore, these columns read as null unless the user examining + the view is a superuser or the same as the user owning the process + being reported on. (Note that because of the collector's reporting delay, current query will only be up-to-date for long-running queries.) @@ -540,16 +540,16 @@ postgres: user database host pg_stat_get_backend_activity_start(integer) - text + timestamp with time zone - The time at which the specified backend process' currently - executing query was started (null if the current user is not a - superuser, or stats_command_string is not - on) + The time at which the given backend process' currently + executing query was started (null if the + current user is not a superuser nor the same user as that of + the session being queried, or + stats_command_string is not on) - pg_stat_reset() boolean diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml index 131a670b59..9311aabfda 100644 --- a/doc/src/sgml/runtime.sgml +++ b/doc/src/sgml/runtime.sgml @@ -1,5 +1,5 @@ @@ -1176,8 +1176,9 @@ SET ENABLE_SEQSCAN TO OFF; Enables the collection of statistics on the currently executing command of each session, along with the time at which that command began execution. This option is off by - default. Note that even when enabled, this information is only - visible to the superuser, so it should not represent a + default. Note that even when enabled, this information is not + visible to all users, only to superusers and the user owning + the session being reported on; so it should not represent a security risk. This data can be accessed via the pg_stat_activity system view; refer to for more information. diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index c2f0ea2c82..787f0226cd 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -308,14 +308,14 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS) int32 beid; AbsoluteTime sec; int usec; - Timestamp result; + TimestampTz result; beid = PG_GETARG_INT32(0); - if (!superuser()) + if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL) PG_RETURN_NULL(); - if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL) + if (!superuser() && beentry->userid != GetUserId()) PG_RETURN_NULL(); sec = beentry->activity_start_sec; @@ -341,7 +341,7 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS) date2j(1970, 1, 1)) * 86400)); #endif - PG_RETURN_TIMESTAMP(result); + PG_RETURN_TIMESTAMPTZ(result); } diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh index 473b2786cf..079ceb076b 100644 --- a/src/bin/initdb/initdb.sh +++ b/src/bin/initdb/initdb.sh @@ -27,7 +27,7 @@ # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group # Portions Copyright (c) 1994, Regents of the University of California # -# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.187 2003/03/25 16:15:44 petere Exp $ +# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.188 2003/04/04 03:03:53 tgl Exp $ # #------------------------------------------------------------------------- @@ -954,7 +954,7 @@ CREATE VIEW pg_stat_activity AS \ pg_stat_get_backend_userid(S.backendid) AS usesysid, \ U.usename AS usename, \ pg_stat_get_backend_activity(S.backendid) AS current_query, \ - pg_stat_get_backend_activity_start(S.backendid) AS query_start \ + pg_stat_get_backend_activity_start(S.backendid) AS query_start \ FROM pg_database D, \ (SELECT pg_stat_get_backend_idset() AS backendid) AS S, \ pg_shadow U \ diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index ff9f65d962..6c0bcfdfc9 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $Id: pg_proc.h,v 1.290 2003/03/21 21:54:29 momjian Exp $ + * $Id: pg_proc.h,v 1.291 2003/04/04 03:03:54 tgl Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -2745,7 +2745,7 @@ DATA(insert OID = 1939 ( pg_stat_get_backend_userid PGNSP PGUID 12 f f t f s 1 DESCR("Statistics: User ID of backend"); DATA(insert OID = 1940 ( pg_stat_get_backend_activity PGNSP PGUID 12 f f t f s 1 25 "23" pg_stat_get_backend_activity - _null_ )); DESCR("Statistics: Current query of backend"); -DATA(insert OID = 2094 ( pg_stat_get_backend_activity_start PGNSP PGUID 12 f f t f s 1 1114 "23" pg_stat_get_backend_activity_start - _null_)); +DATA(insert OID = 2094 ( pg_stat_get_backend_activity_start PGNSP PGUID 12 f f t f s 1 1184 "23" pg_stat_get_backend_activity_start - _null_)); DESCR("Statistics: Start time for current query of backend"); DATA(insert OID = 1941 ( pg_stat_get_db_numbackends PGNSP PGUID 12 f f t f s 1 23 "26" pg_stat_get_db_numbackends - _null_ )); DESCR("Statistics: Number of backends in database");