# Database Tuning & Optimization

> Pinpoint slow queries, N+1 ORM loops, and missing indexes—then ship verified query rewrites, indexing plans, and caching patterns across SQL and MongoDB.

Database Tuning & Optimization is a paid AI agent skill on Agensi by Sheeyassh. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $5 (one-time purchase)
- Creator: [Sheeyassh](https://www.agensi.io/creators/s1reyash)
- Version: 1.0.0
- Last updated: 2026-11-28
- Security: scan passed (2026-11-28); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/database-tuning-optimization
- Tags: data-databases, database-optimization, query-tuning, indexing, n-plus-one

## About this skill

Pinpoint slow queries, N+1 ORM loops, and missing indexes—then ship verified query rewrites, indexing plans, and caching patterns across SQL and MongoDB. Diagnoses and resolves database performance bottlenecks across relational SQL engines, MongoDB, Django ORMs, GraphQL resolvers, and cloud deployments. It pairs execution-plan analysis with composite and partial indexing, N+1 query elimination, and multi-tier caching architectures to cut latency and connection saturation. Every change is anchored in measured query cost, index selectivity, and actual read/write workload patterns.

### What it does
- **Bottleneck & Execution Plan Audit** Analyzes EXPLAIN (ANALYZE, BUFFERS) or MongoDB .explain('executionStats') outputs alongside ORM models and resolvers to rank sequential scans, N+1 loops, and lock contention.
- **Targeted Query, Index & Caching Refactor** Rewrites slow queries (keyset pagination, covering indexes, DataLoader batching, select_related/prefetch_related) and wires Redis or read-replica caching with invalidation rules.
- **Workload Verification & Regression Guard** Creates benchmark queries, CI query-count assertions, and monitoring thresholds (pg_stat_statements or profiler rules) to verify latency drops before deploy.
- **Deterministic Deliverables** Delivers an execution-plan bottleneck report, concrete ORM or resolver query rewrites, non-blocking index definitions (CREATE INDEX CONCURRENTLY or MongoDB rolling indexes), caching and connection-pooling updates, and reproducible query-plan or query-count verification tests.

### How it works
1. **Pre-Flight & Scope Audit** verifies workspace boundaries, inputs, and required tools (`filesystem-read`, `filesystem-write`, `python3`, `shell-exec`) before modifying any files.
2. **Core Workflow Execution** runs **Bottleneck & Execution Plan Audit**, **Targeted Query, Index & Caching Refactor** using modular, non-destructive steps.
3. **Quality Gate Enforcement** applies skill-specific checks including *GraphQL Depth/Complexity Limiting & N+1 Prevention*, *PostgreSQL Query Plan & Migration Safety*.
4. **Verification & Reporting** validates every deliverable against the 7-point checklist and emits an evidence-backed summary.

### Frameworks & tools
Supports `aws`, `azure`, `ci/cd`, `django`, `gcp`, `graphql`. Uses agent tools: `filesystem-read`, `filesystem-write`, `python3`, `shell-exec`. Prerequisites: Local DB or EXPLAIN plan dumps. Compatible with Claude Code, Cursor, Windsurf, Antigravity, Codex CLI, and MCP-enabled agents.

### Why this beats prompting it yourself
Teams often bolt single-column indexes onto hot tables or slap Redis in front of broken queries without fixing the underlying sequential scan or N+1 fan-out. This skill reads your ORM models, resolvers, slow-query dumps, and EXPLAIN plans directly in the repository to align fixes with real access paths. It avoids regressions like redundant write-heavy indexes, unindexed sort keys causing disk spills, and cache stampedes under load. Instead of ad-hoc prompting, Database Tuning & Optimization enforces GraphQL Depth/Complexity Limiting & N+1 Prevention, PostgreSQL Query Plan & Migration Safety, Index Selectivity, Locking Safety & Backup Verification alongside a deterministic 7-point verification checklist.

### Use cases
- Eliminating GraphQL resolver and Django ORM N+1 waterfalls using DataLoader batching and eager prefetching.
- Replacing slow OFFSET pagination and sequential scans on SQL or MongoDB collections with keyset pagination and selective composite indexes.
- Tuning connection pools, read-replica routing, and Redis cache-aside TTLs for bursty workloads on AWS, GCP, or Azure.
- Pruning bloated or overlapping indexes that slow write throughput and inflate cloud storage IOPS.

### Known limitations
Cannot inspect live cluster metrics unless EXPLAIN plans, pg_stat_statements snapshots, or MongoDB profiler logs are provided in the workspace. Hardware-level parameter sizing (such as shared_buffers or IOPS allocation) depends on cloud instance telemetry outside repository files. Index and caching trade-offs assume read/write ratios match the workload samples analyzed.

## Requires

- Local DB or EXPLAIN plan dumps

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Database Tuning & Optimization skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### How is this different from a generic SQL linter?

SQL linters check syntax formatting only. This skill correlates your application ORM and GraphQL access paths with EXPLAIN execution stats, index selectivity, and caching patterns to remove real latency.

### Which databases, frameworks, and agents does it support?

It supports PostgreSQL, MySQL, MongoDB, Django ORMs, and GraphQL resolvers across AWS, GCP, and Azure workloads using any standard AI coding agent.

### What files and outputs does it produce?

You receive an execution-plan bottleneck report, refactored query or resolver code, non-blocking index migration scripts, caching/pooling patches, and query-budget verification tests.

### Do I need production database credentials, and can I use it on one endpoint?

No live production access is needed. You can apply it incrementally to a single slow endpoint using local tests or pasted EXPLAIN plans and slow-query logs.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
