# 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. Source: https://skillsagentes.com/skills/supabase/agent-skills/supabase-postgres-best-practices Repository: https://github.com/supabase/agent-skills Author: supabase License: MIT Updated: hace 15 días Context cost: 209 tok installed, 808 tok once triggered, 15.5k tok with every bundled file Bundle: 36 files, 61 KB Permissions requested: none declared ## Install ```bash npx -y skills add supabase/agent-skills --skill supabase-postgres-best-practices --agent claude-code ``` ## What it does - Aplica reglas de buenas prácticas de Postgres antes de crear o modificar tablas, columnas, migraciones, RLS, índices, triggers, funciones o colas - Guía el diagnóstico de consultas lentas, alto CPU, timeouts, planes EXPLAIN, agotamiento de conexiones, locking y bloat - Organiza las reglas en 8 categorías priorizadas por impacto, con ejemplos SQL correctos e incorrectos ## Use it when - Al escribir consultas SQL o diseñar esquemas - Al implementar índices u optimización de consultas - Al revisar problemas de rendimiento de la base de datos - Al trabajar con Row-Level Security (RLS) ## What triggers it - "Voy a crear una tabla nueva, ¿qué reglas de Postgres debo seguir" - "Esta consulta va lenta, ayúdame a diagnosticarla con EXPLAIN" - "Quiero escribir una política RLS para esta tabla" - "Necesito restaurar un dump con pg_restore, ¿hay algo que considerar" ## Files - CHANGELOG.md — 6 KB - SKILL.md — 3 KB - references/_contributing.md — 4 KB - references/_sections.md — 2 KB - references/_template.md — 1 KB - references/advanced-full-text-search.md — 1 KB - references/advanced-jsonb-indexing.md — 1 KB - references/conn-idle-timeout.md — 1 KB - references/conn-limits.md — 1 KB - references/conn-pooling.md — 1 KB - references/conn-prepared-statements.md — 1 KB - references/data-batch-inserts.md — 1 KB - references/data-n-plus-one.md — 1 KB - references/data-pagination.md — 1 KB - references/data-upsert.md — 1 KB - references/lock-advisory.md — 1 KB - references/lock-deadlock-prevention.md — 2 KB - references/lock-short-transactions.md — 1 KB - references/lock-skip-locked.md — 1 KB - references/monitor-explain-analyze.md — 1 KB - references/monitor-pg-stat-statements.md — 1 KB - references/monitor-vacuum-analyze.md — 1 KB - references/query-composite-indexes.md — 1 KB - references/query-covering-indexes.md — 1 KB - references/query-index-types.md — 1 KB - references/query-missing-indexes.md — 1 KB - references/query-partial-indexes.md — 1 KB - references/schema-constraints.md — 2 KB - references/schema-data-types.md — 1 KB - references/schema-foreign-key-indexes.md — 2 KB - references/schema-lowercase-identifiers.md — 2 KB - references/schema-partitioning.md — 2 KB - references/schema-primary-keys.md — 2 KB - references/security-privileges.md — 2 KB - references/security-rls-basics.md — 1 KB - references/security-rls-performance.md — 2 KB ## SKILL.md Reproduced verbatim from supabase/agent-skills under MIT. This section is the upstream document and is in English. # 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-security --- Skills Agentes — https://skillsagentes.com/skills/supabase/agent-skills/supabase-postgres-best-practices