# Supabase Audit

> 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.

- Skill: `huifer/supabase-audit` (Agent Skill, multi-file: 13 files)
- Install (CLI): `npx skillmds@latest add huifer/supabase-audit`
- Raw SKILL.md: https://api.skillmd.com/api/skills/huifer/supabase-audit/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- Author: huifer (https://skillmd.com/u/huifer)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/huifer/supabase-audit

---


# 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

```sql
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%)
```

