supabase-postgres-best-practices

Provides Postgres performance optimization rules and SQL examples for Supabase database development.

Updated May 14, 2026
One-click install
npx skills add https://github.com/jesusprodriguezUnir/bracketMundial --skill supabase-postgres-best-practices-jesusprodriguezunir
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/jesusprodriguezUnir/bracketMundial/tree/main/.agents/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/jesusprodriguezUnir/bracketMundial --skill supabase-postgres-best-practices-jesusprodriguezunir

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing efficient Postgres queries and schemas is hard, and common mistakes like missing indexes, N+1 queries, or unoptimized RLS policies cause severe performance degradation that is difficult to diagnose without deep database expertise. ## Core Features & Use Cases - Prioritized Rule Library: 8 categories of performance rules ranked by impact, from critical query performance and connection management to advanced features like full-text search and JSONB indexing. - Incorrect vs. Correct SQL Examples: Each rule shows the anti-pattern first, then the optimized solution with quantified impact metrics (e.g., 10-100x faster queries). - Supabase-Specific Guidance: Covers Row-Level Security optimization, connection pooling modes, and prepared statement handling in pooled environments. - Use Case: When writing a migration that adds a foreign key or reviewing a slow query on a multi-tenant table, reference the relevant rule file to get the correct index strategy and RLS policy pattern immediately. ## Quick Start Ask the AI to review your Postgres query or schema design using the Supabase Postgres best practices guidelines.

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 in Supabase?▼

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 based on your query patterns.

What index type should I use for JSONB columns in Postgres?▼

Use a GIN index for JSONB containment queries with the @> operator, since B-tree indexes cannot optimize them. For single-key lookups, an expression index on the specific key is more efficient.

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) with an array parameter, or use a JOIN. This reduces database round trips from N+1 to one, improving performance 10-100x.

Does connection pooling work with prepared statements in Supabase?▼

Named prepared statements fail in transaction-mode pooling because connections are shared between requests. Use unnamed prepared statements, deallocate after use, or switch to session mode on port 5432.

Why is my RLS policy slow on large tables?▼

Functions like auth.uid() are called per row unless wrapped in a SELECT subquery, which caches the result. Also add indexes on columns referenced in policies and use security definer functions for complex checks.

When should I partition a Postgres table?▼

Partition tables exceeding 100M rows, time-series data queried by date ranges, or tables where you need to drop old data efficiently. Range partitioning by timestamp enables 5-20x faster queries and instant partition drops.