Setting the file. One moment.
Skill 01 · Supabase Postgres Best Practices
Subchapter 1.6
references/conn-idle-timeout.mdMarkdown1 KBView on GitHub
Idle connections waste resources. Configure timeouts to automatically reclaim them.
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 locksCorrect (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();For pooled connections, configure at the pooler level:
# pgbouncer.ini
server_idle_timeout = 60
client_idle_timeout = 300Reference: Connection Timeouts (opens in a new tab)