supabase-postgres-best-practices

Provides prioritized Postgres performance optimization rules for queries, schemas, connections, and RLS policies.

1|Updated May 10, 2026
One-click install
npx skills add https://github.com/Tgoldi/claude-skills --skill supabase-postgres-best-practices-tgoldi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/Tgoldi/claude-skills/tree/main/supabase-postgres-best-practices
Command: npx skills add https://github.com/Tgoldi/claude-skills --skill supabase-postgres-best-practices-tgoldi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Slow queries, missing indexes, connection exhaustion, and poorly written RLS policies are the most common causes of Postgres performance issues, and diagnosing them requires deep database expertise. This Skill gives you a prioritized, rule-based reference so you can write, review, and optimize Postgres SQL correctly the first time. ## Core Features & Use Cases - Prioritized Rule Set: 30+ optimization rules organized into 8 categories ranked by impact, from critical query performance and connection management to advanced JSONB indexing and full-text search. - Incorrect vs. Correct SQL Examples: Every rule shows a failing pattern alongside the optimized version, with EXPLAIN output and quantified impact (e.g., 100-1000x faster queries with proper indexes). - Supabase-Specific Guidance: Covers Row Level Security policy optimization, connection pooling modes, and auth.uid() performance patterns specific to Supabase deployments. - Use Case: When reviewing a slow endpoint, consult the query performance rules to identify missing indexes, then apply composite or partial index patterns and verify with EXPLAIN ANALYZE. ## Quick Start Ask the AI to review your SQL query or schema design against Postgres best practices and suggest optimizations.

Frequently Asked Questions about supabase-postgres-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize slow Postgres queries?

Start by adding indexes on columns used in WHERE and JOIN clauses, which can yield 100-1000x speedups on large tables. Use EXPLAIN ANALYZE to confirm whether the planner uses an index scan instead of a sequential scan, then consider composite, partial, or covering indexes for multi-column or filtered queries.

What index type should I use in Postgres?

B-tree is the default and handles equality and range comparisons. Use GIN for JSONB, arrays, and full-text search, BRIN for large time-series tables, and Hash for equality-only lookups. Choosing the right type can improve queries 10-100x.

How do I make Supabase RLS policies faster?

Wrap functions like auth.uid() in a SELECT subquery so they execute once instead of per row, which can be 100x faster on large tables. Add indexes on columns referenced in policies and use security definer functions for complex membership checks.

Does connection pooling work with prepared statements?

Named prepared statements fail in transaction-mode pooling because connections are shared between requests. Use unnamed prepared statements, deallocate statements after use, or switch to session-mode pooling where connections persist for the whole session.

When should I partition a Postgres table?

Partition when tables exceed roughly 100M rows, when queries filter by time ranges, or when you need to drop old data efficiently. Range partitioning by date lets queries scan only relevant partitions and makes dropping old partitions instant compared to DELETE.

Why is OFFSET pagination slow in Postgres?

OFFSET forces the database to scan and discard all skipped rows, so deep pages get progressively slower. Cursor-based (keyset) pagination using WHERE id > last_seen_id uses the index directly and maintains constant O(1) performance regardless of page depth.