Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 0c61cff

Browse files
committed
Make pg_stat_activity.application_name visible to all users, rather than
being hidden when current_query is. Relocate it to a column position more consistent with that behavior. Per discussion.
1 parent 42b2907 commit 0c61cff

File tree

6 files changed

+52
-51
lines changed

6 files changed

+52
-51
lines changed

doc/src/sgml/monitoring.sgml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.72 2009/11/28 23:38:07 tgl Exp $ -->
1+
<!-- $PostgreSQL: pgsql/doc/src/sgml/monitoring.sgml,v 1.73 2009/11/29 18:14:30 tgl Exp $ -->
22

33
<chapter id="monitoring">
44
<title>Monitoring Database Activity</title>
@@ -235,15 +235,15 @@ postgres: <replaceable>user</> <replaceable>database</> <replaceable>host</> <re
235235
<row>
236236
<entry><structname>pg_stat_activity</></entry>
237237
<entry>One row per server process, showing database OID, database
238-
name, process <acronym>ID</>, user OID, user name, current query,
239-
query's waiting status, time at which the current transaction and
240-
current query began execution, time at which the process was
241-
started, client's address and port number, and application name.
238+
name, process <acronym>ID</>, user OID, user name, application name,
239+
current query, query's waiting status, time at which the current
240+
transaction and current query began execution, time at which the
241+
process was started, and client's address and port number.
242242
The columns that report data on the current query are available unless
243243
the parameter <varname>track_activities</varname> has been turned off.
244-
Furthermore, these columns and the application name are only visible if
245-
the user examining the view is a superuser or the same as the user
246-
owning the process being reported on.
244+
Furthermore, these columns are only visible if the user examining
245+
the view is a superuser or the same as the user owning the process
246+
being reported on.
247247
</entry>
248248
</row>
249249

src/backend/catalog/system_views.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 1996-2009, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.62 2009/11/28 23:38:07 tgl Exp $
6+
* $PostgreSQL: pgsql/src/backend/catalog/system_views.sql,v 1.63 2009/11/29 18:14:30 tgl Exp $
77
*/
88

99
CREATE VIEW pg_roles AS
@@ -333,14 +333,14 @@ CREATE VIEW pg_stat_activity AS
333333
S.procpid,
334334
S.usesysid,
335335
U.rolname AS usename,
336+
S.application_name,
336337
S.current_query,
337338
S.waiting,
338339
S.xact_start,
339340
S.query_start,
340341
S.backend_start,
341342
S.client_addr,
342-
S.client_port,
343-
S.application_name
343+
S.client_port
344344
FROM pg_database D, pg_stat_get_activity(NULL) AS S, pg_authid U
345345
WHERE S.datid = D.oid AND
346346
S.usesysid = U.oid;

src/backend/utils/adt/pgstatfuncs.c

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.55 2009/11/28 23:38:07 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/pgstatfuncs.c,v 1.56 2009/11/29 18:14:30 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -420,14 +420,14 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
420420
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "datid", OIDOID, -1, 0);
421421
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "procpid", INT4OID, -1, 0);
422422
TupleDescInitEntry(tupdesc, (AttrNumber) 3, "usesysid", OIDOID, -1, 0);
423-
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "current_query", TEXTOID, -1, 0);
424-
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "waiting", BOOLOID, -1, 0);
425-
TupleDescInitEntry(tupdesc, (AttrNumber) 6, "act_start", TIMESTAMPTZOID, -1, 0);
426-
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "query_start", TIMESTAMPTZOID, -1, 0);
427-
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "backend_start", TIMESTAMPTZOID, -1, 0);
428-
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "client_addr", INETOID, -1, 0);
429-
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "client_port", INT4OID, -1, 0);
430-
TupleDescInitEntry(tupdesc, (AttrNumber) 11, "application_name", TEXTOID, -1, 0);
423+
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "application_name", TEXTOID, -1, 0);
424+
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "current_query", TEXTOID, -1, 0);
425+
TupleDescInitEntry(tupdesc, (AttrNumber) 6, "waiting", BOOLOID, -1, 0);
426+
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "act_start", TIMESTAMPTZOID, -1, 0);
427+
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "query_start", TIMESTAMPTZOID, -1, 0);
428+
TupleDescInitEntry(tupdesc, (AttrNumber) 9, "backend_start", TIMESTAMPTZOID, -1, 0);
429+
TupleDescInitEntry(tupdesc, (AttrNumber) 10, "client_addr", INETOID, -1, 0);
430+
TupleDescInitEntry(tupdesc, (AttrNumber) 11, "client_port", INT4OID, -1, 0);
431431

432432
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
433433

@@ -489,20 +489,24 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
489489
MemSet(nulls, 0, sizeof(nulls));
490490

491491
if (*(int *) (funcctx->user_fctx) > 0)
492+
{
492493
/* Get specific pid slot */
493494
beentry = pgstat_fetch_stat_beentry(*(int *) (funcctx->user_fctx));
495+
}
494496
else
497+
{
495498
/* Get the next one in the list */
496499
beentry = pgstat_fetch_stat_beentry(funcctx->call_cntr + 1); /* 1-based index */
500+
}
497501
if (!beentry)
498502
{
499503
int i;
500504

501505
for (i = 0; i < sizeof(nulls) / sizeof(nulls[0]); i++)
502506
nulls[i] = true;
503507

504-
nulls[3] = false;
505-
values[3] = CStringGetTextDatum("<backend information not available>");
508+
nulls[4] = false;
509+
values[4] = CStringGetTextDatum("<backend information not available>");
506510

507511
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
508512
SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
@@ -512,43 +516,47 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
512516
values[0] = ObjectIdGetDatum(beentry->st_databaseid);
513517
values[1] = Int32GetDatum(beentry->st_procpid);
514518
values[2] = ObjectIdGetDatum(beentry->st_userid);
519+
if (beentry->st_appname)
520+
values[3] = CStringGetTextDatum(beentry->st_appname);
521+
else
522+
nulls[3] = true;
515523

516524
/* Values only available to same user or superuser */
517525
if (superuser() || beentry->st_userid == GetUserId())
518526
{
519527
if (*(beentry->st_activity) == '\0')
520528
{
521-
values[3] = CStringGetTextDatum("<command string not enabled>");
529+
values[4] = CStringGetTextDatum("<command string not enabled>");
522530
}
523531
else
524532
{
525-
values[3] = CStringGetTextDatum(beentry->st_activity);
533+
values[4] = CStringGetTextDatum(beentry->st_activity);
526534
}
527535

528-
values[4] = BoolGetDatum(beentry->st_waiting);
536+
values[5] = BoolGetDatum(beentry->st_waiting);
529537

530538
if (beentry->st_xact_start_timestamp != 0)
531-
values[5] = TimestampTzGetDatum(beentry->st_xact_start_timestamp);
539+
values[6] = TimestampTzGetDatum(beentry->st_xact_start_timestamp);
532540
else
533-
nulls[5] = true;
541+
nulls[6] = true;
534542

535543
if (beentry->st_activity_start_timestamp != 0)
536-
values[6] = TimestampTzGetDatum(beentry->st_activity_start_timestamp);
544+
values[7] = TimestampTzGetDatum(beentry->st_activity_start_timestamp);
537545
else
538-
nulls[6] = true;
546+
nulls[7] = true;
539547

540548
if (beentry->st_proc_start_timestamp != 0)
541-
values[7] = TimestampTzGetDatum(beentry->st_proc_start_timestamp);
549+
values[8] = TimestampTzGetDatum(beentry->st_proc_start_timestamp);
542550
else
543-
nulls[7] = true;
551+
nulls[8] = true;
544552

545553
/* A zeroed client addr means we don't know */
546554
memset(&zero_clientaddr, 0, sizeof(zero_clientaddr));
547555
if (memcmp(&(beentry->st_clientaddr), &zero_clientaddr,
548556
sizeof(zero_clientaddr) == 0))
549557
{
550-
nulls[8] = true;
551558
nulls[9] = true;
559+
nulls[10] = true;
552560
}
553561
else
554562
{
@@ -571,15 +579,15 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
571579
NI_NUMERICHOST | NI_NUMERICSERV);
572580
if (ret)
573581
{
574-
nulls[8] = true;
575582
nulls[9] = true;
583+
nulls[10] = true;
576584
}
577585
else
578586
{
579587
clean_ipv6_addr(beentry->st_clientaddr.addr.ss_family, remote_host);
580-
values[8] = DirectFunctionCall1(inet_in,
588+
values[9] = DirectFunctionCall1(inet_in,
581589
CStringGetDatum(remote_host));
582-
values[9] = Int32GetDatum(atoi(remote_port));
590+
values[10] = Int32GetDatum(atoi(remote_port));
583591
}
584592
}
585593
else if (beentry->st_clientaddr.addr.ss_family == AF_UNIX)
@@ -590,28 +598,21 @@ pg_stat_get_activity(PG_FUNCTION_ARGS)
590598
* connections we have no permissions to view, or with
591599
* errors.
592600
*/
593-
nulls[8] = true;
594-
values[9] = DatumGetInt32(-1);
601+
nulls[9] = true;
602+
values[10] = DatumGetInt32(-1);
595603
}
596604
else
597605
{
598606
/* Unknown address type, should never happen */
599-
nulls[8] = true;
600607
nulls[9] = true;
608+
nulls[10] = true;
601609
}
602610
}
603-
604-
/* application name */
605-
if (beentry->st_appname)
606-
values[10] = CStringGetTextDatum(beentry->st_appname);
607-
else
608-
nulls[10] = true;
609611
}
610612
else
611613
{
612614
/* No permissions to view data about this session */
613-
values[3] = CStringGetTextDatum("<insufficient privilege>");
614-
nulls[4] = true;
615+
values[4] = CStringGetTextDatum("<insufficient privilege>");
615616
nulls[5] = true;
616617
nulls[6] = true;
617618
nulls[7] = true;

src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.553 2009/11/29 03:02:27 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.554 2009/11/29 18:14:30 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/* yyyymmddN */
56-
#define CATALOG_VERSION_NO 200911282
56+
#define CATALOG_VERSION_NO 200911291
5757

5858
#endif

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-2009, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.553 2009/11/28 23:38:07 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.554 2009/11/29 18:14:30 tgl Exp $
1111
*
1212
* NOTES
1313
* The script catalog/genbki.sh reads this file and generates .bki
@@ -2999,7 +2999,7 @@ DATA(insert OID = 2784 ( pg_stat_get_last_autoanalyze_time PGNSP PGUID 12 1 0 0
29992999
DESCR("statistics: last auto analyze time for a table");
30003000
DATA(insert OID = 1936 ( pg_stat_get_backend_idset PGNSP PGUID 12 1 100 0 f f f t t s 0 0 23 "" _null_ _null_ _null_ _null_ pg_stat_get_backend_idset _null_ _null_ _null_ ));
30013001
DESCR("statistics: currently active backend IDs");
3002-
DATA(insert OID = 2022 ( pg_stat_get_activity PGNSP PGUID 12 1 100 0 f f f f t s 1 0 2249 "23" "{23,26,23,26,25,16,1184,1184,1184,869,23,25}" "{i,o,o,o,o,o,o,o,o,o,o,o}" "{pid,datid,procpid,usesysid,current_query,waiting,xact_start,query_start,backend_start,client_addr,client_port,application_name}" _null_ pg_stat_get_activity _null_ _null_ _null_ ));
3002+
DATA(insert OID = 2022 ( pg_stat_get_activity PGNSP PGUID 12 1 100 0 f f f f t s 1 0 2249 "23" "{23,26,23,26,25,25,16,1184,1184,1184,869,23}" "{i,o,o,o,o,o,o,o,o,o,o,o}" "{pid,datid,procpid,usesysid,application_name,current_query,waiting,xact_start,query_start,backend_start,client_addr,client_port}" _null_ pg_stat_get_activity _null_ _null_ _null_ ));
30033003
DESCR("statistics: information about currently active backends");
30043004
DATA(insert OID = 2026 ( pg_backend_pid PGNSP PGUID 12 1 0 0 f f f t f s 0 0 23 "" _null_ _null_ _null_ _null_ pg_backend_pid _null_ _null_ _null_ ));
30053005
DESCR("statistics: current backend PID");

src/test/regress/expected/rules.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ SELECT viewname, definition FROM pg_views WHERE schemaname <> 'information_schem
12891289
pg_rules | SELECT n.nspname AS schemaname, c.relname AS tablename, r.rulename, pg_get_ruledef(r.oid) AS definition FROM ((pg_rewrite r JOIN pg_class c ON ((c.oid = r.ev_class))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (r.rulename <> '_RETURN'::name);
12901290
pg_settings | SELECT a.name, a.setting, a.unit, a.category, a.short_desc, a.extra_desc, a.context, a.vartype, a.source, a.min_val, a.max_val, a.enumvals, a.boot_val, a.reset_val, a.sourcefile, a.sourceline FROM pg_show_all_settings() a(name, setting, unit, category, short_desc, extra_desc, context, vartype, source, min_val, max_val, enumvals, boot_val, reset_val, sourcefile, sourceline);
12911291
pg_shadow | SELECT pg_authid.rolname AS usename, pg_authid.oid AS usesysid, pg_authid.rolcreatedb AS usecreatedb, pg_authid.rolsuper AS usesuper, pg_authid.rolcatupdate AS usecatupd, pg_authid.rolpassword AS passwd, (pg_authid.rolvaliduntil)::abstime AS valuntil, s.setconfig AS useconfig FROM (pg_authid LEFT JOIN pg_db_role_setting s ON (((pg_authid.oid = s.setrole) AND (s.setdatabase = (0)::oid)))) WHERE pg_authid.rolcanlogin;
1292-
pg_stat_activity | SELECT s.datid, d.datname, s.procpid, s.usesysid, u.rolname AS usename, s.current_query, s.waiting, s.xact_start, s.query_start, s.backend_start, s.client_addr, s.client_port, s.application_name FROM pg_database d, pg_stat_get_activity(NULL::integer) s(datid, procpid, usesysid, current_query, waiting, xact_start, query_start, backend_start, client_addr, client_port, application_name), pg_authid u WHERE ((s.datid = d.oid) AND (s.usesysid = u.oid));
1292+
pg_stat_activity | SELECT s.datid, d.datname, s.procpid, s.usesysid, u.rolname AS usename, s.application_name, s.current_query, s.waiting, s.xact_start, s.query_start, s.backend_start, s.client_addr, s.client_port FROM pg_database d, pg_stat_get_activity(NULL::integer) s(datid, procpid, usesysid, application_name, current_query, waiting, xact_start, query_start, backend_start, client_addr, client_port), pg_authid u WHERE ((s.datid = d.oid) AND (s.usesysid = u.oid));
12931293
pg_stat_all_indexes | SELECT c.oid AS relid, i.oid AS indexrelid, n.nspname AS schemaname, c.relname, i.relname AS indexrelname, pg_stat_get_numscans(i.oid) AS idx_scan, pg_stat_get_tuples_returned(i.oid) AS idx_tup_read, pg_stat_get_tuples_fetched(i.oid) AS idx_tup_fetch FROM (((pg_class c JOIN pg_index x ON ((c.oid = x.indrelid))) JOIN pg_class i ON ((i.oid = x.indexrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char"]));
12941294
pg_stat_all_tables | SELECT c.oid AS relid, n.nspname AS schemaname, c.relname, pg_stat_get_numscans(c.oid) AS seq_scan, pg_stat_get_tuples_returned(c.oid) AS seq_tup_read, (sum(pg_stat_get_numscans(i.indexrelid)))::bigint AS idx_scan, ((sum(pg_stat_get_tuples_fetched(i.indexrelid)))::bigint + pg_stat_get_tuples_fetched(c.oid)) AS idx_tup_fetch, pg_stat_get_tuples_inserted(c.oid) AS n_tup_ins, pg_stat_get_tuples_updated(c.oid) AS n_tup_upd, pg_stat_get_tuples_deleted(c.oid) AS n_tup_del, pg_stat_get_tuples_hot_updated(c.oid) AS n_tup_hot_upd, pg_stat_get_live_tuples(c.oid) AS n_live_tup, pg_stat_get_dead_tuples(c.oid) AS n_dead_tup, pg_stat_get_last_vacuum_time(c.oid) AS last_vacuum, pg_stat_get_last_autovacuum_time(c.oid) AS last_autovacuum, pg_stat_get_last_analyze_time(c.oid) AS last_analyze, pg_stat_get_last_autoanalyze_time(c.oid) AS last_autoanalyze FROM ((pg_class c LEFT JOIN pg_index i ON ((c.oid = i.indrelid))) LEFT JOIN pg_namespace n ON ((n.oid = c.relnamespace))) WHERE (c.relkind = ANY (ARRAY['r'::"char", 't'::"char"])) GROUP BY c.oid, n.nspname, c.relname;
12951295
pg_stat_bgwriter | SELECT pg_stat_get_bgwriter_timed_checkpoints() AS checkpoints_timed, pg_stat_get_bgwriter_requested_checkpoints() AS checkpoints_req, pg_stat_get_bgwriter_buf_written_checkpoints() AS buffers_checkpoint, pg_stat_get_bgwriter_buf_written_clean() AS buffers_clean, pg_stat_get_bgwriter_maxwritten_clean() AS maxwritten_clean, pg_stat_get_buf_written_backend() AS buffers_backend, pg_stat_get_buf_alloc() AS buffers_alloc;

0 commit comments

Comments
 (0)