supabase-postgres-best-practices

Provides prioritized Postgres performance optimization rules with incorrect and correct SQL examples.

Updated Apr 17, 2026
One-click install
npx skills add https://github.com/Syedyasir001/RVULibPass --skill supabase-postgres-best-practices-syedyasir001
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/Syedyasir001/RVULibPass/tree/main/.agent/skills/library/supabase-postgres-best-practices
Command: npx skills add https://github.com/Syedyasir001/RVULibPass --skill supabase-postgres-best-practices-syedyasir001

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Slow queries, connection exhaustion, and poorly designed schemas are common Postgres issues that are hard to diagnose without deep expertise. This Skill gives an AI agent a curated, impact-prioritized rule set so it can write, review, and optimize Postgres SQL correctly the first time. ## Core Features & Use Cases - Impact-Prioritized Rules: 8 categories ranked from CRITICAL (query performance, connection management, security/RLS) down to LOW (advanced features), each with quantified impact like "10-100x faster". - Error-First SQL Examples: Every rule shows an incorrect pattern with explanation followed by the correct SQL, covering indexes, pagination, N+1 elimination, connection pooling, RLS optimization, partitioning, and more. - Use Case: Ask the agent to review a slow query on a large orders table; it applies the missing-index and EXPLAIN ANALYZE rules to recommend a composite or partial index with expected performance gains. ## Quick Start Review my Postgres query and schema design using the Supabase best practices rules 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 WHERE and JOIN columns, which can yield 100-1000x speedups on large tables. Use EXPLAIN ANALYZE to identify sequential scans and rows removed by filters, then apply composite, partial, or covering indexes based on your query patterns.

What is the best way to handle Postgres connection pooling?▼

Use a pooler like PgBouncer between your application and Postgres, sizing the pool at roughly (CPU cores * 2) plus spindle count. Transaction mode works for most applications, but use session mode if you rely on named prepared statements or temporary tables.

How do I make Row Level Security policies faster in Postgres?▼

Wrap functions like auth.uid() in a subselect, such as (select auth.uid()), so they execute once instead of per row. Also add indexes on columns referenced in policies and use security definer functions for complex membership checks.

Should I use OFFSET or cursor-based pagination in Postgres?▼

Cursor-based (keyset) pagination is preferred because OFFSET scans all skipped rows, making deep pages progressively slower. Filtering with WHERE id > last_seen_id keeps performance constant regardless of page depth.

When should I partition a Postgres table?▼

Partition when tables exceed roughly 100 million 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.

Why does my Postgres migration fail with ADD CONSTRAINT IF NOT EXISTS?▼

Postgres does not support IF NOT EXISTS for ADD CONSTRAINT, causing a syntax error. Wrap the statement in a DO block that checks pg_constraint for the constraint name before executing ALTER TABLE.