supabase-cost-tuning
Audits Supabase usage to reduce costs by right-sizing compute, cleaning up storage, and optimizing database performance.
Install
mkdir -p .claude/skills/supabase-cost-tuning && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/8962" && unzip -o skill.zip -d .claude/skills/supabase-cost-tuning && rm skill.zipInstalls to .claude/skills/supabase-cost-tuning
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Optimize Supabase costs through plan selection, database tuning, storageKey capabilities
- →Audit database size and dead-tuple bloat
- →Identify unused indexes and orphaned storage assets
- →Implement connection pooling via Supavisor
- →Optimize Edge Function cold starts with dynamic imports
- →Configure usage monitoring and budget alerts
How it works
This skill audits resource usage against plan limits and applies database tuning, storage cleanup, and connection pooling to reduce compute and storage costs.
Inputs & outputs
When to use supabase-cost-tuning
- →Reducing Supabase monthly billing
- →Right-sizing database compute resources
- →Identifying unused storage or orphaned assets
- →Implementing usage monitoring and alerts
About this skill
Supabase Cost Tuning
Overview
Reduce Supabase spend by auditing usage against plan limits, eliminating database and storage waste, and right-sizing compute resources. The three biggest levers: database optimization (vacuum, index cleanup, archival), storage lifecycle management (compress before upload, orphan cleanup), and connection pooling to reduce compute add-on requirements.
Work the three steps below in order — audit first to find where the money goes, then optimize the biggest offenders, then right-size compute. Each step keeps a representative snippet inline; the full query and script sets live in references/ so this file stays scannable.
Prerequisites
- Supabase project with Dashboard access (Settings > Billing)
@supabase/supabase-jsinstalled:npm install @supabase/supabase-js- Service role key for admin operations (storage audit, cleanup scripts)
- SQL editor access (Dashboard > SQL Editor or
psqlconnection)
Pricing Reference
Reviewed 2026-10-22: use current pricing and the project's actual billing dashboard rather than a universal hard-coded plan table. Compute is billed hourly; paid organizations receive $10 of compute credits per month, shared across projects, not a free compute instance for every project. The compute usage reference lists Small at $0.0206/hour (about $15 for 730 hours), Medium at $0.0822/hour (about $60), and Large at $0.1517/hour (about $111), before plan fees, credits and other usage. These dated estimates are not a billing quote or fixed monthly cap.
Read replicas have their own compute and usage costs, not a universal $25/month price. Model the selected size, active hours, disk, egress, region and current plan allowances before changing topology. Pooling can reduce connection overhead but does not guarantee that a smaller compute size will satisfy the workload.
Instructions
Step 1: Audit current usage and identify cost drivers
Find where the database budget is going before changing anything. Run the audit queries in the SQL Editor to surface the biggest tables, unused indexes, dead-tuple bloat, and connection count. Start with total size:
select pg_size_pretty(pg_database_size(current_database())) as total_db_size;
Then audit storage per bucket with a service-role client, and read current spend under Dashboard > Settings > Billing. See full audit queries and storage script for the complete SQL set (table sizes, zero-scan indexes, dead-tuple ratio, connection count) and the per-bucket usage script.
Step 2: Optimize database, storage, and bandwidth
Attack the biggest offenders from Step 1. Archive old rows before deleting, then VACUUM ANALYZE to make dead-tuple space reusable and refresh planner stats; ordinary VACUUM does not generally shrink the on-disk allocation:
vacuum (verbose, analyze) public.events;
For storage, compress images client-side before upload and schedule an orphan-cleanup job. For bandwidth, replace select('*') with explicit column lists, use head: true count queries for totals, and paginate with .range(). See full optimization code for the archival + VACUUM SQL, the compress/clean-orphans scripts, and the bandwidth-reduction patterns.
Step 3: Right-size compute and distinguish invocation cost from latency
Prefer pooling and code fixes over a compute upgrade. Choose the appropriate direct or Supavisor session/transaction connection mode for the client. Migrations may require direct/session semantics; do not send every workflow to transaction pooling:
// Copy the actual direct/session/transaction connection string from Dashboard.
// Do not derive the pooler hostname by changing only the port.
// Transaction pooling constraints (including prepared statements) need review.
Smaller imports and warm-instance caching can improve latency/resource use, but do not themselves reduce hosted Edge Function invocation charges. Current invocation billing is based on invocation count (excluding preflight OPTIONS), with package rounding for billable overage. Avoid unnecessary invocations and retry storms within the application's correctness requirements; do not skip required work to reduce counts. Treat historical optimization examples as resource/latency patterns, not evidence of invocation savings. Use actual billing usage rather than a custom event table as invoice authority.
Output
After completing all three steps, the project has:
- Database size audit with table-level breakdown and dead tuple analysis
- Candidate unused indexes reviewed against representative workloads before any approved drop
- Approved archival and vacuum outcomes measured without promising physical disk shrinkage
- Storage orphans cleaned and upload compression implemented
- Bandwidth reduced through column selection and pagination
- Connection pooling configured to avoid unnecessary compute upgrades
- Edge Function cold starts minimized with dynamic imports and caching
- Usage monitoring table and daily summary view for spend visibility
Error Handling
| Issue | Cause | Solution |
|---|---|---|
| Database approaching 500 MB (Free) or 8 GB (Pro) | Data growth without archival | Archive old records, VACUUM, drop unused indexes |
| Storage costs climbing monthly | Orphaned uploads accumulating | Schedule cleanup job for files not linked to records |
| Unexpected bandwidth spike | select('*') on large tables | Use specific column lists; add .range() pagination |
| Edge Function billing spike | Excess invocations or retry loops | Inspect invocation counts and correctness-preserving admission/retry budgets; import size is a latency concern |
| Connection limit errors | Too many direct connections | Switch to pooler URL (port 6543); reduce client pool size |
| Spend cap reached | A capped usage surface reached its allowance | Review the current spend-cap coverage and response; it does not cap every charge |
| VACUUM not reclaiming space | Long-running transactions holding locks | Check pg_stat_activity for idle-in-transaction; terminate stale sessions |
Examples
Quick cost check — inspect actual billing usage and an authorized database-size query; bucket count is not stored bytes.
Cost estimation — supply reviewed quantities, units, current rates, eligible credits and source/date to an explicitly scoped calculator. No universal Pro-tier total is supplied.
The explicit-input examples validate arithmetic without embedding provider rates. Reconcile every included allowance, package/tier rounding, compute hour, credit and excluded charge against the current billing surface before using an estimate for a decision.
Resources
- Supabase Pricing — plan comparison and calculator
- Compute Add-ons — instance sizing guide
- Spend Cap — prevent unexpected overage charges
- Database Disk Usage — monitoring and management
- Connection Pooling (Supavisor) — reduce connection overhead
- Edge Functions Best Practices — cold start and performance tips
- supabase-js Reference —
createClientand SDK patterns
Next Steps
For architecture patterns, see supabase-reference-architecture.
For performance tuning beyond cost, see supabase-performance-tuning.
When not to use it
- →When project requirements exceed Pro tier resource limits
- →When real-time concurrency needs exceed plan capacity
Prerequisites
Limitations
- →Requires manual intervention for archival and cleanup jobs
- →Some optimizations depend on specific Supabase plan tiers
How it compares
Unlike manual billing review, this approach uses automated SQL audit queries and scripts to identify and reclaim specific resource waste.
Compared to similar skills
supabase-cost-tuning side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| supabase-cost-tuning (this skill) | 0 | 4mo | Review | Intermediate |
| sql-optimization-patterns | 64 | 6mo | No flags | Advanced |
| supabase-postgres-best-practices | 4 | 10mo | No flags | Intermediate |
| supabase-performance-tuning | 4 | 4mo | Review | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by jeremylongshore
View all by jeremylongshore →You might also like
sql-optimization-patterns
wshobson
Master SQL query optimization, indexing strategies, and EXPLAIN analysis to dramatically improve database performance and eliminate slow queries. Use when debugging slow queries, designing database schemas, or optimizing application performance.
supabase-postgres-best-practices
davila7
Postgres performance optimization and best practices from Supabase. Use this skill when writing, reviewing, or optimizing Postgres queries, schema designs, or database configurations.
supabase-performance-tuning
jeremylongshore
Optimize Supabase API performance with caching, batching, and connection pooling. Use when experiencing slow API responses, implementing caching strategies, or optimizing request throughput for Supabase integrations. Trigger with phrases like "supabase performance", "optimize supabase", "supabase latency", "supabase caching", "supabase slow", "supabase batch".
analyzing-query-performance
jeremylongshore
Execute use when you need to work with query optimization. This skill provides query performance analysis with comprehensive guidance and automation. Trigger with phrases like "optimize queries", "analyze performance", or "improve query speed".
find-hypertable-candidates
timescale
Use this skill to analyze an existing PostgreSQL database and identify which tables should be converted to Timescale/TimescaleDB hypertables. **Trigger when user asks to:** - Analyze database tables for hypertable conversion potential - Identify time-series or event tables in an existing schema - Evaluate if a table would benefit from Timescale/TimescaleDB - Audit PostgreSQL tables for migration to Timescale/TimescaleDB/TigerData - Score or rank tables for hypertable candidacy **Keywords:** hypertable candidate, table analysis, migration assessment, Timescale, TimescaleDB, time-series detection, insert-heavy tables, event logs, audit tables Provides SQL queries to analyze table statistics, index patterns, and query patterns. Includes scoring criteria (8+ points = good candidate) and pattern recognition for IoT, events, transactions, and sequential data.
databases
mrgoonie
Work with MongoDB (document database, BSON documents, aggregation pipelines, Atlas cloud) and PostgreSQL (relational database, SQL queries, psql CLI, pgAdmin). Use when designing database schemas, writing queries and aggregations, optimizing indexes for performance, performing database migrations, configuring replication and sharding, implementing backup and restore strategies, managing database users and permissions, analyzing query performance, or administering production databases.