Skip to content

Commit b80734a

Browse files
Added a pg_class metric
1 parent 8113d5a commit b80734a

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

config/pgwatch-prometheus/metrics.yml

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -966,34 +966,33 @@ metrics:
966966
- wal_bytes
967967
- temp_bytes_read
968968
- temp_bytes_written
969-
pg_index_tuples:
969+
pg_class:
970970
description: >
971-
Track tuple counts (live, dead, and total) for indexes using reltuples from pg_class.
972-
This metric provides insights into index tuple distribution and can help identify
973-
indexes that may benefit from maintenance operations.
971+
Direct access to pg_class system catalog data for all relations (tables, indexes, etc).
972+
Provides reltuples, relpages, and other pg_class columns with relname and schemaname
973+
as tags for easy filtering and querying.
974974
sqls:
975975
11: |
976976
select
977977
current_database() as tag_datname,
978978
n.nspname as tag_schemaname,
979-
t.relname as tag_tablename,
980-
i.relname as tag_indexname,
981-
i.reltuples as total_tuples,
982-
coalesce(pg_stat_get_live_tuples(t.oid), 0) as live_tuples,
983-
coalesce(pg_stat_get_dead_tuples(t.oid), 0) as dead_tuples
984-
from pg_class i
985-
join pg_index idx on idx.indexrelid = i.oid
986-
join pg_class t on t.oid = idx.indrelid
987-
join pg_namespace n on n.oid = i.relnamespace
988-
where i.relkind = 'i'
989-
and t.relkind = 'r'
990-
and n.nspname not in ('information_schema', 'pg_catalog')
991-
order by i.reltuples desc nulls last
992-
limit 5000
979+
c.relname as tag_relname,
980+
c.relkind as tag_relkind,
981+
c.reltuples,
982+
c.relpages,
983+
pg_relation_size(c.oid) as relation_size_bytes,
984+
pg_total_relation_size(c.oid) as total_relation_size_bytes
985+
from pg_class c
986+
join pg_namespace n on n.oid = c.relnamespace
987+
where n.nspname not in ('information_schema', 'pg_catalog')
988+
and c.relkind in ('r', 'i', 'm', 'v') -- tables, indexes, materialized views, views
989+
order by pg_total_relation_size(c.oid) desc
990+
limit 10000
993991
gauges:
994-
- total_tuples
995-
- live_tuples
996-
- dead_tuples
992+
- reltuples
993+
- relpages
994+
- relation_size_bytes
995+
- total_relation_size_bytes
997996
pg_stat_user_indexes:
998997
sqls:
999998
11: |
@@ -1985,7 +1984,7 @@ presets:
19851984
pg_stat_wal_receiver: 30
19861985
pg_archiver: 30
19871986
pg_stat_user_tables: 30
1988-
pg_index_tuples: 30
1987+
pg_class: 30
19891988
pg_stat_user_indexes: 30
19901989
pg_stat_statements: 30
19911990
pg_stat_replication: 30

0 commit comments

Comments
 (0)