/supabase-tutorials

How to view slow queries in Supabase?

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.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to view slow queries in Supabase?

 

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:

  • query: The SQL query text that was executed.
  • total_exec_time: Total time spent executing the query across all calls.
  • calls: Number of times the query was executed.
  • mean_time: The average execution time of the query.
  • max_time: The maximum time taken by a single execution of the query.

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:

  • Adding appropriate indexes
  • Rewriting the query for efficiency
  • Reducing the volume of data processed
  • Reviewing your database schema for improvements

Modify and test each query iteratively, ensuring that the changes lead to improved performance.

 

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022