- How you use it
- You ask for it
- What it can do
- writes files
- What's inside
The option
| Option | ASkill · v1.0.0supabase-postgres-best-practices skill (Supabase) |
|---|---|
| How you use it | You ask for it |
| What it can do | writes files |
| What's inside |
What this thread does
The routine
As of November 2026, use a database copy for execution plans and compare hypothetical indexes before drafting migrations. Do first: select a branch or copy, then collect slow-query statistics. Daniel Vaughan's write-up is dated 19 May 2026 and updated 9 October 2026.
1. Rank queries by total execution time, mean time and calls with pg_stat_statements. 2. On the copy, run EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON) and inspect expensive nodes. PostgreSQL distinguishes estimated cost from actual runtime in its EXPLAIN guide. 3. Check for existing indexes covering the same columns. 4. Generate candidates; consider partial indexes for selective filters. 5. Compare estimated costs using HypoPG with plain EXPLAIN, without ANALYZE: hypothetical indexes cannot serve real execution. See HypoPG usage. 6. Set an explicit promotion threshold: Vaughan's flowchart uses over 50 percent, while his reusable skill uses over 30 percent. These are example policies, not measured speedups. 7. Write migrations for promising candidates, measure on the copy, and submit a pull request.
Tooling
The Postgres MCP Pro README (MIT) lists matching tools: get_top_queries, explain_query (can take hypothetical indexes), analyze_query_indexes (up to 10 queries), analyze_workload_indexes and analyze_db_health. For index tuning and comprehensive performance analysis, load the pg_stat_statements and hypopg extensions on the database; hypopg may need a system package. It has a restricted mode (read-only transactions plus an execution time limit) meant for production and an unrestricted mode for development.
Rules worth putting in AGENTS.md (from the write-up)
- Never run EXPLAIN ANALYZE against production; use a branch or read replica.
- Create indexes only through migration files, never ad hoc DDL.
- Paginate any query that can return more than 100 rows.
- Index the referencing column of every foreign key.
- Justify a sequential scan on a large table in a comment.
Common mistakes
EXPLAIN ANALYZEactually executes the statement. Use it on reads, or on a throwaway copy for writes as explained in the PostgreSQL guide.- Trusting row estimates when statistics are stale; run
ANALYZEon the copy first. - Adding an index for every slow query. Index maintenance adds write overhead; consider a query rewrite or a materialised view first.
- Skipping the HypoPG check and shipping an index the planner never uses.
- Giving a community MCP server write access to a real database.
What the sources do not show
The write-up is one person's account about Codex and gives no measured results. EconGnome in an r/dataengineering post says that in his experience agents are very poor at tuning Spark jobs because they optimise one symptom instead of the whole pipeline; that is a claim about Spark, not Postgres, but it is a fair warning to treat the agent's advice as a hypothesis you measure. Neither source provides an independent benchmark of this Postgres tuning routine.
Started from a post by @Daniel Vaughan, packaged by the editor. Original post
- 01 · YouPaste the line from Try it into your agent.
- 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
- 03 · YouApprove a one-line report. Nothing is posted without you.