Database Optimizer

Optimizes PostgreSQL and MySQL schemas, queries, indexes, and migrations for performance.

2|Updated May 21, 2026
One-click install
npx skills add https://github.com/tcvdog/agency-agents-hermes --skill database-optimizer-tcvdog
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: Database Optimizer
Source: https://github.com/tcvdog/agency-agents-hermes/tree/main/engineering/database-optimizer
Command: npx skills add https://github.com/tcvdog/agency-agents-hermes --skill database-optimizer-tcvdog

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Slow queries, missing indexes, N+1 patterns, and risky migrations degrade application performance and cause production incidents. This Skill provides expert guidance on schema design, query optimization, indexing strategies, and safe migration practices for PostgreSQL, MySQL, Supabase, and PlanetScale. ## Core Features & Use Cases - Schema Design & Indexing: Designs normalized schemas with indexed foreign keys, partial indexes, and composite indexes matched to query patterns. - Query Optimization: Uses EXPLAIN ANALYZE to interpret query plans, eliminate sequential scans, and resolve N+1 query problems with JOINs and JSON aggregation. - Safe Migrations & Pooling: Writes reversible, zero-lock migrations using CREATE INDEX CONCURRENTLY and configures connection pooling with PgBouncer or Supabase pooler. - Use Case: Your API endpoint takes 3 seconds because of an N+1 query loading posts per user. This Skill rewrites it as a single aggregated query and adds the right indexes, cutting response time dramatically. ## Quick Start Ask the database optimizer to review your slow query with EXPLAIN ANALYZE and recommend indexes and a rewritten query.

Frequently Asked Questions about Database Optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix a slow PostgreSQL query?▼

Run EXPLAIN ANALYZE on the query to inspect the execution plan. Look for sequential scans on large tables, compare actual versus estimated rows, then add appropriate indexes or rewrite the query with JOINs instead of subqueries.

How to prevent N+1 queries in application code?▼

Replace per-record queries with a single query using JOINs and json_agg aggregation, or use batch loading. Fetching users and their posts in one grouped query eliminates the N+1 pattern entirely.

Which index type should I use in PostgreSQL?▼

B-tree indexes suit most equality and range queries. Use GIN for JSONB and full-text search, GiST for geometric data, and partial indexes when queries consistently filter on a condition like status equals published.

Does adding an index lock the table in production?▼

A standard CREATE INDEX locks the table against writes. Use CREATE INDEX CONCURRENTLY to build the index without blocking reads or writes, which is essential for zero-downtime production migrations.

Can I use connection pooling with Supabase?▼

Yes, Supabase provides a transaction-mode pooler, typically on port 6543 instead of 5432. Point your connection string at the pooler port for serverless environments where opening connections per request is not viable.

When should I denormalize a database schema?▼

Denormalize only after measuring a proven performance bottleneck that indexing cannot fix. Start with a normalized schema, since premature denormalization adds data duplication and consistency risks without guaranteed benefit.