supabase-postgres-best-practices

Provides Postgres best-practice rules for schema design, query optimization, security, and migrations.

3|Updated Jul 28, 2026
One-click install
npx skills add https://github.com/marcmarti9/agentit --skill supabase-postgres-best-practices-marcmarti9
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/marcmarti9/agentit/tree/main/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/marcmarti9/agentit --skill supabase-postgres-best-practices-marcmarti9

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing or changing anything in a Postgres database without established rules leads to slow queries, missing indexes, connection exhaustion, insecure RLS policies, and failed migrations. This Skill gives an AI agent a prioritized, Supabase-maintained rule set so every schema change, query, or migration follows proven Postgres practices. ## Core Features & Use Cases - Prioritized rule library: 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, a corrected pattern, quantified impact, and EXPLAIN or metrics context. - Security and RLS guidance: Covers Row-Level Security policies, SECURITY DEFINER functions, least-privilege roles, and RLS performance optimization. - Use Case: Before writing a migration that adds a column and an RLS policy, load this Skill so the agent applies idempotent constraint patterns, indexes the foreign key, and wraps auth.uid() in a subquery for performance. ## Quick Start Review my Postgres schema and queries using the Supabase Postgres best practices skill and fix any performance or security issues you find.

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 with EXPLAIN ANALYZE to find sequential scans and rows removed by filter, then add indexes on WHERE and JOIN columns. The query-missing-indexes and monitor-explain-analyze references show the exact diagnostic and fix patterns.

What index type should I use in Postgres?▼

Use B-tree for equality and range queries, GIN for JSONB, arrays, and full-text search, GiST for geometric and nearest-neighbor queries, and BRIN for large time-series tables. The query-index-types reference maps each operator pattern to the right index.

Does this skill work with Postgres outside Supabase?▼

Yes, the rules apply to Postgres running anywhere, since they cover core database behavior like indexing, locking, and query planning. Some references include Supabase-specific notes for features like auth.uid() and the connection pooler.

How do I make RLS policies faster in Postgres?▼

Wrap functions like auth.uid() in a SELECT subquery so they execute once instead of per row, and index every column used in policies. For complex checks, use SECURITY DEFINER functions in a private schema with EXECUTE revoked from public roles.

Why does ADD CONSTRAINT IF NOT EXISTS fail in Postgres migrations?▼

Postgres does not support IF NOT EXISTS for ADD CONSTRAINT, so that syntax raises error 42601. Use a DO block that checks pg_constraint for the constraint name before altering the table, making migrations idempotent.

When should I use connection pooling with Postgres?▼

Use pooling for all applications, since each Postgres connection consumes 1-3MB of RAM and high concurrency exhausts max_connections. A pooler like PgBouncer in transaction mode lets hundreds of users share a small pool of connections.