Skip to main content

supabase-postgres-best-practices

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.

SupabaseMIT

SKILL.md

Written by Supabase and published in supabase/agent-skills under the MIT license. Treq shows it unchanged except for heading levels and links to files on GitHub.

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

When supabase-postgres-best-practices runs

Claude Code and Codex keep each installed skill's name and description in context. When a request matches the description, the agent loads the full SKILL.md. You can also run it yourself: type /supabase-postgres-best-practices in Claude Code or $supabase-postgres-best-practices in Codex.

Install supabase-postgres-best-practices

Claude Code

Copy the supabase-postgres-best-practices folder into .claude/skills/ in your project. To use it in every project, copy it into ~/.claude/skills/ instead.

git clone --depth 1 https://github.com/supabase/agent-skills.git /tmp/supabase-agent-skills
mkdir -p .claude/skills
cp -r /tmp/supabase-agent-skills/skills/supabase-postgres-best-practices .claude/skills/

Codex

Codex reads skills from .agents/skills/ in your repository, and from ~/.agents/skills/ for every repository. It detects new skills on its own. Restart Codex if supabase-postgres-best-practices does not appear.

git clone --depth 1 https://github.com/supabase/agent-skills.git /tmp/supabase-agent-skills
mkdir -p .agents/skills
cp -r /tmp/supabase-agent-skills/skills/supabase-postgres-best-practices .agents/skills/

Treq

Open Settings and select the Skills tab. The tab appears when Skills installation is on under Settings → Feature Preview. Search for supabase-postgres-best-practices and choose Install….

Install for repository writes the skill under .treq/skills/ in the current repository. Install for application makes it available to every repository on this machine. Each new workspace gets a copy in .claude/skills/ and .agents/skills/, so Claude Code and Codex both find it. See Installing Skills from the Library.

Files

supabase-postgres-best-practices ships 36 files, 60.6 KB in total. Select a file to load it from GitHub.

CHANGELOG.md5.6 KBView on GitHub ↗

All skills by Supabase