- Home
- Skills
- Code Quality & Review
- Postgres Query Surgeon
Works with the AI Agents you already use
Postgres Query Surgeon
Diagnose a slow Postgres query from its plan, then prescribe the fix with risk notes.
$15
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
| Node | Estimated | Actual | Buffers |
|---|---|---|---|
| Bitmap Heap Scan on orders | 90 | 86,400 | 41,200 |
| Index Scan on created_at | 90 | 86,400 | 38,900 |
| Sort | 90 | 86,400 | 12,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

Requires EXPLAIN (ANALYZE) for accuracy. Focuses on query and index logic rather than hardware-level OS tuning or network latency.
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 2 days ago