optimize-database
Skill8 starsChanged 3 months agoMITView on GitHub
Perform complete database health, correctness, performance, reliability, and scalability audits across SQL, NoSQL, key-value, cache, search, and managed database systems. Detects the existing database and query layer, then checks indexes, query plans, schemas, constraints, relations, transactions, locks, pagination, pooling, caching, migrations, backups, observability, security, retention, replication, partitioning, and capacity. Use when diagnosing slow queries, reviewing an entire data layer, preparing for growth, reducing database cost, or safely optimizing production workloads.
In this repository8 other files it gives its agents.
- architect-backendSkill
- audit-backend-securitySkill
- improve-backend-codeSkill
- integrate-1billSkill
- integrate-easypaisaSkill
- integrate-jazzcashSkill
- integrate-stripeSkill
- screenshot-to-codeSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 8 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Search the repository for database drivers, ORM/query-builder packages, connection configuration, schemas/models, migrations, indexes, …
- Distinctive: line 22
If a data layer exists, explain its current design, healthy choices, measured or evidenced problems, and an ordered safe improvement plan.
- Distinctive: line 24
Do not upgrade a database, driver, or ORM silently.
- Distinctive: line 28
Check every applicable area, even when the request mentions only one slow query:
- Distinctive: line 52
Check correctness, transactions, concurrency, and tenant/security boundaries before performance changes.
- Distinctive: line 53
Add caching, replicas, partitions, search engines, queues, or sharding only when simpler fixes and measured requirements justify their …
- Distinctive: line 54
Treat every schema, constraint, index, or data rewrite as a migration with staging evidence, rollout monitoring, and rollback/recovery.
- Distinctive: line 63
Read references/database-guide.md for database-specific index and query patterns, ORM advice, pooling, caching, migration and backup …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Database Optimization
Optimize any database technology without assuming MongoDB, PostgreSQL, MySQL, an ORM, or a particular hosting provider. Inspect evidence before making recommendations.
First: detect the data layer
Search the repository for database drivers, ORM/query-builder packages, connection configuration, schemas/models, migrations, indexes, constraints, repositories, raw queries, transactions, seeds, caches, search systems, background jobs, analytics workloads, tests, deployment configuration, and monitoring.
Identify:
- database engines, versions, extensions, topology, hosting, and environment;
- drivers, ORM/query layer, versions, pooling, retry, and timeout configuration;
- schemas, relationships, constraints, indexes, migrations, and ownership;
- high-traffic read/write paths, data volume/growth, concurrency, latency, and throughput;
- replicas, partitions/shards, caches, queues, backup/restore, retention, and observability.
If a data layer exists, explain its current design, healthy choices, measured or evidenced problems, and an ordered safe improvement plan. If none exists, design the smallest suitable persistence approach from the product's consistency, query, scale, security, and operational requirements.
Do not upgrade a database, driver, or ORM silently. Check release notes, compatibility, migration requirements, and rollback before changing versions.
Mandatory full audit
Check every applicable area, even when the request mentions only one slow query:
- Correctness and integrity — types, nullability, uniqueness, foreign keys/references, validation, invariants, transactions, isolation, idempotency, and consistency.
- Indexes — missing, unused, duplicate, overlapping, invalid, low-selectivity, oversized, write-heavy, foreign-key, compound order, covering, partial, expression, text, geospatial, TTL, and unique indexes.
- Queries and plans — scans, selectivity, cardinality estimates, join strategy, sort/group operations, temporary work, N+1 calls, repeated queries, over-fetching, application-side filtering, and plan regressions.
- Access patterns — real filters, sorts, joins/population, aggregations, writes, hot keys/rows, batch operations, and read/write amplification.
- Pagination and limits — stable ordering, maximum limits, cursor/keyset strategy, large offsets, unbounded exports, and count-query cost.
- Schema and modeling — normalization/denormalization, relationship ownership, document growth, row width, large fields, enums, temporal/history data, and multi-tenant boundaries.
- Concurrency — transactions, isolation level, locks, deadlocks, optimistic/pessimistic control, race conditions, long-running work, and connection starvation.
- Connections — pool sizing, leaks, timeouts, retries, backoff, prepared statements, proxy/serverless behavior, and graceful shutdown.
- Caching — need, keys, TTL, invalidation, consistency, stampede protection, negative caching, memory limits, and failure fallback.
- Migrations — backward compatibility, locks, table rewrites, online index creation, backfills, expand/contract rollout, validation, rollback, and deployment order.
- Operations — slow-query logs, metrics, tracing, alerts, vacuum/analyze or equivalent maintenance, statistics, fragmentation/bloat, storage, and cost.
- Reliability — backups, restore tests, point-in-time recovery, replication, failover, disaster recovery, RPO/RTO, and reconciliation.
- Growth — retention, archival, partitioning/sharding, replicas, materialized views, queues, warehouse/search separation, capacity forecasts, and scaling thresholds.
- Security and privacy — least privilege, credential storage/rotation, encryption, network access, tenant isolation, sensitive fields, audit logs, deletion/retention, and injection risks.
Workflow
- Establish a baseline using timings, throughput, resource use, query plans, slow-query logs, traces, or representative code and data.
- Trace the complete request/job to every database and cache operation.
- Rank bottlenecks by evidence and user impact instead of applying generic tuning.
- Match indexes to real equality/range filters, joins, sort order, uniqueness, selectivity, and projection while accounting for writes and storage.
- Fix query shape and data access before adding infrastructure. Select only needed fields, batch work, remove N+1 calls, enforce limits, and use stable cursor/keyset pagination where appropriate.
- Check correctness, transactions, concurrency, and tenant/security boundaries before performance changes.
- Add caching, replicas, partitions, search engines, queues, or sharding only when simpler fixes and measured requirements justify their operational cost.
- Treat every schema, constraint, index, or data rewrite as a migration with staging evidence, rollout monitoring, and rollback/recovery.
- Re-run the original measurements and report before/after evidence, tradeoffs, and remaining capacity limits.
Safety
Never run destructive or irreversible database operations without explicit confirmation. This includes dropping data or indexes, truncation, unsafe deletes, column removal or rename, destructive type changes, migration resets, repartitioning, and blind production-cache flushes. Confirm the exact environment and target, verify a usable backup/restore path, test on representative staging data, assess locks and disk headroom, and prepare rollback steps first.
Detailed guidance
Read references/database-guide.md for database-specific index and query patterns, ORM advice, pooling, caching, migration and backup checklists, large-scale strategies, or the detailed review format. Search by heading and load only the sections relevant to the detected stack.
Output
Lead with whether an existing data layer was found and summarize its engines, versions, topology, and query tools. Report findings by severity and measured or likely impact. For every recommendation, state evidence, expected benefit, tradeoff, safe rollout, rollback, and verification method. Include an index review even when no new index is recommended. Separate correctness/data-loss risks, security risks, performance bottlenecks, reliability gaps, capacity concerns, and speculative tuning.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

