Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Postgres Query Surgeon

    1

    Diagnose a slow Postgres query from its plan, then prescribe the fix with risk notes.

    $15

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Postgres Query Surgeon

    Postgres Query Surgeon

    Example session with this skill installed

    This query went from 200ms to 9s after the table passed 20M rows. We already added an index on created_at and it got worse. Here is the EXPLAIN ANALYZE output and table stats.

    • Read your context and instructions
    • Compiled the postgres query surgeon

    Worked example — illustrative data.

    Query diagnosis: order history page

    Verdict

    Cause: estimation error plus a bad scan choice. The planner estimated 90 rows (86,400. Expected effect: 9,100ms to 120ms at 20M rows.

    Evidence

    NodeEstimatedActualBuffers
    Bitmap Heap Scan on orders9086,40041,200
    Index Scan on created_at9086,40038,900
    Sort9086,40012,400

    Estimated rows are 960x low because customer_id and status are correlated and the planner multiplies selectivities independently.

    Fix

    CREATE STATISTICS orders_customer_status (dependencies) ON customer_id, status FROM orders;
    ANALYZE orders;
    CREATE INDEX CONCURRENTLY orders_customer_created ON orders (customer_id, created_at DESC) WHERE status = 'paid';
    

    Risk notes

    CONCURRENTLY avoids the write lock but can fail; recovery is to drop the invalid index and retry. Write cost: about 3% on inserts for this table. Rollback: DROP INDEX CONCURRENTLY.

    Verification

    Re-run the same plan with real parameters. Watch p95 for one week; new statistics change plans for three other queries sharing the table.

    Not addressed

    Two other slow queries in the log, deliberately left for a separate pass.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Postgres Query Surgeon Postgres Query Surgeon: what the audit found

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Code Quality & Review.

    Requires EXPLAIN (ANALYZE) for accuracy. Focuses on query and index logic rather than hardware-level OS tuning or network latency.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 2 days ago

    Permissions

    Read Files
    Listed3 days ago
    Updated2 days ago

    What's inside

    Frequently Asked Questions

    Simply provide the output of `EXPLAIN (ANALYZE, BUFFERS, VERBOSE)` along with your table schema. The tool will then systematically evaluate estimation errors and scan patterns to provide a data-driven optimization report.

    This skill is optimized for PostgreSQL versions 12 through 17. It leverages standard system catalogs and explain plan features, making it compatible with any standard PG deployment, including RDS and Cloud SQL.

    Unlike generic AI prompts that often guess, this skill follows a strict diagnostic framework that prioritizes query rewrites and statistic updates over index creation. This prevents "index bloat" and ensures you aren't just masking underlying architectural issues.

    You receive the full Postgres Query Surgeon logic framework, including its diagnostic checklists and prescriptive templates. This allows you to integrate the skill directly into your existing AI agent workflow or developer toolkit.

    No, the skill focuses on database-level diagnostics like index design and query structure. It does not address external factors such as OS-level kernel tuning, hardware bottlenecks, or cloud-specific IOPS throttling.

    New in Code Quality & Review