supabase-postgres-best-practices

Provides Postgres performance optimization rules and SQL best practices for Supabase databases.

Updated Apr 15, 2026
One-click install
npx skills add https://github.com/shoshoavi/agentic_worflows --skill supabase-postgres-best-practices-shoshoavi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/shoshoavi/agentic_worflows/tree/main/cursor/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/shoshoavi/agentic_worflows --skill supabase-postgres-best-practices-shoshoavi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing and reviewing Postgres queries, schemas, and configurations without expert guidance often leads to slow queries, missing indexes, connection exhaustion, and insecure Row-Level Security policies that only surface in production. ## 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 rewrite, with quantified impact metrics and EXPLAIN output guidance. - Supabase-Specific Guidance: Covers RLS policy optimization, connection pooling modes, prepared statement handling, and Supabase platform configuration. - Use Case: When writing a migration that adds a foreign key or reviewing a slow endpoint, consult the relevant rule file to get the correct index strategy, pagination pattern, or RLS policy structure with ready-to-adapt SQL. ## Quick Start Ask the AI to review your Postgres query or schema design using the Supabase Postgres best practices skill 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 running EXPLAIN ANALYZE on the slow query to identify sequential scans, rows removed by filter, and buffer misses. Then add indexes on WHERE and JOIN columns, use composite indexes for multi-column filters, and consider partial or covering indexes for common query patterns.

How to fix N+1 queries in Postgres applications?▼

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

Does connection pooling work with prepared statements in Postgres?▼

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 the connection persists for the entire session.

Why is my RLS policy slow on large tables?▼

Functions like auth.uid() in policies are called once per row by default. Wrap them in a subselect like (select auth.uid()) so they execute once, add indexes on columns referenced in policies, and use security definer functions for complex membership checks.

When should I use OFFSET vs cursor pagination in Postgres?▼

OFFSET pagination scans all skipped rows, so it degrades linearly on deep pages. Cursor-based (keyset) pagination using WHERE id > last_seen_id with an index delivers constant O(1) performance regardless of page depth, making it the better choice for large tables.

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

Use a GIN index for JSONB containment queries with operators like @>, since the default B-tree cannot optimize them. Choose jsonb_path_ops for a 2-3x smaller index when you only need the @> operator, or create expression indexes for specific key lookups.