- Home
- Skills
- Data & Databases
- MySQL and PostgreSQL Slow Query Log Triage
Works with the AI Agents you already use
MySQL and PostgreSQL Slow Query Log Triage
by Saizul Amin
Triage database bottlenecks by fingerprinting and ranking slow queries from MySQL and PostgreSQL logs.
$6
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
- Run EXPLAIN on the top query patterns.
- Add or adjust indexes for the worst offenders, then re-check the log.
- 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_statementlogs orpg_stat_statementsexports. - 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
- Data collection extracts logs via provided
psqlcopy commands forpg_stat_statementsor identifies slow log file locations in MySQL. - Execution runs the triage script against the log or CSV file with optional time range filters (
--since,--until) or sort overrides. - 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.
- 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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
- Software
Python 3.8+