Skip to content
AI Skills Central

Type to search Agent Skills, workflows, tutorials, tools and the glossary.

Agent Skill

Postgres best practices (Supabase)

Supabase's Postgres rules for schema, indexes, RLS, migrations, connections and slow queries. Works for Postgres anywhere, not just Supabase.

name: supabase-postgres-best-practicesBy SupabaseChecked
View source on GitHub
Bookmark

Bookmarks are kept in your free account, so you can find this page again on any device.

Sign in to bookmark

Install

Commands are pinned to commit c9be0e9, the version we read, wherever the install method supports it.

npx skills

Terminal
npx skills add supabase/agent-skills@c9be0e931b7930f7d02126d04774d904c381e7d7 --skill supabase-postgres-best-practices -a claude-code

Copies the skill into .claude/skills/ in this project, pinned to the reviewed commit.

Plugin marketplace

Claude Code prompt
/plugin marketplace add supabase/agent-skills
/plugin install postgres-best-practices@supabase-agent-skills

Run inside Claude Code. Installs the whole postgres-best-practices plugin from its default branch, not the pinned commit.

What it does

A short SKILL.md that acts as an index into about 35 reference files, each one rule: connection pooling and limits, prepared statements, batch inserts, N+1 queries, pagination, upserts, advisory locks, deadlock prevention, SKIP LOCKED, EXPLAIN reading, JSONB indexing, full-text search and more. The description is deliberately broad so the agent loads it for any database change, even a single column.

When to use it

Any Postgres work where performance and correctness matter: designing tables, adding indexes, writing queries that will run at scale, fixing connection exhaustion, or reviewing a migration. The advice applies to Postgres anywhere, not only on Supabase.

Each reference file is one rule with an explanation and an example, so the agent loads only the rules that apply to the change in front of it rather than the whole collection.

When to skip it

Analytical warehouse SQL, which SQL queries covers. If you only use Postgres through an ORM and never look at the SQL, much of it will not reach your code, though the indexing advice still applies.

Try it

Review this migration and the queries in src/db/orders.ts for
performance problems at 10 million rows. Read EXPLAIN output for the two
slowest queries and propose indexes.

What it can touch

Bundles scripts
No
Pre-approved tools
None declared
Needs
Nothing beyond the agent
Client-specific fields
None, spec fields only

Its instructions steer what your agent does, and it may have changed since the commit we read. How to check a skill.

Instructions only. Because it triggers on almost any SQL work, it will load often; that is the intent.

At commit c9be0e9 the SKILL.md is 65 lines long. Alongside it:

  • references/ (34 entries)
  • CHANGELOG.md

Alternatives

Supabase for the platform around the database, Neon Postgres for Neon-specific setup, and Prisma ORM setup if you work through Prisma.

SKILL.md

The file exactly as published at the reviewed commit, reproduced under its MIT licence.

skills/supabase-postgres-best-practices/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

| 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
  • Neon Postgres

    Neon's guide to connections, pooled vs direct, migrations, branching per PR, autoscaling, scale-to-zero, egress and search on Neon Postgres.

    Checked at d3601d9

  • SQL queries

    Writes correct, fast SQL across PostgreSQL, Snowflake, BigQuery, Redshift and Databricks, with patterns for windows, cohorts, funnels and deduplication.

    Data analysis and BIAnthropicChecked at b4c9a4e

  • ClickHouse best practices

    ClickHouse's own review rules: checks schemas, queries and inserts against 36 rule files, cites each rule, and caps every query an agent runs on your data.

    Checked at 1008fd7