supabase-postgres-best-practices

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

2|Updated May 30, 2026
One-click install
npx skills add https://github.com/virahitvin8/crafty-gis --skill supabase-postgres-best-practices-virahitvin8
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/virahitvin8/crafty-gis/tree/main/GIT_STAR/assignment-generator/antigravity-skills-main/antigravity-skills-main/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/virahitvin8/crafty-gis --skill supabase-postgres-best-practices-virahitvin8

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 developers often lack a prioritized, example-driven reference when writing or reviewing SQL. ## Core Features & Use Cases - Prioritized Rule Library: Rules organized across 8 categories (query performance, connection management, security & RLS, schema design, locking, data access, monitoring, advanced features) ranked by impact from CRITICAL to LOW. - Error-First SQL Examples: Each rule shows an incorrect pattern with explanation followed by the corrected SQL, covering indexes, pagination, N+1 elimination, RLS optimization, and connection pooling. - Use Case: When writing a migration that adds a foreign key or reviewing a slow endpoint, consult the relevant reference file to apply the correct index type, batching pattern, or RLS policy structure with quantified performance impact. ## Quick Start Review my Postgres schema and queries 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 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 is the best way to handle Postgres connection pooling?

Use a pooler like PgBouncer between your application and Postgres so many concurrent users share a small connection pool. Size the pool around (CPU cores * 2) and prefer transaction mode unless you need session-level prepared statements.

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

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.

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

Cursor-based (keyset) pagination is preferred because OFFSET scans all skipped rows, getting slower on deeper pages. 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 100M 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 old-data removal instant.

Why do prepared statements fail with transaction-mode pooling?

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