supabase-postgres-best-practices
supabase/agent-skills
Postgres best practices from Supabase: schema, security, performance, and operations rules for any Postgres database.
What is supabase-postgres-best-practices?
Comprehensive guide to Postgres optimization and correctness maintained by Supabase. Load this skill before writing or modifying database schemas, queries, RLS policies, indexes, migrations, or diagnosing performance issues—it covers query performance, connection management, security, schema design, concurrency, and advanced features across 8 priority categories.
- Provides rules for query optimization, index selection, and EXPLAIN plan analysis
- Guides schema design, column type selection, and migration strategies
- Covers Row-Level Security (RLS) policy design and testing
- Addresses connection pooling, concurrency, locking, and bloat issues
- Includes vector search (pgvector), queues (pgmq), and scheduled jobs (pg_cron)
- Helps diagnose slow queries, timeouts, connection exhaustion, and data visibility problems
How to install supabase-postgres-best-practices
npx skills add https://github.com/supabase/agent-skills --skill supabase-postgres-best-practicesHow to use supabase-postgres-best-practices
- 1.Install the skill using: npx skills add https://github.com/supabase/agent-skills --skill supabase-postgres-best-practices
- 2.Load this skill before writing or modifying any database code
- 3.Reference the rule categories by priority: query performance and connection management first (critical), then schema design, concurrency, and advanced features
- 4.Read individual rule files in references/ for detailed explanations, SQL examples, and EXPLAIN output
- 5.Apply the correct SQL patterns and schema practices to your code generation or review
Use cases
- Designing or altering database tables, columns, and schemas before implementation
- Optimizing slow queries or high-CPU database operations
- Implementing and testing RLS policies for multi-tenant applications
- Choosing appropriate indexes and analyzing EXPLAIN plans
- Configuring connection pooling and managing concurrent access
- Backend developers building with Postgres or Supabase
- Database architects designing schemas and security policies
- DevOps engineers optimizing database performance and operations
- Full-stack developers handling their own database layer
supabase-postgres-best-practices FAQ
Load it before writing or changing anything in a Postgres database: queries, schemas, indexes, migrations, RLS policies, or when diagnosing performance issues. It applies to even single-column changes or individual queries.
No. These are Postgres best practices maintained by Supabase but applicable to Postgres running anywhere—self-hosted, cloud providers, or Supabase.
Eight categories by priority: Query Performance (critical), Connection Management (critical), Security & RLS (critical), Schema Design (high), Concurrency & Locking (medium-high), Data Access Patterns (medium), Monitoring & Diagnostics (low-medium), and Advanced Features (low).
No. It covers schema correctness, migration safety, security (RLS), SQL authoring, and operations—not just performance optimization.
The skill includes guidance on pgvector (vector/semantic search), pgmq (queues), and pg_cron (scheduled jobs) alongside core Postgres practices.
Full instructions (SKILL.md)
Source of truth, from supabase/agent-skills.
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
Related skills
More from supabase/agent-skills and the wider catalog.

