supabase-postgres-best-practices

Provides Postgres performance optimization rules and SQL patterns for Supabase databases.

Updated Jun 8, 2026
One-click install
npx skills add https://github.com/raulisai/eva02 --skill supabase-postgres-best-practices-raulisai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/raulisai/eva02/tree/main/.agents/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/raulisai/eva02 --skill supabase-postgres-best-practices-raulisai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing, reviewing, or optimizing Postgres queries and schemas without expert guidance often leads to slow queries, missing indexes, connection exhaustion, and insecure Row-Level Security policies. This Skill supplies a prioritized rule set of Postgres best practices so AI agents and developers produce performant, secure SQL from the start. ## Core Features & Use Cases - Prioritized Rule Library: 8 categories of rules 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 explanation followed by the correct SQL, including EXPLAIN output and quantified performance gains. - Security & RLS Guidance: Covers Row-Level Security policies, least-privilege grants, SECURITY DEFINER risks, and multi-tenant isolation patterns. - Use Case: When designing a new multi-tenant table, consult the schema and security rules to choose proper data types, index foreign keys, and write an RLS policy that enforces tenant isolation without hurting query performance. ## Quick Start Ask the agent to review your SQL query or schema design using the Postgres best practices rules and suggest optimized alternatives.

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 to identify bottlenecks like sequential scans or rows removed by filters. Then add indexes on WHERE and JOIN columns, use composite indexes for multi-column filters, and consider partial or covering indexes for targeted queries.

What index type should I use in Postgres?

Use B-tree for equality and range comparisons, GIN for JSONB containment and full-text search, GiST for geometric and range types, BRIN for large time-series tables, and hash for equality-only lookups. Choosing the right type can yield 10-100x improvements.

How do I make Row-Level Security policies fast in Supabase?

Wrap functions like auth.uid() in a SELECT subquery so they execute once instead of per row, and always index columns referenced in policies. For complex checks, use SECURITY DEFINER functions in a private schema with explicit auth.uid() validation.

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 after use, or switch to session-mode pooling where connections persist for the entire session.

Why is OFFSET pagination slow on large tables?

OFFSET scans and discards all skipped rows, so deep pages get progressively slower. Cursor-based (keyset) pagination using WHERE id > last_seen_id maintains constant O(1) performance regardless of page depth.

When should I partition a Postgres table?

Partition when tables exceed roughly 100 million 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 data retention instant via DROP TABLE.