Supabase Postgres Best Practices

by supabasec9be0e931b79MITListed Oct 8, 2026Updated Oct 8, 2026

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.

AI-generated overview

Reference rules for writing, reviewing and optimizing Postgres schemas, queries, indexes, RLS and connections.

What it does
Provides a prioritized set of Postgres best-practice rules across eight categories: query performance, connection management, security and RLS, schema design, concurrency and locking, data access patterns, monitoring and diagnostics, and advanced features. Each rule file explains why the topic matters and shows incorrect versus correct SQL examples, with optional EXPLAIN output and metrics. It is an instructions-only reference and produces no files or scripts.
When to use it
Load it before writing or changing anything in a Postgres database, including tables, columns, migrations, RLS policies, indexes, triggers, functions, queues, scheduled jobs, vector search, or data imports. Also use it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant.
Requirements
No tools, packages or credentials are required; it is documentation only and ships no scripts. Network access is not needed, though the document links to external Postgres and Supabase documentation.

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.mdreferences/query-partial-indexes.mdreferences/_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

Source and attribution

Source:supabase/agent-skillsinskills/supabase-postgres-best-practicesat commitc9be0e9

License: MIT

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal