Skip to content
Back to skills

Postgres Slow Query

ASecurity

Diagnose a slow Postgres query. Use when the user says a query, report, or endpoint is slow, is timing out, or asks how to read an EXPLAIN plan or add an index.

  • 5 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added October 25, 2026
ai-agents

Security analysis

A100/100

Scanned October 25, 2026

npx -y skills add hung12ct/gopheragent --skill postgres-slow-query --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Postgres Slow Query?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Postgres Slow Query
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hung12ct-postgres-slow-query/badge)](https://www.skillsdirectory.com/skills/hung12ct-postgres-slow-query)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: postgres-slow-query
description: Diagnose a slow Postgres query. Use when the user says a query, report, or endpoint is slow, is timing out, or asks how to read an EXPLAIN plan or add an index.
---

# Diagnosing a slow Postgres query

Never add an index before step 2. Most "slow query" reports are a plan
problem, and an index added blind makes writes slower without fixing reads.

1. **Get the real plan.** `EXPLAIN (ANALYZE, BUFFERS)` — not plain `EXPLAIN`,
   which shows estimates rather than what actually happened.
2. **Compare rows estimated vs actual.** A ratio worse than 100x means the
   planner is working from bad statistics. Run `ANALYZE` on the table before
   doing anything else.
3. **Read Buffers, not just time.** High `shared read` means it went to disk;
   high `shared hit` with slow wall-clock means the problem is CPU, usually a
   sort or a function in the WHERE clause.
4. **Only then consider an index.** Column order follows the query's equality
   predicates first, then the range predicate, then the sort.

Flag a sequential scan on a large table only if the plan also shows a high
rows-removed-by-filter count — a seq scan returning most of the table is
correct behavior, not a bug.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.