supabase-postgres-best-practices

Provides Postgres optimization rules for schema design, indexing, RLS, and query performance.

Updated Jul 31, 2026
One-click install
npx skills add https://github.com/Rasslonely/NexusXRP --skill supabase-postgres-best-practices-rasslonely
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/Rasslonely/NexusXRP/tree/main/.agents/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/Rasslonely/NexusXRP --skill supabase-postgres-best-practices-rasslonely

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, deadlocks, and insecure Row-Level Security policies. This Skill gives AI agents and developers a prioritized, example-driven rule set so schema changes, migrations, and SQL queries follow proven Postgres best practices from the start. ## Core Features & Use Cases - Prioritized Rule Categories: Eight categories 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: Every rule shows the anti-pattern first, then the optimized rewrite, with quantified impact such as 10-100x faster queries or 50% smaller indexes. - Security & RLS Guidance: Covers Row-Level Security policy design, RLS performance optimization, SECURITY DEFINER pitfalls, and least-privilege role management. - Use Case: When asked to add a new column, write a migration, design a multi-tenant table, or diagnose a slow query, the agent loads the relevant reference file (e.g., references/query-missing-indexes.md) and applies the correct pattern with proper indexes and constraints. ## Quick Start Ask the agent to review your Postgres schema or SQL query using the Supabase Postgres best practices before writing any migration or database change.

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, then use EXPLAIN ANALYZE to confirm the query plan changed from a sequential scan to an index scan. The query performance rules cover missing indexes, composite indexes, partial indexes, and covering indexes with quantified impact.

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, not only Supabase-hosted databases. Supabase-specific notes, such as auth.uid() in RLS policies, are marked separately where applicable.

How do I write RLS policies without hurting performance?

Wrap functions like auth.uid() in a SELECT subquery so they execute once instead of per row, and always index columns referenced in policies. For complex checks, use SECURITY DEFINER functions in a private schema with explicit identity checks.

Why does my Postgres migration fail when adding constraints?

Postgres does not support ADD CONSTRAINT IF NOT EXISTS, so that syntax throws a SQLSTATE 42601 error. Use a DO block that checks pg_constraint for the constraint name before running ALTER TABLE.

When should I use cursor pagination instead of OFFSET?

Use cursor-based (keyset) pagination whenever queries page deep into a table, because OFFSET scans all skipped rows and slows down linearly. Filtering with WHERE id > last_seen_id keeps performance constant regardless of page depth.