Skip to content

Commit 3b4ca4c

Browse files
committed
Code review for pg_stat_get_backend_activity_start patch --- fix
return type, make protection condition agree with recent change to pg_stat_get_backend_activity, clean up documentation.
1 parent a385186 commit 3b4ca4c

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

doc/src/sgml/monitoring.sgml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/monitoring.sgml,v 1.19 2003/03/25 16:15:37 petere Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/monitoring.sgml,v 1.20 2003/04/04 03:03:53 tgl Exp $
33
-->
44

55
<chapter id="monitoring">
@@ -208,9 +208,9 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
208208
which the current query began execution. The columns that report
209209
data on the current query are only available if the parameter
210210
<varname>stats_command_string</varname> has been turned on.
211-
Furthermore, these columns can only be accessed by
212-
superusers; or when the user examining the view is the same as the user
213-
in the row; for others it reads as null. (Note that because of the
211+
Furthermore, these columns read as null unless the user examining
212+
the view is a superuser or the same as the user owning the process
213+
being reported on. (Note that because of the
214214
collector's reporting delay, current query will only be up-to-date for
215215
long-running queries.)</entry>
216216
</row>
@@ -540,16 +540,16 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
540540

541541
<row>
542542
<entry><literal><function>pg_stat_get_backend_activity_start</function>(<type>integer</type>)</literal></entry>
543-
<entry><type>text</type></entry>
543+
<entry><type>timestamp with time zone</type></entry>
544544
<entry>
545-
The time at which the specified backend process' currently
546-
executing query was started (null if the current user is not a
547-
superuser, or <varname>stats_command_string</varname> is not
548-
on)
545+
The time at which the given backend process' currently
546+
executing query was started (null if the
547+
current user is not a superuser nor the same user as that of
548+
the session being queried, or
549+
<varname>stats_command_string</varname> is not on)
549550
</entry>
550551
</row>
551552

552-
553553
<row>
554554
<entry><literal><function>pg_stat_reset</function>()</literal></entry>
555555
<entry><type>boolean</type></entry>

doc/src/sgml/runtime.sgml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.176 2003/04/03 23:32:47 tgl Exp $
2+
$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.177 2003/04/04 03:03:53 tgl Exp $
33
-->
44

55
<Chapter Id="runtime">
@@ -1176,8 +1176,9 @@ SET ENABLE_SEQSCAN TO OFF;
11761176
Enables the collection of statistics on the currently
11771177
executing command of each session, along with the time at
11781178
which that command began execution. This option is off by
1179-
default. Note that even when enabled, this information is only
1180-
visible to the superuser, so it should not represent a
1179+
default. Note that even when enabled, this information is not
1180+
visible to all users, only to superusers and the user owning
1181+
the session being reported on; so it should not represent a
11811182
security risk. This data can be accessed via the
11821183
<structname>pg_stat_activity</structname> system view; refer
11831184
to <xref linkend="monitoring"> for more information.

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
308308
int32 beid;
309309
AbsoluteTime sec;
310310
int usec;
311-
Timestamp result;
311+
TimestampTz result;
312312

313313
beid = PG_GETARG_INT32(0);
314314

315-
if (!superuser())
315+
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
316316
PG_RETURN_NULL();
317317

318-
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
318+
if (!superuser() && beentry->userid != GetUserId())
319319
PG_RETURN_NULL();
320320

321321
sec = beentry->activity_start_sec;
@@ -341,7 +341,7 @@ pg_stat_get_backend_activity_start(PG_FUNCTION_ARGS)
341341
date2j(1970, 1, 1)) * 86400));
342342
#endif
343343

344-
PG_RETURN_TIMESTAMP(result);
344+
PG_RETURN_TIMESTAMPTZ(result);
345345
}
346346

347347

src/bin/initdb/initdb.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
2828
# Portions Copyright (c) 1994, Regents of the University of California
2929
#
30-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.187 2003/03/25 16:15:44 petere Exp $
30+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.188 2003/04/04 03:03:53 tgl Exp $
3131
#
3232
#-------------------------------------------------------------------------
3333

@@ -954,7 +954,7 @@ CREATE VIEW pg_stat_activity AS \
954954
pg_stat_get_backend_userid(S.backendid) AS usesysid, \
955955
U.usename AS usename, \
956956
pg_stat_get_backend_activity(S.backendid) AS current_query, \
957-
pg_stat_get_backend_activity_start(S.backendid) AS query_start \
957+
pg_stat_get_backend_activity_start(S.backendid) AS query_start \
958958
FROM pg_database D, \
959959
(SELECT pg_stat_get_backend_idset() AS backendid) AS S, \
960960
pg_shadow U \

src/include/catalog/pg_proc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: pg_proc.h,v 1.290 2003/03/21 21:54:29 momjian Exp $
10+
* $Id: pg_proc.h,v 1.291 2003/04/04 03:03:54 tgl Exp $
1111
*
1212
* NOTES
1313
* 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
27452745
DESCR("Statistics: User ID of backend");
27462746
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_ ));
27472747
DESCR("Statistics: Current query of backend");
2748-
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_));
2748+
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_));
27492749
DESCR("Statistics: Start time for current query of backend");
27502750
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_ ));
27512751
DESCR("Statistics: Number of backends in database");

0 commit comments

Comments
 (0)