-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathqueries_pg_stat_statements.yml
More file actions
170 lines (160 loc) · 5.49 KB
/
Copy pathqueries_pg_stat_statements.yml
File metadata and controls
170 lines (160 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
###
#
# Begin File: PG17 queries_pg_stat_statements.yml
#
# Copyright © 2017-2025 Crunchy Data Solutions, Inc. All Rights Reserved.
# Copyright © 2025-2026 Snowflake, Inc. All Rights Reserved.
#
###
ccp_pg_stat_statements_total:
query: "SELECT pg_get_userbyid(s.userid) as role,
d.datname AS dbname,
sum(s.calls) AS calls_count,
sum(s.total_exec_time) AS exec_time_ms,
avg(s.mean_exec_time) AS mean_exec_time_ms,
sum(s.rows) AS row_count
FROM public.pg_stat_statements s
JOIN pg_catalog.pg_database d
ON d.oid = s.dbid
GROUP BY 1,2"
metrics:
- role:
usage: "LABEL"
description: "Role that executed the statement"
- dbname:
usage: "LABEL"
description: "Database in which the statement was executed"
- calls_count:
usage: "GAUGE"
description: "Total number of queries run per user/database"
- exec_time_ms:
usage: "GAUGE"
description: "Total runtime of all queries per user/database"
- mean_exec_time_ms:
usage: "GAUGE"
description: "Mean runtime of all queries per user/database"
- row_count:
usage: "GAUGE"
description: "Total rows returned from all queries per user/database"
ccp_pg_stat_statements_top_mean:
query: "SELECT pg_get_userbyid(s.userid) as role,
d.datname AS dbname,
s.queryid,
btrim(replace(left(s.query, 40), '\n', '')) AS query,
max(s.mean_exec_time) exec_time_ms
FROM public.pg_stat_statements s
JOIN pg_catalog.pg_database d
ON d.oid = s.dbid
GROUP BY 1,2,3,4
ORDER BY 5 DESC
LIMIT #PG_STAT_STATEMENTS_LIMIT#"
metrics:
- role:
usage: "LABEL"
description: "Role that executed the statement"
- dbname:
usage: "LABEL"
description: "Database in which the statement was executed"
- queryid:
usage: "LABEL"
description: "Internal hash code, computed from the statement's parse tree"
- query:
usage: "LABEL"
description: "First 40 characters of query text"
- exec_time_ms:
usage: "GAUGE"
description: "Average query runtime in milliseconds"
ccp_pg_stat_statements_top_total:
query: "SELECT pg_get_userbyid(s.userid) as role,
d.datname AS dbname,
s.queryid,
btrim(replace(left(s.query, 40), '\n', '')) AS query,
s.total_exec_time exec_time_ms
FROM public.pg_stat_statements s
JOIN pg_catalog.pg_database d
ON d.oid = s.dbid
ORDER BY 5 DESC
LIMIT #PG_STAT_STATEMENTS_LIMIT#"
metrics:
- role:
usage: "LABEL"
description: "Role that executed the statement"
- dbname:
usage: "LABEL"
description: "Database in which the statement was executed"
- queryid:
usage: "LABEL"
description: "Internal hash code, computed from the statement's parse tree"
- query:
usage: "LABEL"
description: "First 40 characters of query text"
- exec_time_ms:
usage: "GAUGE"
description: "Total time spent in the statement in milliseconds"
ccp_pg_stat_statements_top_max:
query: "SELECT pg_get_userbyid(s.userid) as role,
d.datname AS dbname,
s.queryid,
btrim(replace(left(s.query, 40), '\n', '')) AS query,
s.max_exec_time AS exec_time_ms
FROM public.pg_stat_statements s
JOIN pg_catalog.pg_database d
ON d.oid = s.dbid
ORDER BY 5 DESC
LIMIT #PG_STAT_STATEMENTS_LIMIT#"
metrics:
- role:
usage: "LABEL"
description: "Role that executed the statement"
- dbname:
usage: "LABEL"
description: "Database in which the statement was executed"
- queryid:
usage: "LABEL"
description: "Internal hash code, computed from the statement's parse tree"
- query:
usage: "LABEL"
description: "First 40 characters of query text"
- exec_time_ms:
usage: "GAUGE"
description: "Maximum time spent in the statement in milliseconds"
ccp_pg_stat_statements_top_wal:
query: "SELECT pg_get_userbyid(s.userid) as role,
d.datname AS dbname,
s.queryid,
btrim(replace(left(s.query, 40), '\n', '')) AS query,
s.wal_records AS records,
s.wal_fpi AS fpi,
s.wal_bytes AS bytes
FROM public.pg_stat_statements s
JOIN pg_catalog.pg_database d
ON d.oid = s.dbid
ORDER BY s.wal_bytes DESC
LIMIT #PG_STAT_STATEMENTS_LIMIT#"
metrics:
- role:
usage: "LABEL"
description: "Role that executed the statement"
- dbname:
usage: "LABEL"
description: "Database in which the statement was executed"
- queryid:
usage: "LABEL"
description: "Internal hash code, computed from the statement's parse tree"
- query:
usage: "LABEL"
description: "First 40 characters of query text"
- records:
usage: "GAUGE"
description: "Total number of WAL records generated by the statement"
- fpi:
usage: "GAUGE"
description: "Total number of WAL full page images generated by the statement"
- bytes:
usage: "GAUGE"
description: "Total amount of WAL generated by the statement in bytes"
###
#
# End File: PG17 queries_pg_stat_statements.yml
#
###