Postgres Query Optimizer skill for Claude and Codex
Postgres Query Optimizer as an AI skill. It asks for The slow query, Explain output, Table sizes and 3 more, then does the rest. Free to install in Claude or…
Install it once and Claude or Codex runs it for you. When your request matches, your AI loads the skill, asks for anything it is missing, and works through the template itself. Prefer to fill it in by hand? See the full prompt template.
Download the skill (.zip) · View SKILL.md
When it is used
Use when a Postgres query is slow and needs its EXPLAIN ANALYZE plan read, with index, join, or N+1 fixes that can be verified. Do not use for schema design from scratch or tuning server-level configuration. Related topics: data, coding.
What it will ask you for
- The slow query (longer free text)
- Explain output (longer free text)
- Table sizes (free text, e.g. "Approximate row counts")
- Existing indexes (longer free text)
- Postgres version (free text, e.g. "16")
- How it is called (choose one: Per request, Background job, Report, In a loop from application code)
How it works
- Read the plan from the innermost node outward and mark where estimated and actual rows or time diverge.
- Name the most expensive node and the cause, such as a sequential scan, a spilling sort, or a nested loop over too many rows.
- Propose the smallest fix first, with the exact SQL for the index or the rewritten query.
- Check whether the query runs inside an application loop and, if so, give the single set-based replacement.
- State the expected plan change, how to re-run EXPLAIN to confirm it, and the write cost and lock impact of each index.
What you get
A diagnosis of the slow node, then each fix with its SQL, expected plan change, and confirmation step, ordered smallest change first.
What it watches out for
- Adding an index on every filtered column, which slows writes and still misses the column order the planner needs.
- Creating an index without CONCURRENTLY on a busy table and blocking writes.
- Tuning from EXPLAIN without ANALYZE, so the estimated cost hides the real runtime.
How to install
Claude.ai and the Claude desktop app
- Download the skill .zip.
- Open Settings, then Capabilities, and find Skills.
- Choose Upload skill and select the .zip.
- Ask Claude for help with the task. It loads the skill when your request matches.
Claude Code
- Download the skill .zip.
- Unzip it into ~/.claude/skills/ (or .claude/skills/ inside a project).
- Start a new session. Claude Code loads the skill when your request matches.
Codex
- Download the skill .zip.
- Unzip it into ~/.agents/skills/ (or .agents/skills/ inside a project).
- Codex picks it up on its own. Type $ and the skill name to use it, or just ask for the task.
Cursor
- Download the Cursor rule (.mdc).
- Save it in .cursor/rules/ inside your project.
- Cursor's agent applies the rule when your request matches its description.
AGENTS.md (Codex, Cursor, and other coding agents)
- Copy the AGENTS.md section.
- Paste it into AGENTS.md at the root of your repository, creating the file if needed.
- Coding agents that read AGENTS.md follow it when your request fits.