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, and pg_stat_statements (PostgreSQL) or performance_schema and sys schema (MySQL)
  • pg_stat_statements extension enabled for PostgreSQL query statistics
  • psql or mysql CLI 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

  1. 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_scan count and high seq_tup_read relative to n_live_tup is scanning most of the table repeatedly
Related skills
Installs
30
GitHub Stars
2.2K
First Seen
Jan 23, 2026