supabase-postgres-best-practices

Provides Postgres performance optimization rules for writing, reviewing, and optimizing SQL queries and schemas.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Postgres databases often suffer from slow queries, connection exhaustion, missing indexes, and insecure configurations that are hard to diagnose without deep expertise. This Skill gives AI agents and developers a structured, prioritized rule set to write, review, and optimize Postgres queries, schemas, and configurations correctly the first time. ## Core Features & Use Cases - Prioritized Rule Categories: 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 with explanation, then the correct SQL with quantified impact metrics (e.g., 10-100x faster queries). - Supabase-Specific Guidance: Covers Row-Level Security policies, connection pooling modes, prepared statement handling, and auth-aware optimization patterns. - Use Case: When writing a migration that adds a foreign key, the agent consults the schema rules and automatically adds the required index on the FK column, avoiding slow JOINs and CASCADE operations. ## Quick Start Ask the agent to review your SQL query or schema design against Postgres best practices, for example: review this orders table schema and optimize my slow pagination query.

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 running EXPLAIN ANALYZE on the slow query to identify sequential scans and missing indexes. Add indexes on WHERE and JOIN columns, use composite indexes for multi-column filters, and consider partial or covering indexes for filtered queries.

What is the best way to handle Postgres connection pooling?

Use a pooler like PgBouncer between your application and Postgres so many concurrent users share a small connection pool. Size the pool around (CPU cores x 2), and prefer transaction mode unless you need session-level features like named prepared statements.

Does this skill cover Supabase Row Level Security?

Yes, it includes rules for enabling RLS on multi-tenant tables and optimizing RLS policy performance. Key patterns include wrapping auth.uid() in a SELECT subquery and adding indexes on columns referenced in policies.

Why is OFFSET pagination slow in Postgres?

OFFSET scans and discards all skipped rows, so deep pages get progressively slower. Cursor-based (keyset) pagination using WHERE id > last_seen_id uses the index directly and stays O(1) regardless of page depth.

When should I use GIN indexes instead of B-tree?

Use GIN indexes for JSONB containment queries, array columns, and full-text search with tsvector, since B-tree cannot support those operators. B-tree remains the right default for equality, range, and sorting on scalar columns.