supabase-postgres-best-practices

Provides Postgres performance optimization rules for writing and reviewing SQL queries and schemas.

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

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 a structured, prioritized rulebook of Postgres best practices so generated and reviewed SQL follows proven performance and security patterns. ## Core Features & Use Cases - Prioritized Rule Categories: 8 categories 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, then the correct SQL rewrite with quantified impact (e.g., 10-100x faster queries). - Supabase-Specific Guidance: Covers RLS policy optimization, SECURITY DEFINER functions, connection pooling modes, and prepared statement handling in pooled environments. - Use Case: When designing an orders table for a multi-tenant app, the agent applies rules to index foreign keys, enable RLS with optimized policies, choose proper data types, and write idempotent migration constraints. ## Quick Start Ask the agent to review your Postgres schema or SQL query for performance and security issues using the Supabase best practices rules.

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 and rows removed by filters, then apply composite, partial, or covering indexes matching your query patterns.

What is the best way to handle Postgres connection pooling?▼

Use a pooler like PgBouncer between your application and Postgres, sizing the pool at roughly (CPU cores x 2). Transaction mode suits most applications, but prepared statements and temporary tables 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, giving 100x+ improvements on large tables. Always index columns referenced in policies and use security definer functions for complex membership checks.

Does Postgres automatically index foreign key columns?▼

No, Postgres does not index foreign key columns automatically. Missing FK indexes cause slow JOINs and table-scanning CASCADE deletes, so create an index on every referencing column explicitly.

Why does OFFSET pagination get slower on deeper pages?▼

OFFSET scans and discards all skipped rows, so page 10000 reads hundreds of thousands of rows. 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, contain time-series data queried by date ranges, or require efficient bulk deletion of old data. Range partitioning by timestamp lets queries scan only relevant partitions and makes dropping old data instant.