Why This Matters
Idle connections waste resources. Connections that sit "idle in transaction" are particularly problematic - they hold locks and prevent VACUUM from reclaiming space.
The Problem
Incorrect - Connections held indefinitely
-- No timeout configured
SHOW idle_in_transaction_session_timeout; -- 0 (disabled)
-- Connections stay open forever, even when idle
SELECT pid, state, state_change, query
FROM pg_stat_activity
WHERE state = 'idle in transaction';
-- Shows transactions idle for hours, holding locks
The Solution
Correct - Automatic cleanup of idle connections
-- Terminate connections idle in transaction after 30 seconds
ALTER SYSTEM SET idle_in_transaction_session_timeout = '30s';
-- Terminate completely idle connections after 10 minutes
ALTER SYSTEM SET idle_session_timeout = '10min';
-- Reload configuration
SELECT pg_reload_conf();
Check Your Connection Patterns
Connect your Supabase project to identify idle connections and optimize your configuration.
Start Supabase Audit