supabase-postgres-best-practices

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

Updated Apr 7, 2026
One-click install
npx skills add https://github.com/NT-boop-star/BRMV-tract --skill supabase-postgres-best-practices-nt-boop-star
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/NT-boop-star/BRMV-tract/tree/main/antigravity/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/NT-boop-star/BRMV-tract --skill supabase-postgres-best-practices-nt-boop-star

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Postgres queries, schemas, and configurations often suffer from slow performance, connection exhaustion, and unsafe security patterns that are hard to diagnose without deep expertise. This Skill gives you a curated, impact-prioritized rule set so you can write, review, and optimize Postgres code with confidence. ## Core Features & Use Cases - Impact-Prioritized Rules: 8 categories ranked from CRITICAL (query performance, connection management, security/RLS) to LOW (advanced features), each with quantified impact like "10-100x faster". - Error-First SQL Examples: Every rule shows an incorrect pattern with explanation, then the correct SQL, plus optional EXPLAIN output and metrics. - Use Case: When reviewing a slow endpoint, consult the query and index rules to identify missing indexes, N+1 queries, or OFFSET pagination, then apply the provided corrected SQL directly. ## Quick Start Ask the AI to review your Postgres query or schema against the Supabase best practices 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 find sequential scans, then apply composite, partial, or covering indexes depending on your query filters.

What is the best way to handle Postgres connection pooling?

Use a pooler like PgBouncer between your application and Postgres so hundreds of concurrent users share a small pool of connections. Set pool_size around (CPU cores * 2) and prefer transaction mode unless you need prepared statements or temp tables.

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

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. Also add indexes on columns referenced in policies and use security definer functions for complex checks.

Does this cover N+1 query problems in application code?

Yes, it includes a rule for eliminating N+1 queries by batching with WHERE id = ANY(array) or using JOINs instead of per-item loops. Examples show both pure SQL and application-level patterns with array parameters.

When should I use cursor pagination instead of OFFSET in Postgres?

Use cursor-based (keyset) pagination whenever users page deeply into results, since OFFSET scans all skipped rows and slows linearly. Cursor pagination with WHERE id > last_id stays O(1) regardless of page depth.

Why do prepared statements fail with transaction-mode pooling?

Named prepared statements are tied to individual connections, but transaction-mode pooling reassigns connections per transaction, causing 'prepared statement does not exist' errors. Use unnamed statements, deallocate after use, or switch to session mode.