Database

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 configuration" section of the Database Settings:

Connection Info and Certificate.

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%. 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 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

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 client connection graph

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:


_14
SELECT
_14
pg_stat_activity.pid as connection_id,
_14
ssl,
_14
datname as database,
_14
usename as connected_role,
_14
application_name,
_14
client_addr as IP,
_14
query,
_14
query_start,
_14
state,
_14
backend_start
_14
FROM pg_stat_ssl
_14
JOIN pg_stat_activity
_14
ON pg_stat_ssl.pid = pg_stat_activity.pid;

Interpreting the query:

ColumnDescription
connection_idconnection id
sslIndicates if SSL is in use
databaseName of the connected database (usually postgres)
usenameRole of the connected user
application_nameName of the connecting application
client_addrIP address of the connecting server
queryLast query executed by the connection
query_startTime when the last query was executed
stateQuerying state: active or idle
backend_startTimestamp of the connection's establishment

The usename can be used to identify the source:

RoleAPI/Tool
supabase_adminUsed by Supabase to configure projects and for monitoring
authenticatorData API (PostgREST)
supabase_auth_adminAuth
supabase_storage_adminStorage
supabase_realtime_adminRealtime
supabase_replication_adminSynchronizes Read Replicas
postgresSupabase Dashboard and External Tools (e.g., Prisma, SQLAlchemy, PSQL...)
Custom roles defined by userExternal Tools (e.g., Prisma, SQLAlchemy, PSQL...)