supabase-postgres-best-practices

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

Updated Aug 28, 2026
One-click install
npx skills add https://github.com/Yash-Awasthi/adapfit --skill supabase-postgres-best-practices-yash-awasthi
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/Yash-Awasthi/adapfit/tree/main/.agents/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/Yash-Awasthi/adapfit --skill supabase-postgres-best-practices-yash-awasthi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing and maintaining Postgres schemas, queries, and RLS policies without proven guidelines 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 tested best practices. ## 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. - Incorrect vs. Correct SQL Examples: Each rule file shows the anti-pattern first, then the optimized rewrite, with quantified impact (e.g., 100x faster queries, 10x smaller indexes). - Diagnostics & Security Coverage: Guidance for EXPLAIN ANALYZE, pg_stat_statements, VACUUM tuning, RLS policy optimization, SECURITY DEFINER functions, and safe idempotent migrations. - Use Case: Before writing a migration that adds a column and index to a multi-tenant orders table, load this Skill to choose the right index type, write an idempotent constraint, and add a performant RLS policy. ## Quick Start Review my Postgres schema and slow query against the Supabase 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 to enable 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 membership 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 statements after use, or switch to session-mode pooling where the connection persists.

Why does my Postgres migration fail when adding a constraint?▼

Postgres does not support ADD CONSTRAINT IF NOT EXISTS, so that syntax throws a SQLSTATE 42601 error. Wrap the ALTER TABLE in a DO block that checks pg_constraint for the constraint name before adding it, making the migration 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.

What is the best primary key type for Postgres tables?▼

Use bigint generated always as identity for single-database sequential IDs. For distributed systems, use time-ordered UUIDv7 via the pg_uuidv7 extension instead of random UUIDv4, which causes index fragmentation on large tables.