supabase-postgres-best-practices

Provides Postgres performance optimization rules and SQL examples for queries, schemas, and configurations.

Updated May 2, 2026
One-click install
npx skills add https://github.com/FadhilAlif/jejak_karier --skill supabase-postgres-best-practices-fadhilalif
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/FadhilAlif/jejak_karier/tree/main/.agents/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/FadhilAlif/jejak_karier --skill supabase-postgres-best-practices-fadhilalif

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing and reviewing Postgres queries, schemas, and configurations without expert guidance often leads to slow queries, missing indexes, connection exhaustion, and insecure Row-Level Security policies that are hard to diagnose later. ## Core Features & Use Cases - Prioritized Rule Library: 30+ performance rules organized into 8 categories (query performance, connection management, security & RLS, schema design, locking, data access, monitoring, advanced features), ranked from CRITICAL to LOW impact. - Incorrect vs. Correct SQL Examples: Every rule shows the anti-pattern first, then the optimized rewrite, with quantified impact such as "100-1000x faster queries" or "10x smaller index". - Supabase-Specific Guidance: Covers connection pooling modes, RLS policy optimization with auth.uid(), and prepared statement behavior in pooled environments. - Use Case: When asked to review a slow endpoint, consult the query-missing-indexes and data-n-plus-one rules to rewrite sequential scans and looped queries into indexed, batched SQL. ## 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 by adding indexes on WHERE and JOIN columns to eliminate sequential scans, then use EXPLAIN ANALYZE to confirm the query plan. The query performance rules cover composite indexes, partial indexes, covering indexes, and choosing the right index type such as GIN for JSONB.

How to fix N+1 queries in Postgres applications?

Replace per-item queries in loops with a single batch query using WHERE id = ANY($1) with an array parameter, or rewrite the logic as a JOIN. This reduces database round trips from N+1 to one, often improving throughput 10-100x.

Does connection pooling work with prepared statements in Postgres?

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.

How do I make Row Level Security policies faster?

Wrap functions like auth.uid() in a SELECT subquery so they execute once instead of per row, and add indexes on columns referenced in policies. For complex checks, use security definer functions to avoid per-row evaluation overhead.

When should I partition a Postgres table?

Partition when tables exceed roughly 100 million rows, when queries filter by time ranges, or when you need to drop old data efficiently. Range partitioning by date lets queries scan only relevant partitions and makes old-data deletion instant via DROP TABLE.

Why is OFFSET pagination slow on large tables?

OFFSET forces Postgres to scan and discard all skipped rows, so deep pages get progressively slower. Cursor-based (keyset) pagination using WHERE id > last_seen_id uses the index directly and maintains constant performance regardless of page depth.