agentsclimarketplace

Supabase cost tuning

Skill jeremylongshore/claude-code-plugins-plus-skills/plugins/saas-packs/supabase-pack/skills/supabase-cost-tuning

'Optimize Supabase costs through plan selection, database tuning, storage cleanup,From its SKILL.md

Install
npx -y skills add jeremylongshore/claude-code-plugins-plus-skills --skill supabase-cost-tuning

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its file declares

Copied from the file, not written here

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

7.8 KB, ~1.7k tokens by cl100k_base, as published. Nobody here has run it

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-js installed: npm install @supabase/supabase-js
  • Service role key for admin operations (storage audit, cleanup scripts)
  • SQL editor access (Dashboard > SQL Editor or psql connection)

Pricing Reference

ResourceFree TierPro ($25/mo)Team ($599/mo)
Database500 MB8 GB included, $0.125/GB extra8 GB included
Storage1 GB100 GB included, $0.021/GB extra100 GB included
Bandwidth5 GB250 GB included, $0.09/GB extra250 GB included
Edge Functions500K invocations2M invocations, $2/million extra2M invocations
Realtime200 concurrent500 concurrent500 concurrent
Auth MAU50,000100,000100,000

Compute add-ons (Pro and above):

InstancevCPUsRAMPrice
Micro21 GBIncluded with Pro
Small22 GB$25/mo
Medium24 GB$50/mo
Large48 GB$100/mo
XL816 GB$200/mo
2XL1632 GB$400/mo

Decision framework: Read replicas ($25/mo each) beat scaling up when reads dominate and geographic distribution is needed. Connection pooling (Supavisor, free) reduces compute pressure from idle connections.

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 reclaim space and refresh planner stats:

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 reduce Edge Function costs

Prefer pooling and code fixes over a compute upgrade. Route direct pg connections (migrations, ORMs) through the Supavisor pooler URL instead of scaling the instance:

// Direct:   postgresql://postgres:[email protected]:5432/postgres
// Pooled:   postgresql://postgres:[email protected]:6543/postgres

Cut Edge Function cost by keeping imports lightweight (dynamic-import heavy libraries only on the paths that need them) and caching expensive results across warm invocations. Add a lightweight usage-tracking table plus a daily materialized-view summary for spend visibility. See full compute and Edge Function code for the pooling config, cold-start patterns, and usage-monitoring schema (Step 3 section).

Output

After completing all three steps, the project has:

  • Database size audit with table-level breakdown and dead tuple analysis
  • Unused indexes identified and dropped to reclaim storage
  • Old data archived and vacuumed to free database space
  • 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

IssueCauseSolution
Database approaching 500 MB (Free) or 8 GB (Pro)Data growth without archivalArchive old records, VACUUM, drop unused indexes
Storage costs climbing monthlyOrphaned uploads accumulatingSchedule cleanup job for files not linked to records
Unexpected bandwidth spikeselect('*') on large tablesUse specific column lists; add .range() pagination
Edge Function billing spikeRetry loops or heavy importsAdd circuit breaker with max 3 retries; dynamic imports
Connection limit errorsToo many direct connectionsSwitch to pooler URL (port 6543); reduce client pool size
Spend cap reachedUsage exceeded Pro included resourcesEnable spend cap in Dashboard > Settings > Billing to prevent overage
VACUUM not reclaiming spaceLong-running transactions holding locksCheck pg_stat_activity for idle-in-transaction; terminate stale sessions

Examples

Quick cost check — read database size and bucket count with a service-role client to see how close a growing project sits to its plan limits.

Monthly cost estimation — feed measured usage (DB GB, storage GB, bandwidth GB, Edge Function invocations, MAU) into a Pro-tier overage calculator that prints a line-item breakdown and total.

See full example scripts for the runnable quick-check and the estimateMonthlyCost calculator with a worked $31.05/mo case.

Resources

Next Steps

For architecture patterns, see supabase-reference-architecture. For performance tuning beyond cost, see supabase-performance-tuning.

What ships with it: 6 files

12.2 KB alongside SKILL.md

Keep looking

Skills are one crate of 326,144. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.