Agent Skill
Postgres best practices (Supabase)
Supabase's Postgres rules for schema, indexes, RLS, migrations, connections and slow queries. Works for Postgres anywhere, not just Supabase.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkInstall
Commands are pinned to commit c9be0e9, the version we read, wherever the install method supports it.
npx skills
npx skills add supabase/agent-skills@c9be0e931b7930f7d02126d04774d904c381e7d7 --skill supabase-postgres-best-practices -a claude-codeCopies the skill into .claude/skills/ in this project, pinned to the reviewed commit.
Plugin marketplace
/plugin marketplace add supabase/agent-skills
/plugin install postgres-best-practices@supabase-agent-skillsRun inside Claude Code. Installs the whole postgres-best-practices plugin from its default branch, not the pinned commit.
Upload
git clone https://github.com/supabase/agent-skills.git
cd agent-skills && git checkout c9be0e931b7930f7d02126d04774d904c381e7d7
cd skills && zip -r ~/supabase-postgres-best-practices.zip supabase-postgres-best-practicesThen in Claude open Customize > Skills, choose + > Upload a skill and pick the zip. Code execution must be enabled in Settings > Capabilities.
npx skills
npx skills add supabase/agent-skills@c9be0e931b7930f7d02126d04774d904c381e7d7 --skill supabase-postgres-best-practices -a codexInstalls to .agents/skills/, which Codex scans from the working directory up to the repo root.
npx skills
npx skills add supabase/agent-skills@c9be0e931b7930f7d02126d04774d904c381e7d7 --skill supabase-postgres-best-practices -a cursorInstalls to .agents/skills/, one of the folders Cursor reads skills from.
gh skill
gh skill install supabase/agent-skills skills/supabase-postgres-best-practices --pin c9be0e931b7930f7d02126d04774d904c381e7d7 --agent github-copilotNeeds GitHub CLI 2.90.0 or later. Use --scope user to install for every repository.
npx skills
npx skills add supabase/agent-skills@c9be0e931b7930f7d02126d04774d904c381e7d7 --skill supabase-postgres-best-practicesPinned to the commit we reviewed. The CLI asks which agents to install for; add -g to install for your user instead of this project.
What it does
A short SKILL.md that acts as an index into about 35 reference files, each one rule: connection pooling and limits, prepared statements, batch inserts, N+1 queries, pagination, upserts, advisory locks, deadlock prevention, SKIP LOCKED, EXPLAIN reading, JSONB indexing, full-text search and more. The description is deliberately broad so the agent loads it for any database change, even a single column.
When to use it
Any Postgres work where performance and correctness matter: designing tables, adding indexes, writing queries that will run at scale, fixing connection exhaustion, or reviewing a migration. The advice applies to Postgres anywhere, not only on Supabase.
Each reference file is one rule with an explanation and an example, so the agent loads only the rules that apply to the change in front of it rather than the whole collection.
When to skip it
Analytical warehouse SQL, which SQL queries covers. If you only use Postgres through an ORM and never look at the SQL, much of it will not reach your code, though the indexing advice still applies.
Try it
Review this migration and the queries in src/db/orders.ts for
performance problems at 10 million rows. Read EXPLAIN output for the two
slowest queries and propose indexes.
What it can touch
- Bundles scripts
- No
- Pre-approved tools
- None declared
- Needs
- Nothing beyond the agent
- Client-specific fields
- None, spec fields only
Its instructions steer what your agent does, and it may have changed since the commit we read. How to check a skill.
Instructions only. Because it triggers on almost any SQL work, it will load often; that is the intent.
At commit c9be0e9 the SKILL.md is 65 lines long. Alongside it:
references/(34 entries)CHANGELOG.md
Alternatives
Supabase for the platform around the database, Neon Postgres for Neon-specific setup, and Prisma ORM setup if you work through Prisma.
SKILL.md
The file exactly as published at the reviewed commit, reproduced under its MIT licence.
---
name: supabase-postgres-best-practices
description: "Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pg_cron, pgmq), vector/semantic search (pgvector), and restoring dumps (pg_restore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query."
license: MIT
metadata:
author: supabase
version: "1.1.1"
organization: Supabase
date: January 2026
abstract: Comprehensive Postgres performance optimization guide for developers using Supabase and Postgres. Contains performance rules across 8 categories, prioritized by impact from critical (query performance, connection management) to incremental (advanced features). Each rule includes detailed explanations, incorrect vs. correct SQL examples, query plan analysis, and specific performance metrics to guide automated optimization and code generation.
---
# Supabase Postgres Best Practices
Comprehensive performance optimization guide for Postgres, maintained by Supabase. Contains rules across 8 categories, prioritized by impact to guide automated query optimization and schema design.
## When to Apply
Reference these guidelines when:
- Writing SQL queries or designing schemas
- Implementing indexes or query optimization
- Reviewing database performance issues
- Configuring connection pooling or scaling
- Optimizing for Postgres-specific features
- Working with Row-Level Security (RLS)
## Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|----------|----------|--------|--------|
| 1 | Query Performance | CRITICAL | `query-` |
| 2 | Connection Management | CRITICAL | `conn-` |
| 3 | Security & RLS | CRITICAL | `security-` |
| 4 | Schema Design | HIGH | `schema-` |
| 5 | Concurrency & Locking | MEDIUM-HIGH | `lock-` |
| 6 | Data Access Patterns | MEDIUM | `data-` |
| 7 | Monitoring & Diagnostics | LOW-MEDIUM | `monitor-` |
| 8 | Advanced Features | LOW | `advanced-` |
## How to Use
Read individual rule files for detailed explanations and SQL examples:
```
references/query-missing-indexes.md
references/query-partial-indexes.md
references/_sections.md
```
Each rule file contains:
- Brief explanation of why it matters
- Incorrect SQL example with explanation
- Correct SQL example with explanation
- Optional EXPLAIN output or metrics
- Additional context and references
- Supabase-specific notes (when applicable)
## References
- https://www.postgresql.org/docs/current/
- https://supabase.com/docs
- https://wiki.postgresql.org/wiki/Performance_Optimization
- https://supabase.com/docs/guides/database/overview
- https://supabase.com/docs/guides/auth/row-level-securityRelated skills
Neon Postgres
Neon's guide to connections, pooled vs direct, migrations, branching per PR, autoscaling, scale-to-zero, egress and search on Neon Postgres.
SQL queries
Writes correct, fast SQL across PostgreSQL, Snowflake, BigQuery, Redshift and Databricks, with patterns for windows, cohorts, funnels and deduplication.
ClickHouse best practices
ClickHouse's own review rules: checks schemas, queries and inserts against 36 rule files, cites each rule, and caps every query an agent runs on your data.
Guides and recipes that use Postgres best practices (Supabase)
- Agent Skill best practices: nine design patterns with real examples
Agent skill best practices as nine design patterns, from checklists and routers to script-backed and gated skills, each with a real example and when to use it.