analyzing-database-indexes
Installation
SKILL.md
Database Index Advisor
Overview
Analyze database index usage, identify missing indexes causing sequential scans, detect redundant or unused indexes wasting write performance, and recommend optimal index configurations for PostgreSQL and MySQL.
Prerequisites
- Database credentials with access to
pg_stat_user_indexes,pg_stat_user_tables, andpg_stat_statements(PostgreSQL) orperformance_schemaandsysschema (MySQL) pg_stat_statementsextension enabled for PostgreSQL query statisticspsqlormysqlCLI for executing analysis queries- Representative workload running (analysis during off-peak hours may miss important query patterns)
- At least 24 hours of statistics accumulation since the last
pg_stat_reset()
Instructions
- Identify tables with high sequential scan activity (candidates for missing indexes):
- PostgreSQL:
SELECT relname, seq_scan, seq_tup_read, idx_scan, n_live_tup FROM pg_stat_user_tables WHERE seq_scan > 100 AND n_live_tup > 10000 ORDER BY seq_tup_read DESC LIMIT 20 - A table with high
seq_scancount and highseq_tup_readrelative ton_live_tupis scanning most of the table repeatedly
- PostgreSQL:
Related skills