supabase-postgres-best-practices

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

Updated Mar 29, 2026
One-click install
npx skills add https://github.com/Divith123/Flamingo --skill supabase-postgres-best-practices-divith123
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/Divith123/Flamingo/tree/main/.agents/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/Divith123/Flamingo --skill supabase-postgres-best-practices-divith123

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Slow queries, connection exhaustion, and poorly designed schemas are the most common causes of Postgres performance issues, and diagnosing them requires deep expertise. This Skill gives you a curated, impact-prioritized rule set from Supabase so you can write, review, and optimize SQL with confidence. ## Core Features & Use Cases - Prioritized Rule Categories: Covers 8 categories ranked by impact, from critical query performance and connection management to advanced features like full-text search and JSONB indexing. - Error-First SQL Examples: Each rule shows an incorrect pattern with an explanation, followed by the corrected SQL, quantified impact, and references to official Postgres and Supabase documentation. - Use Case: When reviewing a slow endpoint, consult the query and index rules to identify missing indexes, N+1 query patterns, or OFFSET pagination, then apply the provided rewrites such as composite indexes or cursor-based pagination. ## Quick Start Ask the AI to review your Postgres query or schema design against the Supabase best practices rules and suggest optimized SQL.

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, then apply composite, partial, or covering indexes depending 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.

How do I fix N+1 query problems in Postgres?▼

Replace per-item queries in loops with a single batch query using WHERE id = ANY($1::bigint[]) or a JOIN. This reduces database round trips from N+1 to one, often improving performance 10-100x.

Does Row-Level Security slow down Postgres queries?▼

Poorly written RLS policies can, especially when functions like auth.uid() are called per row. Wrap function calls in a SELECT subquery so they execute once, and always index columns referenced in policies for 5-10x faster RLS queries.

When should I use cursor pagination instead of OFFSET?▼

Use cursor-based (keyset) pagination whenever users paginate deeply into large datasets. OFFSET scans all skipped rows and gets slower with page depth, while cursor pagination with WHERE id > last_id maintains constant O(1) performance.