agentleFS
tim-osterhustim-osterhus/millrace-skills/skills/postgres-query-performance/SKILL.md

postgres-query-performance

Skill0 starsChanged 7 months agoApache-2.0View on GitHub

Guardrail for evidence-first Postgres and Supabase query, schema, index, RLS, and migration performance reviews.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. About 0 are common, 14 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈14

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    If evidence is missing, say what you are assuming and name the next verifier instead of pretending the plan is proven.

    line 42
  2. Distinctive:

    Do not tune without a plan or plan evidence.

    line 46
  3. Distinctive:

    Do not guess indexes from column names alone.

    line 47
  4. Distinctive:

    Do not treat RLS as free; account for policy cost and plan shape.

    line 48
  5. Distinctive:

    Do not recommend a migration without rollback and verification.

    line 49
  6. Distinctive:

    Do not expand into generic DBA advice, connection pooling, or platform-ops territory.

    line 50
  7. Distinctive:

    Keep the recommended fix small: add or adjust one index, rewrite one query, change one schema detail, or split one migration.

    line 51
  8. Distinctive:

    Prefer concrete evidence over theory when the claim is about performance.

    line 52
  9. Distinctive:

    If a migration is involved, the rollback shape, deploy order, and verification target.

    line 59
  10. Distinctive:

    Start by naming the classification and the first evidence to inspect.

    line 62
  11. Distinctive:

    If evidence is missing, state the assumption and the next verifier explicitly.

    line 66
  12. Distinctive:

    If a migration is part of the answer, include rollback and verification in the same pass.

    line 67
  13. Very specific:

    Use EXPLAIN or EXPLAIN ANALYZE as the primary proof surface when available.

    line 73
  14. Distinctive:

    If the needed evidence is missing, state the assumption, the next verifier, and the specific artifact still needed.

    line 75
  15. Distinctive:

    If the task involves a migration, add rollback and verification before concluding.

    line 77

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Postgres Query Performance

Purpose

Help agents diagnose slow Postgres or Supabase-backed paths by reading the query, plan, schema, indexes, and RLS policies first, then recommending the smallest safe change class. This is a guardrail, not a generic DBA manual.

Use When

  • the task is a slow query, suspect plan regression, missing index, late RLS filtering, or risky migration
  • the database is Postgres or Supabase-backed Postgres
  • the answer needs evidence before recommending a query rewrite, index change, schema change, or rollback shape

Do Not Use When

  • the issue is pure SQL syntax or correctness, not performance
  • the database is not Postgres
  • the work belongs to broad database administration, hosting, or connection-tuning advice

Quick Start

  1. Classify the task first: query review, schema/index review, RLS/perf review, or migration/rollback planning.
  2. Inspect the query text and the first plan evidence available: EXPLAIN, EXPLAIN ANALYZE, actual row counts, and execution metrics.
  3. Then inspect the schema facts that change plan shape: indexes, keys, table size, selectivity, and relevant RLS policies.
  4. Rule in or out the likely bottleneck class: missing index, bad join shape, low selectivity or cardinality, policy evaluation cost, or migration risk.
  5. If evidence is missing, say what you are assuming and name the next verifier instead of pretending the plan is proven.
  6. End with the smallest safe change class and the evidence captured for the next check.

Operating Constraints

  • Do not tune without a plan or plan evidence.
  • Do not guess indexes from column names alone.
  • Do not treat RLS as free; account for policy cost and plan shape.
  • Do not recommend a migration without rollback and verification.
  • Do not expand into generic DBA advice, connection pooling, or platform-ops territory.
  • Keep the recommended fix small: add or adjust one index, rewrite one query, change one schema detail, or split one migration.
  • Prefer concrete evidence over theory when the claim is about performance.

Inputs This Skill Expects

  • The query text and any bind parameters or filters that affect selectivity.
  • The current plan evidence, ideally EXPLAIN ANALYZE plus actual rows and timing.
  • Existing indexes, keys, constraints, table sizes, and row-count context.
  • Relevant schema details, joins, and RLS policy snippets.
  • If a migration is involved, the rollback shape, deploy order, and verification target.

Output Contract

  • Start by naming the classification and the first evidence to inspect.
  • Separate plan evidence from schema or policy assumptions.
  • Identify the most likely bottleneck class before suggesting a fix.
  • Give the smallest safe change class and the evidence that makes it safe enough.
  • If evidence is missing, state the assumption and the next verifier explicitly.
  • If a migration is part of the answer, include rollback and verification in the same pass.
  • End with a handoff line naming the next verifier and the evidence intentionally captured.

Procedure

  1. Classify the request before recommending any change.
  2. Inspect query text and plan evidence first, then compare the observed shape with indexes, schema, and policies.
  3. Use EXPLAIN or EXPLAIN ANALYZE as the primary proof surface when available.
  4. Decide whether the main issue is index coverage, join shape, selectivity or cardinality, policy evaluation cost, or migration risk.
  5. If the needed evidence is missing, state the assumption, the next verifier, and the specific artifact still needed.
  6. Recommend the smallest safe fix class and keep the change bounded to the observed bottleneck.
  7. If the task involves a migration, add rollback and verification before concluding.

Pitfalls And Gotchas

  • Rejected trope: tuning without a plan or plan evidence. Better alternative: start from EXPLAIN ANALYZE and actual rows.
  • Rejected trope: guessing indexes from column names. Better alternative: match the filter, join, and sort order to the observed plan and selectivity.
  • Rejected trope: treating RLS as free. Better alternative: inspect the policy predicates and account for when they are evaluated.
  • Rejected trope: recommending a migration without rollback or verification. Better alternative: include the rollback path and the evidence that proves the change safe.
  • Rejected trope: broad DBA advice. Better alternative: stay within the smallest query, schema, index, or policy change that addresses the observed bottleneck.

Progressive Disclosure

Start with the query and plan, then widen only if schema, policy, or migration facts change the bottleneck class. Keep one umbrella skill for query, index, schema, RLS, and migration guidance so the evidence loop stays in one place. Add deeper references only if later QA shows the plan-reading guidance needs more detail.

Verification Pattern

  • Confirm the first evidence named is the query and plan, not a guessed optimization.
  • Confirm the bottleneck class matches the observed plan and schema facts.
  • Confirm the recommendation is one small change class rather than a broad rewrite.
  • Confirm RLS cost is checked separately from base query cost when policies exist.
  • Confirm any migration includes rollback and verification.
  • Confirm the handoff names the next verifier and the evidence intentionally captured.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.