Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    MySQL and PostgreSQL Slow Query Log Triage

    by Saizul Amin

    1

    Triage database bottlenecks by fingerprinting and ranking slow queries from MySQL and PostgreSQL logs.

    $6

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    MySQL and PostgreSQL Slow Query Log Triage

    MySQL and PostgreSQL Slow Query Log Triage

    Example session with this skill installed

    Here is our MySQL slow query log. Group the queries and show me the top 5 worth fixing first.

    • Read your context and instructions
    • Compiled the mysql and postgresql

    I ran the bundled script from the slow-query-log-triage skill and reviewed its findings.

    Demo data: this is the real, unedited output of the skill's script on the test fixture that ships with its source repo.

    Script output

    mysql: 11 executions, 4 distinct queries, 31.1 s total
    
    #1  43.4% of time  6 calls  total 13.50 s  mean 2,250.0 ms p95 2,500 ms  max 2,500 ms
        rows sent 120  examined 6,000,000
        db: shop  user: app
        SELECT id, total FROM orders WHERE status = ? AND customer_id = ? ORDER BY created_at DESC LIMIT ?
        hint: examines 50,000 rows per row returned: missing or unused index (run EXPLAIN, see index-advisor)
    
    #2  38.6% of time  1 calls  total 12.00 s  mean 12,000.0 ms p95 12,000 ms  max 12,000 ms
        rows sent 1  examined 5,000,000
        db: shop  user: app
        SELECT COUNT (*) FROM events WHERE kind IN (?+)
        hint: examines 5,000,000 rows per row returned: missing or unused index (run EXPLAIN, see index-advisor)
    
    #3  14.5% of time  3 calls  total 4.50 s  mean 1,500.0 ms p95 1,500 ms  max 1,500 ms
        db: shop  user: app
        UPDATE inventory SET qty = qty - ? WHERE product_id = ?
        hint: 80% of the time is lock wait: look for long transactions
    
    #4  3.5% of time  1 calls  total 1.10 s  mean 1,100.0 ms p95 1,100 ms  max 1,100 ms
        rows sent 5  examined 50
        db: shop  user: app
        SELECT id FROM users WHERE email = ?
    

    Next steps

    1. Run EXPLAIN on the top query patterns.
    2. Add or adjust indexes for the worst offenders, then re-check the log.
    3. Track total time per pattern after each change.

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

    About this skill

    Stop guessing which database queries are slowing down your application. When the database is under load or CPU is spiking, this skill identifies the specific query shapes consuming the most resources across MySQL, MariaDB, and PostgreSQL.

    What it does

    • Multi-engine support parses MySQL/MariaDB slow logs (including gzipped files) and PostgreSQL log_min_duration_statement logs or pg_stat_statements exports.
    • Query fingerprinting groups unique query shapes by normalizing literals to placeholders, allowing you to see aggregate impact rather than individual outliers.
    • Resource ranking sorts queries by total time, execution count, p95 latency, lock time, and temporary disk spills.
    • Efficiency metrics calculates rows examined per row returned to highlight missing indexes and sequential scans.
    • Bottleneck detection flags N+1 query patterns, cache misses, and lock contention issues automatically.

    How it works

    1. Data collection extracts logs via provided psql copy commands for pg_stat_statements or identifies slow log file locations in MySQL.
    2. Execution runs the triage script against the log or CSV file with optional time range filters (--since, --until) or sort overrides.
    3. Classification analyzes the top 5 to 10 query groups to determine if the fix is a missing index, a query rewrite, or application-level caching.
    4. Planning generates a prioritized report with expected impact percentages for each recommended fix.

    Frameworks & tools

    This skill uses Python 3.8+ standard library scripts to process log files. It integrates with MySQL, MariaDB, and PostgreSQL workflows.

    Why this beats prompting it yourself

    Manual log analysis is tedious and prone to missing high-frequency, low-latency queries that aggregate into major bottlenecks. This skill provides precise normalization and statistical distribution (mean vs. p95) that generic prompts cannot calculate accurately from raw text.

    Use cases

    • Diagnose 100% CPU usage on database instances.
    • Identify "chatty" N+1 queries that should be batched or cached.
    • Audit database performance after a major deployment.
    • Justify new indexes by showing exactly how many rows are examined per result.

    Known limitations

    Enabling logs or resetting statistics requires server-side configuration changes and user approval. It does not resolve active lock contention in real-time.


    Open source: saizul/sql-database-skills on GitHub (MIT licence, by Saizul Amin).

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Data & Databases.

    Requires Python 3.8+. Server configuration changes like enabling slow_query_log or installing pg_stat_statements require manual user approval.

    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.

    Frequently Asked Questions

    This skill specializes in 'query fingerprinting,' which groups thousands of individual log entries into unique query shapes. It then calculates precise statistical metrics like p95 latency and rows-examined-per-row-returned to pinpoint the exact cause of database CPU spikes.

    The skill is compatible with MySQL, MariaDB, and PostgreSQL. It supports standard text logs, gzipped files, and exports from the 'pg_stat_statements' extension.

    You will receive the Python-based triage scripts, pre-configured execution commands for both MySQL and PostgreSQL, and the logic required for the AI agent to interpret and prioritize the findings.

    Yes, you can use the '--since' and '--until' flags to isolate specific time windows, such as a deployment window or a period of high traffic, to see exactly which queries were causing issues during that time.

    No, this skill is a diagnostic tool that analyzes existing logs or exports; it does not require an active connection to your production database or the ability to execute write commands.

    The agent will provide a prioritized report that classifies the top bottlenecks and suggests specific remediations, such as adding indexes, rewriting N+1 query patterns, or implementing application-level caching.

    New in Data & Databases