Skip to content

Commit 202c720

Browse files
committed
Add Top $n indexes by estimated bloat % panel to pg index overview dashboard
1 parent 52fbda0 commit 202c720

1 file changed

Lines changed: 252 additions & 11 deletions

File tree

grafana/postgres/v12/index-overview.json

Lines changed: 252 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@
189189
"orderByTime": "ASC",
190190
"policy": "default",
191191
"rawQuery": true,
192-
"rawSql": "WITH index_scan_changes AS (\n SELECT\n time,\n dbname,\n tag_data ->> 'index_full_name' AS index_full_name,\n tag_data ->> 'table_full_name' AS table_full_name,\n (data ->> 'idx_scan')::int8 - LEAD((data ->> 'idx_scan')::int8) OVER w AS idx_scans,\n (data ->> 'index_size_b')::int8 AS index_size_b,\n ROW_NUMBER() OVER w AS rn\n FROM\n index_stats\n WHERE\n dbname IN ($dbname)\n WINDOW w AS (\n PARTITION BY dbname,\n tag_data ->> 'table_full_name',\n tag_data ->> 'index_full_name'\n ORDER BY time DESC\n )\n),\ntotal_scans AS (\n SELECT\n dbname,\n table_full_name,\n index_full_name,\n SUM(COALESCE(idx_scans, 0)) AS total_idx_scans,\n MAX(index_size_b) FILTER (WHERE rn = 1) AS latest_index_size\n FROM\n index_scan_changes\n WHERE\n $__timeFilter(time)\n GROUP BY\n dbname, table_full_name, index_full_name\n)\nSELECT\n dbname AS \"Source Name\",\n index_full_name AS \"Index Name\",\n table_full_name AS \"Table Name\",\n latest_index_size AS \"Index Size\",\n total_idx_scans AS \"Scans\"\nFROM\n total_scans\nORDER BY\n latest_index_size DESC\nLIMIT $top",
192+
"rawSql": "WITH index_scan_changes AS (\n SELECT\n time,\n dbname,\n tag_data ->> 'index_full_name' AS index_full_name,\n tag_data ->> 'table_full_name' AS table_full_name,\n (data ->> 'idx_scan')::int8 - LEAD((data ->> 'idx_scan')::int8) OVER w AS idx_scans,\n (data ->> 'index_size_b')::int8 AS index_size_b,\n ROW_NUMBER() OVER w AS rn\n FROM\n index_stats\n WHERE\n dbname IN ($dbname)\n WINDOW w AS (\n PARTITION BY dbname,\n tag_data ->> 'table_full_name',\n tag_data ->> 'index_full_name'\n ORDER BY time DESC\n )\n),\ntotal_scans AS (\n SELECT\n dbname,\n table_full_name,\n index_full_name,\n SUM(COALESCE(idx_scans, 0)) AS total_idx_scans,\n MAX(index_size_b) FILTER (WHERE rn = 1) AS latest_index_size\n FROM\n index_scan_changes\n WHERE\n $__timeFilter(time)\n GROUP BY\n dbname, table_full_name, index_full_name\n)\nSELECT\n dbname AS \"Source Name\",\n table_full_name AS \"Table Name\",\n index_full_name AS \"Index Name\",\n latest_index_size AS \"Index Size\",\n total_idx_scans AS \"Scans\"\nFROM\n total_scans\nORDER BY\n latest_index_size DESC\nLIMIT $top",
193193
"refId": "A",
194194
"resultFormat": "table",
195195
"select": [
@@ -245,6 +245,247 @@
245245
],
246246
"type": "table"
247247
},
248+
{
249+
"datasource": {
250+
"type": "grafana-postgresql-datasource",
251+
"uid": "pgwatch-metrics"
252+
},
253+
"fieldConfig": {
254+
"defaults": {
255+
"color": {
256+
"mode": "thresholds"
257+
},
258+
"custom": {
259+
"align": "auto",
260+
"cellOptions": {
261+
"type": "auto"
262+
},
263+
"footer": {
264+
"reducers": []
265+
},
266+
"inspect": false
267+
},
268+
"decimals": 2,
269+
"displayName": "",
270+
"mappings": [],
271+
"thresholds": {
272+
"mode": "absolute",
273+
"steps": []
274+
},
275+
"unit": "short"
276+
},
277+
"overrides": [
278+
{
279+
"matcher": {
280+
"id": "byName",
281+
"options": "Table Name"
282+
},
283+
"properties": [
284+
{
285+
"id": "unit",
286+
"value": "short"
287+
},
288+
{
289+
"id": "decimals",
290+
"value": 2
291+
},
292+
{
293+
"id": "links",
294+
"value": [
295+
{
296+
"targetBlank": true,
297+
"title": "Opens 'Table details' dashboard",
298+
"url": "/d/table-details?var-dbname=${__data.fields[\"dbname\"]}&var-table_full_name=${__data.fields[\"table_full_name\"]}"
299+
}
300+
]
301+
},
302+
{
303+
"id": "custom.align",
304+
"value": "left"
305+
},
306+
{
307+
"id": "custom.width",
308+
"value": 265
309+
},
310+
{
311+
"id": "custom.inspect",
312+
"value": true
313+
}
314+
]
315+
},
316+
{
317+
"matcher": {
318+
"id": "byName",
319+
"options": "Index Size"
320+
},
321+
"properties": [
322+
{
323+
"id": "unit",
324+
"value": "bytes"
325+
},
326+
{
327+
"id": "decimals",
328+
"value": 1
329+
},
330+
{
331+
"id": "custom.align",
332+
"value": "left"
333+
},
334+
{
335+
"id": "custom.width",
336+
"value": 301
337+
}
338+
]
339+
},
340+
{
341+
"matcher": {
342+
"id": "byName",
343+
"options": "Index Name"
344+
},
345+
"properties": [
346+
{
347+
"id": "custom.width",
348+
"value": 306
349+
},
350+
{
351+
"id": "custom.inspect",
352+
"value": true
353+
}
354+
]
355+
},
356+
{
357+
"matcher": {
358+
"id": "byName",
359+
"options": "Source Name"
360+
},
361+
"properties": [
362+
{
363+
"id": "custom.width",
364+
"value": 186
365+
}
366+
]
367+
},
368+
{
369+
"matcher": {
370+
"id": "byName",
371+
"options": "Estimated Bloat size"
372+
},
373+
"properties": [
374+
{
375+
"id": "unit",
376+
"value": "bytes"
377+
}
378+
]
379+
},
380+
{
381+
"matcher": {
382+
"id": "byName",
383+
"options": "Estimated Bloat %"
384+
},
385+
"properties": [
386+
{
387+
"id": "unit",
388+
"value": "percent"
389+
}
390+
]
391+
}
392+
]
393+
},
394+
"gridPos": {
395+
"h": 8,
396+
"w": 24,
397+
"x": 0,
398+
"y": 8
399+
},
400+
"id": 17,
401+
"options": {
402+
"cellHeight": "sm",
403+
"showHeader": true,
404+
"sortBy": []
405+
},
406+
"pluginVersion": "12.3.1",
407+
"targets": [
408+
{
409+
"datasource": {
410+
"type": "grafana-postgresql-datasource",
411+
"uid": "pgwatch-metrics"
412+
},
413+
"format": "table",
414+
"group": [],
415+
"groupBy": [
416+
{
417+
"params": [
418+
"$__interval"
419+
],
420+
"type": "time"
421+
},
422+
{
423+
"params": [
424+
"null"
425+
],
426+
"type": "fill"
427+
}
428+
],
429+
"metricColumn": "none",
430+
"orderByTime": "ASC",
431+
"policy": "default",
432+
"rawQuery": true,
433+
"rawSql": "WITH last_fetch_time(time) AS (\n SELECT time\n FROM btree_bloat\n WHERE time <= $__timeTo()\n ORDER BY time DESC\n LIMIT 1\n)\n\nSELECT\n dbname AS \"Source Name\",\n tag_data->>'tblname' AS \"Table Name\",\n tag_data->>'idxname' AS \"Index Name\",\n data->>'real_size' AS \"Index Size\",\n data->>'bloat_pct' AS \"Estimated Bloat %\",\n data->>'bloat_size' AS \"Estimated Bloat size\"\nFROM\n btree_bloat\nWHERE time = (SELECT time FROM last_fetch_time)\nORDER BY (data->>'bloat_pct')::float8 DESC\nLIMIT $top\n",
434+
"refId": "A",
435+
"resultFormat": "table",
436+
"select": [
437+
[
438+
{
439+
"params": [
440+
"value"
441+
],
442+
"type": "field"
443+
},
444+
{
445+
"params": [],
446+
"type": "mean"
447+
}
448+
]
449+
],
450+
"sql": {
451+
"columns": [
452+
{
453+
"parameters": [],
454+
"type": "function"
455+
}
456+
],
457+
"groupBy": [
458+
{
459+
"property": {
460+
"type": "string"
461+
},
462+
"type": "groupBy"
463+
}
464+
],
465+
"limit": 50
466+
},
467+
"tags": [],
468+
"timeColumn": "time",
469+
"where": [
470+
{
471+
"name": "$__timeFilter",
472+
"params": [],
473+
"type": "macro"
474+
}
475+
]
476+
}
477+
],
478+
"title": "Top $top indexes by estimated bloat %",
479+
"transformations": [
480+
{
481+
"id": "merge",
482+
"options": {
483+
"reducers": []
484+
}
485+
}
486+
],
487+
"type": "table"
488+
},
248489
{
249490
"datasource": {
250491
"type": "grafana-postgresql-datasource",
@@ -308,7 +549,7 @@
308549
"h": 8,
309550
"w": 12,
310551
"x": 0,
311-
"y": 8
552+
"y": 16
312553
},
313554
"id": 13,
314555
"options": {
@@ -426,7 +667,7 @@
426667
"h": 8,
427668
"w": 12,
428669
"x": 12,
429-
"y": 8
670+
"y": 16
430671
},
431672
"id": 14,
432673
"options": {
@@ -545,7 +786,7 @@
545786
"h": 8,
546787
"w": 12,
547788
"x": 0,
548-
"y": 16
789+
"y": 24
549790
},
550791
"id": 15,
551792
"options": {
@@ -664,7 +905,7 @@
664905
"h": 8,
665906
"w": 12,
666907
"x": 12,
667-
"y": 16
908+
"y": 24
668909
},
669910
"id": 16,
670911
"options": {
@@ -844,7 +1085,7 @@
8441085
"h": 8,
8451086
"w": 24,
8461087
"x": 0,
847-
"y": 24
1088+
"y": 32
8481089
},
8491090
"id": 12,
8501091
"options": {
@@ -1024,7 +1265,7 @@
10241265
"h": 7,
10251266
"w": 12,
10261267
"x": 0,
1027-
"y": 32
1268+
"y": 40
10281269
},
10291270
"id": 11,
10301271
"options": {
@@ -1259,7 +1500,7 @@
12591500
"h": 7,
12601501
"w": 12,
12611502
"x": 12,
1262-
"y": 32
1503+
"y": 40
12631504
},
12641505
"id": 10,
12651506
"options": {
@@ -1522,7 +1763,7 @@
15221763
"h": 6,
15231764
"w": 24,
15241765
"x": 0,
1525-
"y": 39
1766+
"y": 47
15261767
},
15271768
"id": 8,
15281769
"options": {
@@ -1604,7 +1845,7 @@
16041845
"h": 7,
16051846
"w": 24,
16061847
"x": 0,
1607-
"y": 45
1848+
"y": 53
16081849
},
16091850
"id": 6,
16101851
"options": {
@@ -1755,5 +1996,5 @@
17551996
"timezone": "browser",
17561997
"title": "Index overview",
17571998
"uid": "index-overview",
1758-
"version": 102
1999+
"version": 4
17592000
}

0 commit comments

Comments
 (0)