Skip to content
cccskills
FreePublished on GitHub

supabase-postgres-best-practices

PostgreSQL performance optimization guidelines from Supabase. Apply when writing SQL, designing schemas, configuring RLS, or optimizing database performance.

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md3.9 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

Supabase PostgreSQL Best Practices

Source: https://github.com/supabase/agent-skills

Rule Categories (Prioritized by Impact)

PriorityCategoryImpactPrefix
1Query PerformanceCRITICALquery-
2Connection ManagementCRITICALconn-
3Security & RLSCRITICALsecurity-
4Schema DesignHIGHschema-
5Concurrency & LockingMEDIUM-HIGHlock-
6Data Access PatternsMEDIUMdata-
7Monitoring & DiagnosticsLOW-MEDIUMmonitor-
8Advanced FeaturesLOWadvanced-

1. Query Performance (CRITICAL)

  • Always add indexes for columns used in WHERE, JOIN, and ORDER BY clauses
  • Use partial indexes for filtered queries: CREATE INDEX idx_active ON users(email) WHERE active = true
  • Prefer EXISTS over IN for subqueries
  • Avoid SELECT * - specify only needed columns
  • Use EXPLAIN ANALYZE to verify query plans
  • Add composite indexes for multi-column queries (column order matters)
  • Use covering indexes to avoid heap lookups

2. Connection Management (CRITICAL)

  • Use Supabase connection pooler (PgBouncer) for serverless/edge functions
  • Use transaction mode for short-lived queries
  • Use session mode only when needed (prepared statements, advisory locks)
  • Set appropriate pool size limits
  • Release connections promptly - avoid holding connections during external calls
  • Use connection timeouts to prevent leaks

3. Security & RLS (CRITICAL)

  • Enable RLS on ALL tables exposed via Supabase API
  • Write policies using auth.uid() and auth.jwt()
  • Avoid functions marked SECURITY DEFINER unless necessary
  • Use SECURITY INVOKER as default for functions
  • Never trust client-side data - validate in policies
  • Test RLS policies with different roles
  • Use USING for read policies, WITH CHECK for write policies

4. Schema Design (HIGH)

  • Use appropriate data types (e.g., uuid for IDs, timestamptz for times)
  • Add NOT NULL constraints where applicable
  • Use CHECK constraints for data validation
  • Prefer text over varchar(n) unless length limit is meaningful
  • Use partial indexes instead of filtered queries
  • Design schemas for the access patterns, not just the data model

5. Concurrency & Locking (MEDIUM-HIGH)

  • Use SELECT ... FOR UPDATE SKIP LOCKED for queue patterns
  • Keep transactions short to minimize lock contention
  • Avoid long-running transactions during migrations
  • Use advisory locks for application-level coordination
  • Be aware of lock ordering to prevent deadlocks

6. Data Access Patterns (MEDIUM)

  • Use Supabase client libraries for standard CRUD
  • Use RPC functions for complex operations
  • Implement pagination with cursor-based approach (not OFFSET)
  • Use realtime subscriptions judiciously
  • Batch operations where possible

7. Monitoring & Diagnostics (LOW-MEDIUM)

  • Monitor pg_stat_statements for slow queries
  • Check pg_stat_user_indexes for unused indexes
  • Monitor connection count and pool utilization
  • Set up alerts for long-running queries
  • Review lock waits periodically

8. Advanced Features (LOW)

  • Use CTEs for readable complex queries (but note CTE materialization)
  • Leverage PostgreSQL extensions (pgvector, pg_trgm, etc.)
  • Use generated columns for computed values
  • Consider table partitioning for very large tables
  • Use LISTEN/NOTIFY for event-driven patterns

References

For detailed rule files with specific examples, see templates/guides/supabase-postgres/.

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

Pre-action boundary checking — validates agent tool calls against declared capabilities and task contracts

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Auto-detect project context and optimize harness — deactivate unused agents/skills, suggest missing experts, generate project profile

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Adversarial code review using attacker mindset — trust boundary, attack surface, business logic, and defense evaluation

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Apache Airflow best practices for DAG authoring, testing, and production deployment

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Alembic migration patterns for naming conventions, safety checks, expand-contract, env.py configuration, and CI integration

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

Pre-routing ambiguity analysis — scores request clarity and asks clarifying questions when needed (inspired by ouroboros)

The English summary is being prepared. Showing the original description.

baekenough/second-brain15Updated Oct 8, 2026

See all skills by baekenough

Report a problem with this skill