Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions pgFirstAid.sql
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ where
and n.nspname = pt.schemaname
and c.relname = pt.tablename
);
-- CRITICAL: Unused indexes consuming significant space
-- CRITICAL: Large indexes never used for reads consuming significant space
insert
into
health_results
Expand All @@ -392,7 +392,7 @@ where
'Table Health' as category,
'Unused Large Index' as check_name,
quote_ident(psi.schemaname) || '.' || quote_ident(psio.indexrelname) as object_name,
'Large unused index consuming disk space and potentially impacting write performance' as issue_description,
'Large index never used for reads, consuming disk space and potentially impacting write performance' as issue_description,
pg_size_pretty(pg_relation_size(psi.indexrelid)) || ' (0 scans)' as current_value,
'Consider dropping this index if truly unused after monitoring usage patterns. Never drop an index without validating usage!' as recommended_action,
'https://www.postgresql.org/docs/current/sql-dropindex.html' as documentation_link,
Expand All @@ -401,10 +401,37 @@ from
pg_stat_user_indexes psi
join pg_statio_user_indexes psio on
psi.indexrelid = psio.indexrelid
join pg_index pgi on
pgi.indexrelid = psi.indexrelid
where
idx_scan = 0
and pg_relation_size(psi.indexrelid) > 104857600;
-- 100MB
and not pgi.indisunique
and not pgi.indisexclusion
Comment thread
randoneering marked this conversation as resolved.
and pg_relation_size(psi.indexrelid) > 104857600; -- 100MB
-- MEDIUM: Large unique/constraint indexes never used for reads
insert
into
health_results
select
'MEDIUM' as severity,
'Table Health' as category,
'Unread Large Constraint-Backing Index' as check_name,
quote_ident(psi.schemaname) || '.' || quote_ident(psio.indexrelname) as object_name,
'Large unique or constraint index never used for reads. It is enforced on every write, so review whether the constraint is needed.' as issue_description,
pg_size_pretty(pg_relation_size(psi.indexrelid)) || ' (0 scans)' as current_value,
'Confirm the underlying unique or primary-key constraint is still required. Drop the constraint if it is not necessary.' as recommended_action,
Comment thread
randoneering marked this conversation as resolved.
'https://www.postgresql.org/docs/current/ddl-constraints.html' as documentation_link,
3 as severity_order
from
pg_stat_user_indexes psi
join pg_statio_user_indexes psio on
psi.indexrelid = psio.indexrelid
join pg_index pgi on
pgi.indexrelid = psi.indexrelid
where
idx_scan = 0
and (pgi.indisunique or pgi.indisexclusion)
and pg_relation_size(psi.indexrelid) > 104857600; -- 100MB
-- HIGH: Inactive Replication slots
insert
into
Expand Down
33 changes: 29 additions & 4 deletions view_pgFirstAid.sql
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,13 @@ where
and c.relname = pt.tablename
)
union all
-- CRITICAL: Unused indexes consuming significant space
-- CRITICAL: Large indexes never used for reads consuming significant space
select
'CRITICAL' as severity,
'Table Health' as category,
'Unused Large Index' as check_name,
quote_ident(psi.schemaname) || '.' || quote_ident(psio.indexrelname) as object_name,
'Large unused index consuming disk space and potentially impacting write performance' as issue_description,
'Large index never used for reads, consuming disk space and potentially impacting write performance' as issue_description,
pg_size_pretty(pg_relation_size(psi.indexrelid)) || ' (0 scans)' as current_value,
'Consider dropping this index if truly unused after monitoring usage patterns. Never drop an index without validating usage!' as recommended_action,
'https://www.postgresql.org/docs/current/sql-dropindex.html' as documentation_link,
Expand All @@ -390,10 +390,35 @@ from
pg_stat_user_indexes psi
join pg_statio_user_indexes psio on
psi.indexrelid = psio.indexrelid
join pg_index pgi on
pgi.indexrelid = psi.indexrelid
where
idx_scan = 0
and pg_relation_size(psi.indexrelid) > 104857600
-- 100MB
and not pgi.indisunique
and not pgi.indisexclusion
and pg_relation_size(psi.indexrelid) > 104857600 -- 100MB
union all
-- MEDIUM: Large unique/constraint indexes never used for reads
select
'MEDIUM' as severity,
'Table Health' as category,
'Unread Large Constraint-Backing Index' as check_name,
quote_ident(psi.schemaname) || '.' || quote_ident(psio.indexrelname) as object_name,
'Large unique or constraint index never used for reads. It is enforced on every write, so review whether the constraint is needed.' as issue_description,
pg_size_pretty(pg_relation_size(psi.indexrelid)) || ' (0 scans)' as current_value,
'Confirm the underlying unique or primary-key constraint is still required. Drop the constraint if it is not necessary.' as recommended_action,
'https://www.postgresql.org/docs/current/ddl-constraints.html' as documentation_link,
3 as severity_order
from
pg_stat_user_indexes psi
join pg_statio_user_indexes psio on
psi.indexrelid = psio.indexrelid
join pg_index pgi on
pgi.indexrelid = psi.indexrelid
where
idx_scan = 0
and (pgi.indisunique or pgi.indisexclusion)
and pg_relation_size(psi.indexrelid) > 104857600 -- 100MB
union all
-- HIGH: Inactive Replication slots
(with q as (
Expand Down
33 changes: 29 additions & 4 deletions view_pgFirstAid_managed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,13 @@ where
and c.relname = pt.tablename
)
union all
-- CRITICAL: Unused indexes consuming significant space
-- CRITICAL: Large indexes never used for reads consuming significant space
select
'CRITICAL' as severity,
'Table Health' as category,
'Unused Large Index' as check_name,
quote_ident(psi.schemaname) || '.' || quote_ident(psio.indexrelname) as object_name,
'Large unused index consuming disk space and potentially impacting write performance' as issue_description,
'Large index never used for reads, consuming disk space and potentially impacting write performance' as issue_description,
pg_size_pretty(pg_relation_size(psi.indexrelid)) || ' (0 scans)' as current_value,
'Consider dropping this index if truly unused after monitoring usage patterns. Never drop an index without validating usage!' as recommended_action,
'https://www.postgresql.org/docs/current/sql-dropindex.html' as documentation_link,
Expand All @@ -385,10 +385,35 @@ from
pg_stat_user_indexes psi
join pg_statio_user_indexes psio on
psi.indexrelid = psio.indexrelid
join pg_index pgi on
pgi.indexrelid = psi.indexrelid
where
idx_scan = 0
and pg_relation_size(psi.indexrelid) > 104857600
-- 100MB
and not pgi.indisunique
and not pgi.indisexclusion
and pg_relation_size(psi.indexrelid) > 104857600 -- 100MB
union all
-- MEDIUM: Large unique/constraint indexes never used for reads
select
'MEDIUM' as severity,
'Table Health' as category,
'Unread Large Constraint-Backing Index' as check_name,
quote_ident(psi.schemaname) || '.' || quote_ident(psio.indexrelname) as object_name,
'Large unique or constraint index never used for reads. It is enforced on every write, so review whether the constraint is needed.' as issue_description,
pg_size_pretty(pg_relation_size(psi.indexrelid)) || ' (0 scans)' as current_value,
'Confirm the underlying unique or primary-key constraint is still required. Drop the constraint if it is not necessary.' as recommended_action,
'https://www.postgresql.org/docs/current/ddl-constraints.html' as documentation_link,
3 as severity_order
from
pg_stat_user_indexes psi
join pg_statio_user_indexes psio on
psi.indexrelid = psio.indexrelid
join pg_index pgi on
pgi.indexrelid = psi.indexrelid
where
idx_scan = 0
and (pgi.indisunique or pgi.indisexclusion)
and pg_relation_size(psi.indexrelid) > 104857600 -- 100MB
union all
-- HIGH: Inactive Replication slots
(with q as (
Expand Down
Loading