supabase-postgres-best-practices

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

2|1|Updated Jun 9, 2026
One-click install
npx skills add https://github.com/zester4/zilmate --skill supabase-postgres-best-practices-zester4
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/zester4/zilmate/tree/main/.agents/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/zester4/zilmate --skill supabase-postgres-best-practices-zester4

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 costly to fix later. ## Core Features & Use Cases - Prioritized Rule Library: 8 categories of Postgres best practices 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 solution with quantified impact metrics and EXPLAIN output guidance. - Supabase-Specific Guidance: Covers RLS policy optimization, SECURITY DEFINER functions, connection pooling modes, and prepared statement handling in pooled environments. - Use Case: When reviewing a slow multi-tenant query, consult the RLS performance and missing indexes references to rewrite the policy with cached auth.uid() calls and add the right composite index. ## Quick Start Ask the agent to review your Postgres query or schema design using the Supabase Postgres best practices guidelines and suggest optimizations.

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 missing indexes?

Add indexes on columns used in WHERE and JOIN clauses to replace sequential scans with index scans, which can be 100-1000x faster on large tables. Use EXPLAIN ANALYZE to confirm the query plan changes from Seq Scan to Index Scan.

How to fix N+1 query problems in Postgres applications?

Replace per-item queries in loops with a single batch query using WHERE id = ANY($1::bigint[]) or a JOIN. This reduces database round trips from N+1 to one, cutting latency by 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 after use, or switch to session-mode pooling where connections persist.

Why is my Row-Level Security policy slow on large tables?

RLS policies calling functions like auth.uid() per row cause severe slowdowns. Wrap the function in a SELECT subquery so it executes once, and add indexes on columns referenced in the policy.

When should I use cursor pagination instead of OFFSET in Postgres?

Use cursor-based pagination whenever users page deeply into results, since OFFSET scans all skipped rows and slows linearly. Keyset pagination with WHERE id > last_seen_id stays O(1) regardless of page depth.

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

Use a GIN index for JSONB containment queries with the @> operator, since the default B-tree cannot optimize them. Choose jsonb_path_ops for a 2-3x smaller index when only containment queries are needed.