| name | supabase-audit |
| description | Supabase cost optimization and audit expert. Monitors database performance, storage, bandwidth, Edge Functions, Auth MAU, and provides optimization recommendations. Trigger when user mentions Supabase costs, database optimization, or Supabase audit. |
| when_to_use | - User asks about Supabase billing
- User needs to optimize database performance
- User encounters Supabase cost overages
- User needs to audit table structure and indexes
- User wants to reduce Edge Function invocations
|
| allowed-tools | Bash(psql *) |
Supabase Cost Optimization Expert
Cost Components
| Component | Free Tier | Billing Metric |
|---|
| Database | 500MB | Storage size |
| Storage | 1GB | Storage + Egress |
| Auth | 50,000 MAU | Monthly Active Users |
| Edge Functions | 500K invocations | Invocations |
| Realtime | 200 concurrent | Connections |
| Bandwidth | 5GB | Egress |
Common Anti-Patterns
| Anti-Pattern | Problem | Reference |
|---|
| Slow queries | High CPU time | references/slow-queries.md |
| Missing indexes | Sequential scans | references/index-optimization.md |
| Missing FK indexes | Slow joins | references/missing-foreign-key-index.md |
| Table bloat | Dead tuples | references/table-bloat.md |
| Connection issues | Too many connections | references/connection-pooling.md |
| Inefficient joins | Cartesian products | references/inefficient-join.md |
| Correlated subqueries | N+1 pattern | references/slow-subquery.md |
| Deep pagination | OFFSET performance | references/inefficient-pagination.md |
Audit Workflow
Step 1: Check Database Size
SELECT pg_database_size(current_database());
SELECT pg_size_pretty(pg_database_size(current_database()));
Step 2: Identify Expensive Queries
Use pg_stat_statements to find slow queries.
See references/slow-queries.md for detailed analysis.
Step 3: Check Index Usage
Analyze sequential scans vs index scans.
See references/index-optimization.md for optimization strategies.
Step 4: Monitor Table Bloat
Check dead tuple ratio and vacuum status.
See references/table-bloat.md for cleanup procedures.
Step 5: Verify Connection Pooling
Ensure proper connection management.
See references/connection-pooling.md for configuration.
Benchmark Reference
| Optimization | Before | After | Improvement |
|---|
| Add index | 500ms | 5ms | 99% |
| Clean bloat | 500MB | 300MB | 40% |
| Use pooling | 60 conn | 200+ conn | 233% |
| Fix join | 5000ms | 50ms | 99% |
| Cursor pagination | 100ms | 5ms | 95% |
Output Format
## Supabase Cost Audit Report
### 1. Current Usage
- Database size: X MB / 500 MB (X%)
- Storage: X GB / 1 GB (X%)
- Bandwidth: X GB / 5 GB (X%)
- Auth MAU: X / 50,000 (X%)
### 2. Anti-Patterns Detected
| Query | Anti-Pattern | Reference | Fix |
|-------|--------------|-----------|-----|
| ... | ... | ... | ... |
### 3. Recommendations (by priority)
1. [P0] Fix: <anti-pattern> → Expected improvement: XX%
Reference: references/<file>.md
### 4. Cost Projection
- Current: $X/month
- After optimization: $X/month
- Savings: $X/month (XX%)