Connection management
Using your connections resourcefully
Connections#
Every Compute Add-On has a pre-configured direct connection count and Supavisor pool size. This guide discusses ways to observe and manage them resourcefully.
Configuring Supavisor's pool size#
You can change how many database connections Supavisor can manage by altering the pool size in the "Connection pooling" section of the Database Settings:

The general rule is that if you are heavily using the PostgREST database API, you should be conscientious about raising your pool size past 40% of the Database Max Connections. Otherwise, you can commit 80% to the pool. This leaves adequate room for the Authentication server and other utilities.
These numbers are generalizations and depends on other Supabase products that you use and the extent of their usage. The actual values depend on your concurrent peak connection usage. For instance, if you were only using 80 connections in a week period and your database max connections is set to 500, then realistically you could allocate the difference of 420 (minus a reasonable buffer) to service more demand.
Monitoring connections#
Capturing historical usage#
Dashboard monitoring charts#

For Teams and Enterprise plans, Supabase provides Advanced Telemetry charts directly within the Dashboard. The Database client connections chart displays historical connection data broken down by connection type:
- Postgres: Direct connections from your application
- PostgREST: Connections from the PostgREST API layer
- Reserved: Administrative connections for Supabase services
- Auth: Connections from Supabase Auth service
- Storage: Connections from Supabase Storage service
- Other roles: Miscellaneous database connections
This chart helps you monitor connection pool usage, identify connection leaks, and plan capacity. It also shows a reference line for your compute size's maximum connection limit.
For more details on using these monitoring charts, see the Reports guide.
Grafana Dashboard#
Supabase offers a Grafana Dashboard that records and visualizes over 200 project metrics, including connections. For setup instructions, check the metrics docs.
Its "Client Connections" graph displays connections for both Supavisor and Postgres

Observing live connections#
pg_stat_activity is a special view that keeps track of processes being run by your database, including live connections. It's particularly useful for determining if idle clients are hogging connection slots.
Query to get all live connections:
1SELECT2 pg_stat_activity.pid as connection_id,3 ssl,4 datname as database,5 usename as connected_role,6 application_name,7 client_addr as IP,8 query,9 query_start,10 state,11 backend_start12FROM pg_stat_ssl13JOIN pg_stat_activity14ON pg_stat_ssl.pid = pg_stat_activity.pid;Interpreting the query:
| Column | Description |
|---|---|
connection_id | connection id |
ssl | Indicates if SSL is in use |
database | Name of the connected database (usually postgres) |
usename | Role of the connected user |
application_name | Name of the connecting application |
client_addr | IP address of the connecting server |
query | Last query executed by the connection |
query_start | Time when the last query was executed |
state | Querying state. See Session states for the full list of values and what each one means. |
backend_start | Timestamp of the connection's establishment |
The username can be used to identify the source:
| Role | API/Tool |
|---|---|
supabase_admin | Used by Supabase for monitoring and by Realtime |
authenticator | Data API (PostgREST) |
supabase_auth_admin | Auth |
supabase_storage_admin | Storage |
supabase_replication_admin | Synchronizes Read Replicas |
postgres | Supabase Dashboard and External Tools (e.g., Prisma, SQLAlchemy, PSQL...) |
| Custom roles defined by user | External Tools (e.g., Prisma, SQLAlchemy, PSQL...) |
Diagnosing stuck and blocked queries#
If your application is slow or hanging, the cause is usually visible right now in pg_stat_activity - a query that's stuck, one session blocking others, or a transaction left open by mistake. This section covers how to read a session's state, find out what's blocking a query, and stop the session responsible.
Session states#
The state column on pg_stat_activity can be one of six values:
| State | Meaning |
|---|---|
active | The session is currently executing a query. A query running longer than expected is worth investigating, but a nonzero count of active sessions is normal on its own. |
idle | The session is connected and waiting for the client to send a new command. Normal for pooled or long-lived connections. |
idle in transaction | The session has an open transaction but isn't currently running a query. This holds locks and blocks table cleanup for as long as it stays open, and almost always means the application forgot to commit or roll back. |
idle in transaction (aborted) | The last statement in the transaction failed. Postgres releases the transaction's ordinary locks as part of the abort - the exception is session-level advisory locks (pg_advisory_lock, not pg_advisory_xact_lock), which are held until explicitly unlocked or the session ends. The client still needs to send rollback to close the transaction before the session will accept new commands. |
fastpath function call | The session is executing a function through Postgres's low-level fastpath protocol, most commonly for large object reads or writes. Rare, and normally brief. |
disabled | Activity tracking (track_activities) is turned off for this session, so Postgres isn't recording its state or query. |
idle in transaction is the state most worth watching. Unlike a slow active query, which is at least making progress, an idle-in-transaction session is holding its locks indefinitely while doing nothing.
Finding blocked queries#
Postgres tracks which sessions are waiting on a lock held by another session. Query pg_stat_activity and pg_blocking_pids() together to see this directly:
1select2 a.pid,3 a.usename as role_name,4 a.application_name,5 a.state,6 a.query,7 a.wait_event_type,8 a.wait_event,9 a.xact_start as transaction_start,10 a.query_start,11 a.state_change,12 pg_blocking_pids(a.pid) as blocked_by13from pg_stat_activity as a14where15 a.datname = current_database()16 and a.pid != pg_backend_pid()17 and a.backend_type = 'client backend'18order by a.query_start asc nulls last;The where clause excludes the query's own session and Postgres's internal background workers (autovacuum, the WAL writer, extensions like pg_cron), so the results only show sessions a client opened.
blocked_by is an array, not a single value, for two reasons:
- A session can be waiting on more than one session at once, if several sessions hold a lock that all conflict with what it's requesting.
- Blocking can chain: session A holds a lock, session B waits on A, session C waits on B.
blocked_byonly ever lists the direct blocker, so tracing a long queue back to its root cause may mean following the chain through more than one session.
Cancelling or terminating a session#
Postgres gives you two ways to stop a session, and they behave differently:
select pg_cancel_backend(pid);cancels the session's currently running query but leaves the connection open. The application gets one failed query back and can continue using that connection.select pg_terminate_backend(pid);ends the session's connection entirely.
Which one to use depends on the session's state:
- For an
activesession that's stuck waiting on a lock or running longer than expected, cancel it first. It's the less disruptive option, and it's usually enough to unstick the wait or stop the runaway query. - For a session that's
idle in transaction, cancelling does nothing - there's no running query to cancel, and the open transaction stays open regardless. Terminating the session is the only way to force the transaction closed and release its locks. - For a session that's
idle in transaction (aborted), its ordinary locks were already released when the transaction aborted. The correct fix is for the client to issuerollback, which closes the transaction cleanly. Reservepg_terminate_backendfor a client that's unresponsive or a connection that needs to close regardless - it won't release anything further in this case, aside from a session-level advisory lock, which persists until the session ends.
Both functions require you to either be a superuser, hold the pg_signal_backend role, or be signalling your own session - and even pg_signal_backend can't be used to stop a session belonging to an actual superuser role. If you hit a permission error while terminating a session, see this troubleshooting guide.
If you're on Supabase, you can see all of this - session states, blocking chains, and a way to terminate a stuck session - on your project's Database Connections page in the dashboard, without writing any SQL.