supabase-postgres-best-practices

Applies Postgres performance, schema, security, and migration rules to SQL authoring and optimization tasks.

Updated Aug 7, 2026
One-click install
npx skills add https://github.com/Ramadan-Elgamal/Autobees --skill supabase-postgres-best-practices-ramadan-elgamal
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/Ramadan-Elgamal/Autobees/tree/main/.agents/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/Ramadan-Elgamal/Autobees --skill supabase-postgres-best-practices-ramadan-elgamal

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing and changing Postgres schemas, queries, and RLS policies without established rules leads to slow queries, connection exhaustion, deadlocks, and data leaks. This Skill provides a prioritized rule set maintained by Supabase so every SQL change follows proven best practices. ## Core Features & Use Cases - Prioritized Rule Categories: Eight categories ranked by impact, from query performance and connection management (CRITICAL) 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 such as 10-100x faster queries. - Security & RLS Guidance: Covers Row Level Security policies, RLS performance optimization, SECURITY DEFINER functions, and least-privilege role design. - Use Case: When asked to add an index, design a multi-tenant table, write a migration, or diagnose a slow query, the agent loads the relevant reference file and produces SQL that follows the correct pattern, such as using partial indexes, cursor pagination, or idempotent constraint creation. ## Quick Start Review my Postgres schema and slow queries using the Supabase Postgres best practices rules and suggest optimized SQL.

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 indexes?

Add indexes on columns used in WHERE and JOIN clauses to avoid sequential scans, which can be 100-1000x slower on large tables. Use composite indexes for multi-column filters, partial indexes for filtered queries, and covering indexes with INCLUDE for index-only scans.

How do I write RLS policies in Postgres without hurting performance?

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. Always index columns referenced in policies and use security definer functions in a private schema for complex checks.

Does Postgres connection pooling work with prepared statements?

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

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 pagination using WHERE id > last_seen_id uses the index directly and stays O(1) regardless of page depth.

Can I use ADD CONSTRAINT IF NOT EXISTS in Postgres migrations?

No, Postgres does not support ADD CONSTRAINT IF NOT EXISTS and it raises a syntax error. Use a DO block that checks pg_constraint for the constraint name before running ALTER TABLE to make migrations idempotent.

When should I partition a Postgres table?

Partition tables exceeding roughly 100 million rows, time-series data queried by date ranges, or tables where you need to drop old data efficiently. Range partitioning by timestamp lets queries scan only relevant partitions and makes dropping old partitions instant.