supabase-postgres-best-practices

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

Updated Mar 23, 2026
One-click install
npx skills add https://github.com/Haseeb-Arshad/my-folio-book --skill supabase-postgres-best-practices-haseeb-arshad
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: supabase-postgres-best-practices
Source: https://github.com/Haseeb-Arshad/my-folio-book/tree/main/.continue/skills/supabase-postgres-best-practices
Command: npx skills add https://github.com/Haseeb-Arshad/my-folio-book --skill supabase-postgres-best-practices-haseeb-arshad

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing and changing Postgres schemas, queries, and RLS policies without established rules leads to slow queries, connection exhaustion, deadlocks, and data leaks. This Skill provides a prioritized rule set so every SQL change follows proven Postgres best practices. ## Core Features & Use Cases - Prioritized Rule Categories: Eight categories ranked by impact, from query performance and connection management (critical) to advanced features like full-text search and JSONB indexing. - Incorrect vs. Correct SQL Examples: Each rule file 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 performance-safe RLS patterns. - Use Case: Before writing a migration that adds a column and index to a multi-tenant orders table, load this Skill to get the correct index type, safe constraint syntax, and RLS policy pattern. ## Quick Start Load the supabase-postgres-best-practices skill and review my SQL migration for performance and security issues before I run it.

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 filters, then add indexes on WHERE and JOIN columns. The skill's query performance rules cover missing indexes, composite indexes, partial indexes, and covering indexes with measured impact.

How to write RLS policies in Postgres without hurting performance?▼

Wrap functions like auth.uid() in a SELECT subquery so they execute once instead of per row, and index every column used in policies. For complex checks, use SECURITY DEFINER functions in a private schema with EXECUTE revoked from public roles.

Does Postgres connection pooling work with prepared statements?▼

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 the connection persists.

Why does OFFSET pagination get slower on deep pages?▼

OFFSET scans and discards all skipped rows, so page 10000 reads hundreds of thousands of rows. Cursor-based pagination using WHERE id > last_seen_id uses the index directly and stays constant-time regardless of page depth.

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 instantly. Range partitioning by date lets queries scan only relevant partitions and makes retention a fast DROP TABLE.