Learn how to view slow queries in Supabase with our step-by-step guide—from accessing your dashboard and running SQL queries to optimizing slow requests.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Access Your Supabase Project Dashboard
First, navigate to the Supabase website at supabase.io and log in with your credentials. After signing in, you will see a list of your projects. Choose the project where you want to view slow queries. Click on it to open the project dashboard.
Step 2: Navigate to the Database Section
Once you're in the project dashboard, look for the option labeled "Database" on the side menu. Click on it to access the database management area.
Step 3: Open the SQL Editor
Within the Database section, locate and click on "SQL Editor." This is where you can run SQL queries to interact with your database and view various performance metrics.
Step 4: Execute the Query to View Slow Queries
In the SQL Editor, you will need to run a specific query to identify slow queries. Enter the following SQL command:
EXPLAIN ANALYZE SELECT query, total_exec_time, calls, mean_time, max_time
FROM pg_stat_statements
WHERE mean\_time > 500; -- This threshold is set in milliseconds
This query retrieves query statistics from pg_stat_statements
view. The condition mean_time > 500
filters out slow queries, specifically those that take longer than 500 milliseconds on average to execute.
Step 5: Analyze the Query Results
After you run the SQL command, the results will appear below the editor. The displayed information will include:
Carefully analyze these results to determine which queries are the slowest and might need optimization.
Step 6: Optional - Modify the Threshold for Slow Queries
If you want to adjust the threshold to capture more or fewer slow queries, change the number in the mean_time > 500
condition of the SQL query. For instance, you can change it to mean_time > 300
to include queries with a mean execution time over 300 milliseconds.
EXPLAIN ANALYZE SELECT query, total_exec_time, calls, mean_time, max_time
FROM pg_stat_statements
WHERE mean\_time > 300;
Adjust the threshold as needed based on your performance requirements and expectations.
Step 7: Optimize Identified Slow Queries
Once you have identified slow queries, consider optimizing them to enhance performance. Common optimizations include:
Modify and test each query iteratively, ensuring that the changes lead to improved performance.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.