Skip to content
Supabase Postgres Best Practices

Supabase Postgres Best Practices Skill

Supabase's official Postgres skill — eight rule categories ranked by impact, each with wrong-vs-right SQL and EXPLAIN output, for schema, RLS, indexing and query work on Postgres anywhere.

GitHub Docs

Install

Install with the skills CLI

One command for Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf and dozens of other agents. Needs Node.js; the skill is fetched straight from supabase/agent-skills.

$ npx skills add supabase/agent-skills --skill supabase-postgres-best-practices

Run it in a terminal. The CLI finds the agents installed on your machine, asks which ones to add the skill to, and whether to install it into the folder you ran it from or for all your projects.

Other ways to install

Copy the whole skill folder — SKILL.md and any scripts or references beside it — into ~/.claude/skills/supabase-postgres-best-practices/, where Claude Code picks it up in every project. Only git is needed.

tmp=$(mktemp -d) && \
  git clone --depth 1 --branch main https://github.com/supabase/agent-skills.git "$tmp" && \
  mkdir -p ~/.claude/skills && \
  cp -R "$tmp"/skills/supabase-postgres-best-practices ~/.claude/skills/supabase-postgres-best-practices

No scripts or references next to it? Saving the SKILL.md alone as ~/.claude/skills/supabase-postgres-best-practices/SKILL.md works too.

Using another agent? Its personal skills folder
Codex
~/.agents/skills/
Cursor
~/.cursor/skills/
GitHub Copilot
~/.copilot/skills/
Gemini CLI
~/.gemini/skills/
Windsurf
~/.codeium/windsurf/skills/
OpenCode
~/.config/opencode/skills/

About

  • Eight rule categories ranked from critical to low impact
  • Each rule pairs incorrect SQL with the corrected version and an EXPLAIN plan
  • Covers RLS policies and the tests that verify tenant isolation
  • Diagnostic rules for slow queries, locking, bloat and connection exhaustion
  • Applies to Postgres anywhere, with Supabase-specific notes called out separately
  • Includes pgvector, pgmq and pg_cron guidance

Supabase maintains this skill for Postgres generally, not only Postgres on Supabase. Its instruction is to load before touching anything that lives in a database — creating or altering a table, picking a column type, writing a migration or a declarative schema file, adding an RLS policy, an index, a trigger, a database function, a queue or a pg_cron job, setting up pgvector search, or restoring a dump.

It is equally the skill to load when something is already wrong: slow queries, high CPU, timeouts, connection exhaustion, locking, bloat, an EXPLAIN plan you cannot read, or rows visible to the wrong tenant.

How the rules are organised

Eight categories, ordered by impact, each with a rule-file prefix:

  1. Query performance (query-) — critical
  2. Connection management (conn-) — critical
  3. Security and RLS (security-) — critical
  4. Schema design (schema-) — high
  5. Concurrency and locking (lock-) — medium-high
  6. Data access patterns (data-) — medium
  7. Monitoring and diagnostics (monitor-) — low-medium
  8. Advanced features (advanced-) — low

Every rule file follows the same shape: why it matters, an incorrect SQL example with an explanation of the damage, the corrected version, EXPLAIN output or a metric where one is illuminating, and Supabase-specific notes where the managed platform changes the answer.

That structure is what makes it useful to an agent rather than a human reading a blog post — a rule is retrievable by prefix, and the wrong/right pair gives the model a concrete pattern to match against the SQL in front of it.

Version 1.1.1, MIT licensed.

Try it

Once installed, ask your agent something like:

Use the supabase-postgres-best-practices skill to review this migration before I run it — check the index choices, the RLS policy and whether the column types will scale.

SKILL.md

The instructions your agent loads, as published by Supabase.

SKILL.md
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
PriorityCategoryImpactPrefix
1Query PerformanceCRITICALquery-
2Connection ManagementCRITICALconn-
3Security & RLSCRITICALsecurity-
4Schema DesignHIGHschema-
5Concurrency & LockingMEDIUM-HIGHlock-
6Data Access PatternsMEDIUMdata-
7Monitoring & DiagnosticsLOW-MEDIUMmonitor-
8Advanced FeaturesLOWadvanced-
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-security
Install

A PostgreSQL development skill from GitHub's awesome-copilot collection: JSONB, arrays, window functions, full-text search, index strategy, EXPLAIN ANALYZE and pg_stat_statements, with an optimization checklist.

A PostgreSQL code-review skill from GitHub's awesome-copilot collection: checks schemas, JSONB and array usage, PL/pgSQL functions, extensions and Row Level Security against PostgreSQL-specific anti-patterns.

Skill: Supabase

by Supabase

Featured

Supabase's official skill covering Database, Auth, Edge Functions, Realtime, Storage, Vectors, Cron and Queues — with a hard rule to verify against the live changelog before writing code.

New

A PostgreSQL schema design checklist for agents: primary keys, data types to prefer and avoid, constraints, B-tree/GIN/GiST/BRIN indexes, partitioning and JSONB, with PostgreSQL-specific gotchas and worked DDL.

Browse all skills →