Skip to content

Commit e7f58a4

Browse files
committed
Reduce cardinality of pg_stat_statements
Make the example queries.yaml `pg_stat_statements` query safer. * Select the top 10% of queries by total query time. * Only expose the top 100 queries by total query time. * Keep only the most useful metrics. * Comment out the example by default. Fixes: #549 Signed-off-by: SuperQ <[email protected]>
1 parent d273f97 commit e7f58a4

File tree

1 file changed

+52
-71
lines changed

1 file changed

+52
-71
lines changed

Diff for: queries.yaml

+52-71
Original file line numberDiff line numberDiff line change
@@ -146,77 +146,58 @@ pg_statio_user_tables:
146146
usage: "COUNTER"
147147
description: "Number of buffer hits in this table's TOAST table indexes (if any)"
148148

149-
# WARNING: This set of metrics can be very expensive on a busy server as every unique query executed will create an additional time series
150-
pg_stat_statements:
151-
query: "SELECT t2.rolname, t3.datname, queryid, calls, total_time / 1000 as total_time_seconds, min_time / 1000 as min_time_seconds, max_time / 1000 as max_time_seconds, mean_time / 1000 as mean_time_seconds, stddev_time / 1000 as stddev_time_seconds, rows, shared_blks_hit, shared_blks_read, shared_blks_dirtied, shared_blks_written, local_blks_hit, local_blks_read, local_blks_dirtied, local_blks_written, temp_blks_read, temp_blks_written, blk_read_time / 1000 as blk_read_time_seconds, blk_write_time / 1000 as blk_write_time_seconds FROM pg_stat_statements t1 JOIN pg_roles t2 ON (t1.userid=t2.oid) JOIN pg_database t3 ON (t1.dbid=t3.oid) WHERE t2.rolname != 'rdsadmin'"
152-
master: true
153-
metrics:
154-
- rolname:
155-
usage: "LABEL"
156-
description: "Name of user"
157-
- datname:
158-
usage: "LABEL"
159-
description: "Name of database"
160-
- queryid:
161-
usage: "LABEL"
162-
description: "Query ID"
163-
- calls:
164-
usage: "COUNTER"
165-
description: "Number of times executed"
166-
- total_time_seconds:
167-
usage: "COUNTER"
168-
description: "Total time spent in the statement, in milliseconds"
169-
- min_time_seconds:
170-
usage: "GAUGE"
171-
description: "Minimum time spent in the statement, in milliseconds"
172-
- max_time_seconds:
173-
usage: "GAUGE"
174-
description: "Maximum time spent in the statement, in milliseconds"
175-
- mean_time_seconds:
176-
usage: "GAUGE"
177-
description: "Mean time spent in the statement, in milliseconds"
178-
- stddev_time_seconds:
179-
usage: "GAUGE"
180-
description: "Population standard deviation of time spent in the statement, in milliseconds"
181-
- rows:
182-
usage: "COUNTER"
183-
description: "Total number of rows retrieved or affected by the statement"
184-
- shared_blks_hit:
185-
usage: "COUNTER"
186-
description: "Total number of shared block cache hits by the statement"
187-
- shared_blks_read:
188-
usage: "COUNTER"
189-
description: "Total number of shared blocks read by the statement"
190-
- shared_blks_dirtied:
191-
usage: "COUNTER"
192-
description: "Total number of shared blocks dirtied by the statement"
193-
- shared_blks_written:
194-
usage: "COUNTER"
195-
description: "Total number of shared blocks written by the statement"
196-
- local_blks_hit:
197-
usage: "COUNTER"
198-
description: "Total number of local block cache hits by the statement"
199-
- local_blks_read:
200-
usage: "COUNTER"
201-
description: "Total number of local blocks read by the statement"
202-
- local_blks_dirtied:
203-
usage: "COUNTER"
204-
description: "Total number of local blocks dirtied by the statement"
205-
- local_blks_written:
206-
usage: "COUNTER"
207-
description: "Total number of local blocks written by the statement"
208-
- temp_blks_read:
209-
usage: "COUNTER"
210-
description: "Total number of temp blocks read by the statement"
211-
- temp_blks_written:
212-
usage: "COUNTER"
213-
description: "Total number of temp blocks written by the statement"
214-
- blk_read_time_seconds:
215-
usage: "COUNTER"
216-
description: "Total time the statement spent reading blocks, in milliseconds (if track_io_timing is enabled, otherwise zero)"
217-
- blk_write_time_seconds:
218-
usage: "COUNTER"
219-
description: "Total time the statement spent writing blocks, in milliseconds (if track_io_timing is enabled, otherwise zero)"
149+
#
150+
# WARNING:
151+
# This set of metrics can be very expensive on a busy server as every
152+
# unique query executed will create an additional time series
153+
#
154+
# pg_stat_statements:
155+
# query: |
156+
# SELECT
157+
# pg_get_userbyid(userid) as user,
158+
# pg_database.datname,
159+
# pg_stat_statements.queryid,
160+
# pg_stat_statements.calls as calls_total,
161+
# pg_stat_statements.total_time / 1000.0 as seconds_total,
162+
# pg_stat_statements.rows as rows_total,
163+
# pg_stat_statements.blk_read_time / 1000.0 as block_read_seconds_total,
164+
# pg_stat_statements.blk_write_time / 1000.0 as block_write_seconds_total
165+
# FROM pg_stat_statements
166+
# JOIN pg_database
167+
# ON pg_database.oid = pg_stat_statements.dbid
168+
# WHERE
169+
# total_time > (
170+
# SELECT percentile_cont(0.1)
171+
# WITHIN GROUP (ORDER BY total_time)
172+
# FROM pg_stat_statements
173+
# )
174+
# ORDER BY seconds_total DESC
175+
# LIMIT 100
176+
# metrics:
177+
# - user:
178+
# usage: "LABEL"
179+
# description: "The user who executed the statement"
180+
# - datname:
181+
# usage: "LABEL"
182+
# description: "The database in which the statement was executed"
183+
# - queryid:
184+
# usage: "LABEL"
185+
# description: "Internal hash code, computed from the statement's parse tree"
186+
# - calls_total:
187+
# usage: "COUNTER"
188+
# description: "Number of times executed"
189+
# - seconds_total:
190+
# usage: "COUNTER"
191+
# description: "Total time spent in the statement, in seconds"
192+
# - rows_total:
193+
# usage: "COUNTER"
194+
# description: "Total number of rows retrieved or affected by the statement"
195+
# - block_read_seconds_total:
196+
# usage: "COUNTER"
197+
# description: "Total time the statement spent reading blocks, in seconds"
198+
# - block_write_seconds_total:
199+
# usage: "COUNTER"
200+
# description: "Total time the statement spent writing blocks, in seconds"
220201

221202
pg_process_idle:
222203
query: |

0 commit comments

Comments
 (0)