supabase-postgres-best-practices

Provides Postgres performance optimization rules and SQL examples for query, schema, and security design.

1|Updated May 26, 2026
One-click install
npx skills add https://github.com/nimdvir/dima-publishing --skill supabase-postgres-best-practices-nimdvir
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/nimdvir/dima-publishing/tree/main/.continue/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/nimdvir/dima-publishing --skill supabase-postgres-best-practices-nimdvir

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Slow queries, missing indexes, connection exhaustion, and insecure Row-Level Security policies are common Postgres issues that are hard to diagnose without deep expertise. This Skill gives AI agents and developers a prioritized, example-driven rulebook for writing and reviewing performant, secure Postgres and Supabase databases. ## Core Features & Use Cases - Prioritized Rule Categories: Rules organized across 8 categories 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 file shows the anti-pattern first, then the optimized solution, with quantified impact metrics and EXPLAIN output guidance. - Supabase-Specific Guidance: Covers RLS policy optimization, SECURITY DEFINER functions, connection pooling modes, and prepared statement behavior with Supabase's pooler. - Use Case: When reviewing a migration that adds a foreign key without an index, or optimizing a paginated endpoint using OFFSET, reference the relevant rule file to get the correct SQL pattern with an explanation of why it is faster. ## Quick Start Ask the AI to review your Postgres query or schema design using the Supabase Postgres best practices rules 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 with missing indexes?▼

Add indexes on columns used in WHERE clauses and JOIN conditions to avoid sequential scans on large tables. Use EXPLAIN ANALYZE to confirm the query switches from a Seq Scan to an Index Scan, which can yield 100-1000x speedups.

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 pool of connections. Transaction mode works for most apps, but prepared statements require session mode or unnamed 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, and add indexes on columns referenced in policies. For complex checks, use SECURITY DEFINER functions with an explicit auth.uid() check inside.

Does Postgres automatically index foreign key columns?▼

No, Postgres does not automatically index foreign key columns, so JOINs and ON DELETE CASCADE operations can trigger full table scans. Always create an index on the referencing column manually.

Why is OFFSET pagination slow on large Postgres tables?▼

OFFSET scans and discards all skipped rows, so deep pages get progressively slower. Cursor-based (keyset) pagination using WHERE id > last_seen_id uses the index directly and stays O(1) 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 old-data deletion instant.