Skip to content

Commit 12946dc

Browse files
author
dmitry
committed
add fields isregularbackend, databaseid, roleid to _current and _history views
1 parent 3c1046c commit 12946dc

File tree

6 files changed

+177
-7
lines changed

6 files changed

+177
-7
lines changed

collector.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ probe_waits(History *observations, HTAB *profile_hash,
175175
item.queryId = 0;
176176

177177
item.ts = ts;
178+
item.isRegularBackend = !(proc->isBackgroundWorker);
179+
item.databaseId = proc->databaseId;
180+
item.roleId = proc->roleId;
178181

179182
/* Write to the history if needed */
180183
if (write_history)

pg_wait_sampling--1.1--1.2.sql

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/* contrib/pg_wait_sampling/pg_wait_sampling--1.0--1.1.sql */
2+
3+
DROP FUNCTION pg_wait_sampling_get_current (
4+
pid int4,
5+
OUT pid int4,
6+
OUT event_type text,
7+
OUT event text
8+
) CASCADE;
9+
10+
DROP FUNCTION pg_wait_sampling_get_history (
11+
OUT pid int4,
12+
OUT ts timestamptz,
13+
OUT event_type text,
14+
OUT event text
15+
) CASCADE;
16+
17+
DROP FUNCTION pg_wait_sampling_get_profile (
18+
OUT pid int4,
19+
OUT event_type text,
20+
OUT event text,
21+
OUT count bigint
22+
) CASCADE;
23+
24+
CREATE FUNCTION pg_wait_sampling_get_current (
25+
pid int4,
26+
OUT pid int4,
27+
OUT event_type text,
28+
OUT event text,
29+
OUT queryid int8,
30+
OUT isregularbackend boolean,
31+
OUT databaseid oid,
32+
OUT roleid oid
33+
)
34+
RETURNS SETOF record
35+
AS 'MODULE_PATHNAME'
36+
LANGUAGE C VOLATILE CALLED ON NULL INPUT;
37+
38+
CREATE VIEW pg_wait_sampling_current AS
39+
SELECT * FROM pg_wait_sampling_get_current(NULL::integer);
40+
41+
GRANT SELECT ON pg_wait_sampling_current TO PUBLIC;
42+
43+
CREATE FUNCTION pg_wait_sampling_get_history (
44+
OUT pid int4,
45+
OUT ts timestamptz,
46+
OUT event_type text,
47+
OUT event text,
48+
OUT queryid int8
49+
)
50+
RETURNS SETOF record
51+
AS 'MODULE_PATHNAME'
52+
LANGUAGE C VOLATILE STRICT;
53+
54+
CREATE VIEW pg_wait_sampling_history AS
55+
SELECT * FROM pg_wait_sampling_get_history();
56+
57+
GRANT SELECT ON pg_wait_sampling_history TO PUBLIC;
58+
59+
CREATE FUNCTION pg_wait_sampling_get_profile (
60+
OUT pid int4,
61+
OUT event_type text,
62+
OUT event text,
63+
OUT queryid int8,
64+
OUT count int8
65+
)
66+
RETURNS SETOF record
67+
AS 'MODULE_PATHNAME'
68+
LANGUAGE C VOLATILE STRICT;
69+
70+
CREATE VIEW pg_wait_sampling_profile AS
71+
SELECT * FROM pg_wait_sampling_get_profile();
72+
73+
GRANT SELECT ON pg_wait_sampling_profile TO PUBLIC;

pg_wait_sampling--1.2.sql

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* contrib/pg_wait_sampling/setup.sql */
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use "CREATE EXTENSION pg_wait_sampling" to load this file. \quit
5+
6+
CREATE FUNCTION pg_wait_sampling_get_current (
7+
pid int4,
8+
OUT pid int4,
9+
OUT event_type text,
10+
OUT event text,
11+
OUT queryid int8,
12+
OUT isregularbackend boolean,
13+
OUT databaseid oid,
14+
OUT roleid oid
15+
)
16+
RETURNS SETOF record
17+
AS 'MODULE_PATHNAME'
18+
LANGUAGE C VOLATILE CALLED ON NULL INPUT;
19+
20+
CREATE VIEW pg_wait_sampling_current AS
21+
SELECT * FROM pg_wait_sampling_get_current(NULL::integer);
22+
23+
GRANT SELECT ON pg_wait_sampling_current TO PUBLIC;
24+
25+
CREATE FUNCTION pg_wait_sampling_get_history (
26+
OUT pid int4,
27+
OUT ts timestamptz,
28+
OUT event_type text,
29+
OUT event text,
30+
OUT queryid int8,
31+
OUT isregularbackend boolean,
32+
OUT databaseid oid,
33+
OUT roleid oid
34+
)
35+
RETURNS SETOF record
36+
AS 'MODULE_PATHNAME'
37+
LANGUAGE C VOLATILE STRICT;
38+
39+
CREATE VIEW pg_wait_sampling_history AS
40+
SELECT * FROM pg_wait_sampling_get_history();
41+
42+
GRANT SELECT ON pg_wait_sampling_history TO PUBLIC;
43+
44+
CREATE FUNCTION pg_wait_sampling_get_profile (
45+
OUT pid int4,
46+
OUT event_type text,
47+
OUT event text,
48+
OUT queryid int8,
49+
OUT count int8
50+
)
51+
RETURNS SETOF record
52+
AS 'MODULE_PATHNAME'
53+
LANGUAGE C VOLATILE STRICT;
54+
55+
CREATE VIEW pg_wait_sampling_profile AS
56+
SELECT * FROM pg_wait_sampling_get_profile();
57+
58+
GRANT SELECT ON pg_wait_sampling_profile TO PUBLIC;
59+
60+
CREATE FUNCTION pg_wait_sampling_reset_profile()
61+
RETURNS void
62+
AS 'MODULE_PATHNAME'
63+
LANGUAGE C VOLATILE STRICT;
64+
65+
-- Don't want this to be available to non-superusers.
66+
REVOKE ALL ON FUNCTION pg_wait_sampling_reset_profile() FROM PUBLIC;

pg_wait_sampling.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
514514
params->ts = GetCurrentTimestamp();
515515

516516
funcctx->user_fctx = params;
517-
tupdesc = CreateTemplateTupleDesc(4);
517+
tupdesc = CreateTemplateTupleDesc(7);
518518
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "pid",
519519
INT4OID, -1, 0);
520520
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "type",
@@ -523,6 +523,12 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
523523
TEXTOID, -1, 0);
524524
TupleDescInitEntry(tupdesc, (AttrNumber) 4, "queryid",
525525
INT8OID, -1, 0);
526+
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "isregularbackend",
527+
BOOLOID, -1, 0);
528+
TupleDescInitEntry(tupdesc, (AttrNumber) 6, "databaseid",
529+
OIDOID, -1, 0);
530+
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "roleid",
531+
OIDOID, -1, 0);
526532

527533
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
528534

@@ -540,6 +546,9 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
540546
item->pid = proc->pid;
541547
item->wait_event_info = proc->wait_event_info;
542548
item->queryId = pgws_proc_queryids[proc - ProcGlobal->allProcs];
549+
item->isRegularBackend = !(proc->isBackgroundWorker);
550+
item->databaseId = proc->databaseId;
551+
item->roleId = proc->roleId;
543552
funcctx->max_calls = 1;
544553
}
545554
else
@@ -562,6 +571,9 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
562571
params->items[j].pid = proc->pid;
563572
params->items[j].wait_event_info = proc->wait_event_info;
564573
params->items[j].queryId = pgws_proc_queryids[i];
574+
params->items[j].isRegularBackend = !(proc->isBackgroundWorker);
575+
params->items[j].databaseId = proc->databaseId;
576+
params->items[j].roleId = proc->roleId;
565577
j++;
566578
}
567579
funcctx->max_calls = j;
@@ -579,8 +591,8 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
579591
if (funcctx->call_cntr < funcctx->max_calls)
580592
{
581593
HeapTuple tuple;
582-
Datum values[4];
583-
bool nulls[4];
594+
Datum values[7];
595+
bool nulls[7];
584596
const char *event_type,
585597
*event;
586598
HistoryItem *item;
@@ -604,6 +616,9 @@ pg_wait_sampling_get_current(PG_FUNCTION_ARGS)
604616
nulls[2] = true;
605617

606618
values[3] = UInt64GetDatum(item->queryId);
619+
values[4] = BoolGetDatum(item->isRegularBackend);
620+
values[5] = ObjectIdGetDatum(item->databaseId);
621+
values[6] = ObjectIdGetDatum(item->roleId);
607622
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
608623

609624
SRF_RETURN_NEXT(funcctx, HeapTupleGetDatum(tuple));
@@ -858,7 +873,7 @@ pg_wait_sampling_get_history(PG_FUNCTION_ARGS)
858873
funcctx->max_calls = history->count;
859874

860875
/* Make tuple descriptor */
861-
tupdesc = CreateTemplateTupleDesc(5);
876+
tupdesc = CreateTemplateTupleDesc(8);
862877
TupleDescInitEntry(tupdesc, (AttrNumber) 1, "pid",
863878
INT4OID, -1, 0);
864879
TupleDescInitEntry(tupdesc, (AttrNumber) 2, "sample_ts",
@@ -869,6 +884,13 @@ pg_wait_sampling_get_history(PG_FUNCTION_ARGS)
869884
TEXTOID, -1, 0);
870885
TupleDescInitEntry(tupdesc, (AttrNumber) 5, "queryid",
871886
INT8OID, -1, 0);
887+
TupleDescInitEntry(tupdesc, (AttrNumber) 6, "isregularbackend",
888+
BOOLOID, -1, 0),
889+
TupleDescInitEntry(tupdesc, (AttrNumber) 7, "databaseid",
890+
OIDOID, -1, 0),
891+
TupleDescInitEntry(tupdesc, (AttrNumber) 8, "roleid",
892+
OIDOID, -1, 0);
893+
872894
funcctx->tuple_desc = BlessTupleDesc(tupdesc);
873895

874896
MemoryContextSwitchTo(oldcontext);
@@ -883,8 +905,8 @@ pg_wait_sampling_get_history(PG_FUNCTION_ARGS)
883905
{
884906
HeapTuple tuple;
885907
HistoryItem *item;
886-
Datum values[5];
887-
bool nulls[5];
908+
Datum values[8];
909+
bool nulls[8];
888910
const char *event_type,
889911
*event;
890912

@@ -908,6 +930,9 @@ pg_wait_sampling_get_history(PG_FUNCTION_ARGS)
908930
nulls[3] = true;
909931

910932
values[4] = UInt64GetDatum(item->queryId);
933+
values[5] = BoolGetDatum(item->isRegularBackend);
934+
values[6] = ObjectIdGetDatum(item->databaseId);
935+
values[7] = ObjectIdGetDatum(item->roleId);
911936
tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
912937

913938
history->index++;

pg_wait_sampling.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pg_wait_sampling extension
22
comment = 'sampling based statistics of wait events'
3-
default_version = '1.1'
3+
default_version = '1.2'
44
module_pathname = '$libdir/pg_wait_sampling'
55
relocatable = true

pg_wait_sampling.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ typedef struct
3434
int pid;
3535
uint32 wait_event_info;
3636
uint64 queryId;
37+
bool isRegularBackend;
38+
Oid databaseId;
39+
Oid roleId;
3740
TimestampTz ts;
3841
} HistoryItem;
3942

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy