# Optimize Supabase Postgres Performance

Slow queries and schema drift can make Postgres apps hard to scale. This skill gives AI agents Supabase-backed rules for indexes, RLS, pooling, and diagnostics.

## Install

```bash
npx skillstore add supabase/supabase-postgres-best-practices
```

## Metadata

- Status: approved
- Slug: supabase-supabase-postgres-best-practices
- Version: 1.0.0
- Author version: 1.0.0
- Skillstore revision: r1
- Version status: valid
- Tree hash: 8b95add1421e84077fa10f0480a8a85115c5d7d105445c50be9b75da48e341b9
- Author: supabase
- GitHub username: supabase
- License: MIT
- Repository: https://github.com/supabase/agent-skills/tree/main/skills/postgres-best-practices/
- Ref: f93e9bb0daca99badb6a7e574b97737155d57cb3
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: scripts, network, external\_commands
- Quality score: 80
- Quality tier: silver
- Public page: https://skillstore.pages.dev/skills/supabase-supabase-postgres-best-practices
- Manifest: https://skillstore.pages.dev/api/skills/supabase-supabase-postgres-best-practices/manifest

## Capabilities

- Guides index selection for WHERE clauses, JOINs, JSONB, full text search, partial indexes, and covering indexes.
- Explains connection pooling, connection limits, idle timeouts, and prepared statement behavior in Supabase projects.
- Shows RLS policy patterns and performance tips for multi-tenant Postgres applications.
- Provides SQL examples for schema design, partitioning, primary keys, and lowercase identifiers.
- Covers transaction scope, deadlock prevention, advisory locks, and SKIP LOCKED queue processing.
- Includes diagnostics guidance for pg\_stat\_statements, VACUUM, ANALYZE, and EXPLAIN ANALYZE.

## Use Cases

- Review Slow Queries: Analyze query patterns and choose indexes, pagination, or batching changes that fit Postgres behavior.
- Plan Supabase Scaling: Review connection pooling, idle timeouts, and connection limits before traffic or serverless load increases.
- Improve Tenant Isolation: Design RLS policies that enforce access rules while avoiding expensive per-row checks.

## Prompt Templates

### Review a Query

```
Review this Postgres query for common Supabase performance issues. Suggest indexes, query changes, and validation steps.
```

### Design Indexes

```
Given these tables and frequent filters, recommend B-tree, GIN, BRIN, composite, partial, or covering indexes. Explain the trade-offs.
```

### Audit RLS Policies

```
Review these Supabase RLS policies for tenant isolation and performance. Identify missing indexes and expensive policy expressions.
```

### Create a Database Plan

```
Create a prioritized Postgres optimization plan covering queries, schema design, pooling, locking, data access patterns, and diagnostics.
```

## Limitations

- It provides guidance, not live database inspection or automated migration execution.
- Examples must be adapted and tested against each schema and workload.
- It does not replace Supabase project monitoring, backups, or production change review.
- Some recommendations depend on the active Postgres version and available extensions.

## Best Practices

- Start with the real workload, then validate each change with EXPLAIN ANALYZE or production metrics.
- Index foreign keys, RLS filter columns, and common multi-column query patterns before tables grow large.
- Keep transactions short and use pooling settings that match application concurrency.

## Anti Patterns

- Adding single-column indexes for every field without matching actual query patterns.
- Relying on application-only tenant filters instead of database-enforced RLS.
- Using OFFSET pagination or N\+1 query loops on large result sets.

## Security Audit

- Audited at: 2026-07-07T04:46:40.554\+00:00
- Summary: All static findings were adjudicated as false positives. The flagged content consists of SQL examples, markdown formatting, public documentation links, and contributor instructions; no prompt injection, data exfiltration, or unauthorized command execution was found.

## Stats

- Views: 260
- Downloads: 17
- Favorites: 0
- Popularity score: 0
