.cursor/skills/supabase-postgres-best-practices/SKILL.md
Postgres performance optimization and best practices for Supabase, maintained from Supabase's official guidance for AI agents. Covers query performance, indexes, connection management, RLS, schema design, concurrency, and monitoring. Use when writing SQL or designing schemas, adding indexes, reviewing database performance, configuring connection pooling, or working with Row-Level Security (RLS).
npx skillsauth add ripgraphics/authorsinfo supabase-postgres-best-practicesInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Comprehensive performance optimization guide for Postgres on Supabase, aligned with Supabase's Postgres Best Practices for AI Agents. Apply these rules when writing SQL, designing schemas, or diagnosing performance.
Reference these guidelines when:
| Priority | Category | Impact | Focus | |----------|------------------------|------------|--------------------------| | 1 | Query Performance | CRITICAL | EXPLAIN, indexes | | 2 | Connection Management | CRITICAL | Pooling, limits | | 3 | Security & RLS | CRITICAL | Policies, least privilege| | 4 | Schema Design | HIGH | Types, constraints | | 5 | Concurrency & Locking | MEDIUM-HIGH| Locks, transactions | | 6 | Data Access Patterns | MEDIUM | Batching, pagination | | 7 | Monitoring & Diagnostics | LOW-MEDIUM| Stats, slow queries | | 8 | Advanced Features | LOW | Extensions, pgvector |
Use EXPLAIN (ANALYZE, BUFFERS, VERBOSE) to inspect plans. Look for Sequential Scans on large tables, high cost estimates, and unnecessary nested loops. Supabase provides index_advisor for suggesting beneficial indexes.
EXPLAIN (ANALYZE, BUFFERS, VERBOSE) SELECT ... ;
sign_up_date, status).-- Single column
CREATE INDEX idx_orders_customer_id ON orders (customer_id);
CREATE INDEX idx_customers_sign_up_date ON customers (sign_up_date);
-- ORDER BY + LIMIT
CREATE INDEX idx_orders_date_of_purchase ON orders (date_of_purchase);
Choose the type that fits the data and access pattern:
| Type | Use case |
|---------|----------|
| B-tree | Default; equality and range, ORDER BY. |
| BRIN | Chronologically increasing columns (e.g. created_at); often 10x smaller than B-tree. |
| GIN | JSONB, arrays, full-text. |
| Hash | Equality only (Postgres 10+). |
-- BRIN for time-ordered, append-heavy tables
CREATE INDEX idx_orders_created_at ON orders USING BRIN (created_at);
Index only the rows that matter. The query's WHERE must match the index predicate.
CREATE INDEX idx_orders_shipped ON orders (date_of_purchase)
WHERE status = 'shipped';
When filtering or joining on multiple columns, one composite index can avoid multiple index lookups. Order columns by selectivity (most selective first) unless the query has ORDER BY on a prefix.
CREATE INDEX idx_customers_sign_up_priority ON customers (sign_up_date, priority);
Indexes speed reads but slow writes. Only index columns used frequently in WHERE, JOIN, or ORDER BY. Remove indexes that don't improve the query plan.
Keep planner statistics up to date so it can choose indexes correctly. Run ANALYZE after bulk changes or periodically.
ANALYZE customers;
max_connections; do not assume unlimited connections.uuid, timestamptz, numeric for money).NOT NULL and constraints where the domain requires it.SELECT ... FOR UPDATE only when necessary and with a short transaction.LIMIT + keyset or offset) for large result sets; avoid unbounded SELECT *.SELECT * when wide tables are involved.pg_stat_* views and Supabase dashboard metrics to spot slow queries and connection usage.npx skills add supabase/agent-skills --skill supabase-postgres-best-practicesFor per-rule details and more examples, see reference.md or the official skill references.
tools
Webpack build optimization expert with deep knowledge of configuration patterns, bundle analysis, code splitting, module federation, performance optimization, and plugin/loader ecosystem. Use PROACTIVELY for any Webpack bundling issues including complex optimizations, build performance, custom plugins/loaders, and modern architecture patterns. If a specialized expert is a better fit, I will recommend switching and stop.
development
Web application security expert. OWASP Top 10, XSS, SQLi, CSRF, SSRF, authentication bypass, IDOR. Use for web app security testing.
testing
Vitest testing framework expert for Vite integration, Jest migration, browser mode testing, and performance optimization
tools
Vite build optimization expert with deep knowledge of ESM-first development, HMR optimization, plugin ecosystem, production builds, library mode, and SSR configuration. Use PROACTIVELY for any Vite bundling issues including dev server performance, build optimization, plugin development, and modern ESM patterns. If a specialized expert is a better fit, I will recommend switching and stop.