AGENT SKILL
postgres-query-performance
Diagnose and fix slow PostgreSQL queries with indexes and EXPLAIN
- License 许可
- Apache-2.0
- 所属仓库
- linktogo/maggie
- 最近更新
- 2026-11-14
- Stars
- ★ 2
- Forks
- 2
01 前言 Front Matter
- name
- postgres-query-performance
- globs
- [ "**/*.sql", "**/*.repository.ts" ]
- description
- Diagnose and fix slow PostgreSQL queries with indexes and EXPLAIN
03 SKILL.md 正文
PostgreSQL query performance
Before optimizing, measure. Guessing at indexes wastes time and disk.
Diagnose
- Run
EXPLAIN (ANALYZE, BUFFERS)on the real query with realistic parameters. - Watch for
Seq Scanon large tables in the hot path, highrowsestimates that diverge from actual, and nested-loop joins over big row counts. - Reproduce against production-sized data — plans flip as tables grow.
Fix
- Index the columns used in
WHERE,JOIN, andORDER BY. A composite index order matters: most selective / equality columns first, range columns last. - Add partial indexes for queries that always filter the same predicate
(
WHERE deleted_at IS NULL). - Select only the columns you need; avoid
SELECT *in application queries. - Kill N+1 patterns: fetch related rows in one query with a join or
WHERE id = ANY($1)rather than a query per parent row. - Keep transactions short; long-running ones bloat dead tuples and block
VACUUM.
Verify
Re-run EXPLAIN ANALYZE after the change and confirm the plan uses the index
and the total time dropped. An index that the planner ignores is dead weight —
remove it.
04 同仓库更多 Skills
vuejs-state-management
Manage Vue application state with Pinia and the right state locality
★ 2
vuejs-composition-api
Write Vue 3 components with the Composition API, script setup, and composables
★ 2
reactjs-hooks
Use React hooks correctly — dependencies, effects, and custom hooks
★ 2
reactjs-component-design
Write small, composable React components with clean props and no needless state
★ 2
postgres-migrations
Write safe, reversible, zero-downtime PostgreSQL schema migrations
★ 2
nx-task-running
Run Nx tasks efficiently with affected, caching, and target dependencies
★ 2