How to track concurrent connections
Hello - How do I track current active connections to my supabase project?
My webapp uses the python supabase library and assigns every user one client, as each user has different permissions in RLS. Talking to the supabase bot, it explained that 1 client counts as 1 connection, unless we use pooling. It then gave me some SQL to check how many concurrent “connections” my supabase project was dealing with:
SELECT count(*) AS total_connections
FROM pg_stat_activity
WHERE state = 'active';
Even with 4 different users logged in on different devices, the count would stay at 1, briefly spiking to 2 every so often, but never higher than that. I’m not sure if this counter is even accurate, and I don’t quite trust the bot’s answers to my other questions.
Q1. Does one client really count as a connection? (ie. I have a maximum of 60 concurrent users)
Q2. Where can I find out about connection pooling and how does it work?
Q3. Once a user’s access token has expired, does their client still count as a connection?
Q4. How can I get a live value for concurrent connections to my supabase project?
7 Replies
Hello
Q1, Q2
But you webapp is talking to the supabase over Postgrest right?
Supabase uses connection pooling by default when you are using defaults
this is good doc
https://supabase.com/docs/guides/database/connecting-to-postgres#serverside-poolers
Q3 - it doesn't matter, all matters is connection to the database
But supabase official client does it ok
Problem is only when you start to connect to the database yourself
from this diagram you can understand it better
https://supabase.com/docs/_next/image?url=%2Fdocs%2Fimg%2Fguides%2Fdatabase%2Fconnecting-to-postgres%2Fhow-connection-pooling-works--light.png&w=3840&q=75&dpl=dpl_95CZnMDJio2Y974uRpfKAxJMykwP
Q4 your query is OK
you can check also active connections here
https://supabase.com/dashboard/project/YOURPROJECTID/reports/database
will look like this

here is also good query
https://supabase.com/docs/guides/database/connection-management#observing-live-connections
Thanks so much, really helpful!
np