SU

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

Installs 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, storage
72 charsno explicit “when” trigger
Intermediate

Key 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

You give it
Current Supabase project usage metrics and billing data
You get back
Optimized resource allocation and reduced monthly spend

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

When not to use it

  • When project requirements exceed Pro tier resource limits
  • When real-time concurrency needs exceed plan capacity

Prerequisites

Supabase project with Dashboard access@supabase/supabase-js installedService role keySQL editor access

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.

SkillInstallsUpdatedSafetyDifficulty
supabase-cost-tuning (this skill)027dReviewIntermediate
sql-optimization-patterns642moNo flagsAdvanced
supabase-postgres-best-practices46moNo flagsIntermediate
supabase-performance-tuning427dReviewAdvanced

Try saying

Example prompts that trigger this skill in your AI assistant.

More by jeremylongshore

View all by jeremylongshore

analyzing-logs

jeremylongshore

Analyze application logs to detect performance issues, identify error patterns, and improve stability by extracting key insights.

14123

ollama-setup

jeremylongshore

Configure auto-configure Ollama when user needs local LLM deployment, free AI alternatives, or wants to eliminate hosted API costs. Trigger phrases: "install ollama", "local AI", "free LLM", "self-hosted AI", "replace OpenAI", "no API costs". Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

1167

backtesting-trading-strategies

jeremylongshore

Backtest crypto and traditional trading strategies against historical data. Calculates performance metrics (Sharpe, Sortino, max drawdown), generates equity curves, and optimizes strategy parameters. Use when user wants to test a trading strategy, validate signals, or compare approaches. Trigger with phrases like "backtest strategy", "test trading strategy", "historical performance", "simulate trades", "optimize parameters", or "validate signals".

1071

generating-database-seed-data

jeremylongshore

Process this skill enables AI assistant to generate realistic test data and database seed scripts for development and testing environments. it uses faker libraries to create realistic data, maintains relational integrity, and allows configurable data volumes. u... Use when working with databases or data models. Trigger with phrases like 'database', 'query', or 'schema'.

1033

cursor-codebase-indexing

jeremylongshore

Execute set up and optimize Cursor codebase indexing. Triggers on "cursor index setup", "codebase indexing", "index codebase", "cursor semantic search". Use when working with cursor codebase indexing functionality. Trigger with phrases like "cursor codebase indexing", "cursor indexing", "cursor".

885

testing-mobile-apps

jeremylongshore

Execute mobile app testing on iOS and Android devices/simulators. Use when performing specialized testing. Trigger with phrases like "test mobile app", "run iOS tests", or "validate Android functionality".

810

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.

64220

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.

439

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

416

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

18

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.

18

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.

16

Search skills

Search the agent skills registry