As your Supabase application grows, keeping an eye on its performance and health becomes crucial. This section will guide you through the essential tools and techniques for monitoring your deployed Supabase project and tuning it for optimal performance.
Supabase provides several built-in tools for monitoring. The first place to look is your project's dashboard. Here, you'll find an overview of your API usage, database connections, and storage activity. Familiarize yourself with these metrics, as they're your first line of defense in identifying potential issues.
Database performance is often the bottleneck in applications. Supabase's PostgreSQL database offers powerful tools for performance analysis. You can identify slow queries by looking at the 'Database' tab in your dashboard, which often highlights long-running queries. Additionally, understanding PostgreSQL's EXPLAIN command is invaluable.
SELECT pg_stat_statements_reset();The pg_stat_statements extension (usually enabled by default in Supabase) tracks execution statistics for all SQL statements executed by the server. You can query it to find the slowest or most frequently executed queries. To get a clear picture after a period of activity, you might want to reset the statistics before a performance test or at the start of a monitoring session.
SELECT query, calls, total_time, mean_time FROM pg_stat_statements ORDER BY total_time DESC LIMIT 10;This query will show you the top 10 queries by total execution time. Analyzing these results will help you pinpoint which queries are candidates for optimization. Look for queries with high total_time and mean_time relative to the number of calls.
When a query is identified as slow, the next step is to understand how the database is executing it. This is where EXPLAIN comes in. Prefixing a SELECT, INSERT, UPDATE, or DELETE statement with EXPLAIN will show you the query plan – the steps the database intends to take to fulfill the query.