CataloguePerformance, Scale & Cost
Database & Query Health Audit
Reads queries, indexes, and the way schema change is recorded.
What it examines
- Filters, joins, and sorts with no matching index
- Indexes nothing uses
- Sequential scans on large tables
- Schema with no versioned migration history
- Connection pools sized for a different workload
- Missing foreign keys, uniqueness, or checks the domain implies
- Transactions held open across a network call
What you get back
A findings file. Each item has the evidence, how serious it is, and a fix.
Dependencies
- An AI coding agent that reads SKILL.md files, such as Claude Code, Codex or Gemini CLI
- Read access to the repository, including schema and migration files
- Optional: query logs, EXPLAIN output or a read replica. They unlock the live checks. Without any of them, the unused-index and full-scan checks are recorded as insufficient evidence rather than guessed.
- Python 3 with the jsonschema package, to check findings.json before fixing anything
How it works
The audit is read-only. It reads the schema, migrations and queries in your code to find missing indexes, risky migrations and query patterns that scale badly.
When you supply query logs, EXPLAIN output or a replica, it also checks which indexes are never used and which queries scan whole tables.
You get findings.json and findings.md. The remediate skill reads findings.json. Index changes are the easy part, and schema and migration changes need your approval.
Setup
- Unzip the download. Copy the audit and remediate folders into your agent's skills folder (for Claude Code, .claude/skills/) in the repository you want to check.
- Export slow-query logs or EXPLAIN output if you can, or point the agent at a read replica. Never point it at your primary database.
- Open the repository in your agent and ask it to run the c2-database-query-health-audit skill.
- Check the result with the validator: pip install jsonschema, then python3 schema/validate.py findings.json.
- Ask your agent to run the c2-database-query-health-remediate skill using findings.json. Fix some findings and leave the rest open if you like.
Run it with your agent
Copy the prompt, fill in the parts in square brackets, and paste it into your agent.
Run the c2-database-query-health-audit skill on this repository. Query logs, EXPLAIN output or a read replica: [what is available, or none]. Never connect to the primary database. Mode: audit only. Do not change any code. Write findings.json and findings.md in the repository root.
Run the c2-database-query-health-remediate skill using findings.json. Work through the findings I choose, and leave the rest open.