- Home
- Skills
- Data & Databases
- Postgres Query Optimizer: Find & Prove the Fix
Works with the AI Agents you already use
Postgres Query Optimizer: Find & Prove the Fix
Runs EXPLAIN ANALYZE safely, pinpoints exactly why your Postgres query is slow, and tests every fix in a rolled-back transaction. Verified 375–2,347× speedups.
$5
Postgres Query Optimizer: Find & Prove the Fix
Example session with this skill installed
On the connected staging database, optimize SELECT * FROM orders WHERE customer_id = 842 AND status = 'pending'. You may test fixes and roll them back. Give me the SQL worth applying.
- Read your context and instructions
- Compiled the postgres query optimizer
The query's median execution time fell from
240 ms to 36 ms, an
85% reduction, with a composite index in staging.
Test changes were rolled back. No index was kept.
Findings and tested fixes
The main bottleneck was a full scan of orders, discarding 1,199,976 rows to return 24. No existing index covered both filter columns.
| Test | Median time | Result |
|---|---|---|
| Original query | 240 ms | Baseline |
| Index on customer_id and status | 36 ms | Verified improvement |
| Statistics refresh alone | 236 ms | No meaningful improvement |
The indexed plan used a bitmap index scan followed by a bitmap heap scan instead of reading the entire table.
SQL worth applying
For production, build the index concurrently to avoid blocking normal writes during the build. Run this outside a transaction block:
CREATE INDEX CONCURRENTLY idx_orders_customer_status
ON orders (customer_id, status);
ANALYZE orders;
The index consumes disk space and adds work to inserts and updates. This test did not measure that write overhead. Staging results may differ from production.
Detailed plan timings and test comparisons are in pgopt-output/report.md.
Next steps
- Confirm staging data volume is representative of production.
- Apply the index during an appropriate deployment window.
- Recheck query timing and write performance after deployment.
Connects securely to your tools. The creator never sees your data.
About this skill
A slow database query can hold up an entire page or endpoint. Find where PostgreSQL spends its time, get specific fixes, and test whether they actually help before keeping them.
What it does
- Explains the bottleneck: Reads the query execution plan to identify expensive scans, joins, sorts, and other slow steps.
- Suggests targeted fixes: Recommends relevant indexes, statistics updates, or memory settings rather than guessing from SQL alone.
- Tests improvements: With database access and permission, compares timings and rolls back the test changes.
- Reports what failed: Shows tested fixes that did not help, alongside the exact SQL for useful changes.
How it works
- Share a slow query with database access, or paste a PostgreSQL execution plan.
- Get a breakdown of the costly steps and suggested fixes.
- Approve live testing if you want measured comparisons.
- Review the report and choose which changes to apply.
Works with
PostgreSQL, including Supabase, Neon, Amazon RDS, and Cloud SQL. Running the tool requires Python 3 and the PostgreSQL psql client. Offline analysis works from a JSON execution plan.
Why use this skill
Avoid spending time adding indexes that do not address the bottleneck. Measured comparisons help you separate useful changes from ones that only sound promising.
Use cases
- Diagnose a slow customer dashboard query.
- Check whether a proposed index improves an endpoint.
- Review a query plan without sharing database access.
Known limitations
Handles one query at a time. Test timings depend on the environment. Index tests can block writes, so production testing needs care.
Optimizes one query at a time. Does not model index write overhead or auto-verify query rewrites. Timings depend on test data; live index tests can block writes.
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 any payment.
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 1 month ago