debug-db-query

Diagnoses slow or failing Postgres and MongoDB queries with EXPLAIN analysis and structured fixes.

1|Updated Apr 21, 2026
One-click install
npx skills add https://github.com/sswapnil2/ai-config-fintech --skill debug-db-query
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: debug-db-query
Source: https://github.com/sswapnil2/ai-config-fintech/tree/main/skills/debug-db-query
Command: npx skills add https://github.com/sswapnil2/ai-config-fintech --skill debug-db-query

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Diagnose slow or failing database queries and provide actionable debugging guidance.

Core Features & Use Cases

  • EXPLAIN (ANALYZE, BUFFERS) analysis for Postgres queries to identify slow operations and missing indexes.
  • Mongo path analysis with explain("executionStats"), looking for COLLSCAN, non-selective filters, and sort-related issues.
  • Structured fixes: recommend index changes, query rewrites, and strategies to reduce N+1 queries and lock contention.

Quick Start

Reproduce the issue in staging and run an EXPLAIN ANALYZE with realistic parameters to surface the bottlenecks.

Frequently Asked Questions about debug-db-query

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

FAQPage Schema
How do I debug slow Postgres queries using EXPLAIN ANALYZE?

Debug slow Postgres queries by running EXPLAIN (ANALYZE, BUFFERS) with realistic parameters to identify slow operations, missing indexes, and lock contention. The Skill provides structured troubleshooting steps and index-gap analysis to optimize database performance.

Why does my MongoDB query perform a full collection scan?

MongoDB queries perform full collection scans (COLLSCAN) due to non-selective filters or missing indexes. Analyze the executionStats via explain to identify sort-related issues and receive actionable guidance on index changes and query rewrites.

What is the best way to diagnose N+1 query patterns in a database?

Diagnose N+1 query patterns by reproducing the issue in staging and analyzing query execution paths. The Skill enforces a structured workflow to identify redundant queries and recommends query rewrites to reduce database load.

Does this database query analysis work for both MongoDB and Postgres?

Database query analysis supports both Postgres and MongoDB environments. It guides EXPLAIN ANALYZE for Postgres and explain executionStats for MongoDB, covering index-gap analysis and lock-contention investigations across typical fintech stacks.

How do I fix database lock contention issues in production?

Fix database lock contention by following structured troubleshooting guidance that includes reproducing the issue, analyzing execution plans, and applying query rewrites. The Skill provides verification criteria for staging and production environments.

What steps should I take when database query optimization is not working?

When query optimization is not working, enforce a structured workflow starting with reproducing the issue in staging using realistic parameters. Run EXPLAIN ANALYZE to surface bottlenecks, then apply recommended index changes and verify fixes.