supabase-postgres-best-practices

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing and changing Postgres schemas, queries, and RLS policies without proven 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 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 shows the anti-pattern first, then the optimized rewrite, with quantified impact such as 10-100x faster queries. - Security & RLS Guidance: Covers Row-Level Security policies, SECURITY DEFINER functions, least-privilege roles, and safe constraint migrations. - Use Case: When diagnosing a slow endpoint, load this Skill to check for missing indexes, N+1 queries, OFFSET pagination, or unoptimized RLS policies and apply the recommended SQL fixes. ## 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?▼

Start with EXPLAIN ANALYZE to find sequential scans and rows removed by filter, then add indexes on WHERE and JOIN columns. The query performance rules cover missing indexes, composite indexes, partial indexes, and covering indexes with measured speedups.

What index type should I use for Postgres JSONB columns?▼

Use a GIN index for JSONB containment queries with the @> operator, since B-tree indexes cannot optimize them. For single-key lookups, an expression index on attributes->>'key' is more efficient.

Does this Skill work with Postgres outside Supabase?▼

Yes, the rules apply to Postgres running anywhere, since they target core Postgres features like indexes, RLS, partitioning, and connection pooling. Supabase-specific notes are included only where relevant, such as auth.uid() in RLS policies.

How do I fix N+1 queries in Postgres?▼

Replace per-item queries in a loop with a single batch query using WHERE id = ANY($1::bigint[]) or a JOIN. This reduces database round trips from N+1 to one, typically improving throughput 10-100x.

Why is my RLS policy slow on large tables?▼

Functions like auth.uid() are called per row unless wrapped in a SELECT subquery, which caches the result. Also add indexes on columns referenced in policies and use security definer functions for complex membership checks.

When should I use cursor pagination instead of OFFSET?▼

Use cursor-based (keyset) pagination whenever queries page deep into large tables, because OFFSET scans all skipped rows and slows linearly. Cursor pagination with WHERE id > last_id stays O(1) regardless of page depth.