Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Postgres performance optimization and best practices guide maintained by Supabase
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/conn-idle-timeout.md
1---2title: Configure Idle Connection Timeouts3impact: HIGH4impactDescription: Reclaim 30-50% of connection slots from idle clients5tags: connections, timeout, idle, resource-management6---78## Configure Idle Connection Timeouts910Idle connections waste resources. Configure timeouts to automatically reclaim them.1112**Incorrect (connections held indefinitely):**1314```sql15-- No timeout configured16show idle_in_transaction_session_timeout; -- 0 (disabled)1718-- Connections stay open forever, even when idle19select pid, state, state_change, query20from pg_stat_activity21where state = 'idle in transaction';22-- Shows transactions idle for hours, holding locks23```2425**Correct (automatic cleanup of idle connections):**2627```sql28-- Terminate connections idle in transaction after 30 seconds29alter system set idle_in_transaction_session_timeout = '30s';3031-- Terminate completely idle connections after 10 minutes32alter system set idle_session_timeout = '10min';3334-- Reload configuration35select pg_reload_conf();36```3738For pooled connections, configure at the pooler level:3940```ini41# pgbouncer.ini42server_idle_timeout = 6043client_idle_timeout = 30044```4546Reference: [Connection Timeouts](https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-IDLE-IN-TRANSACTION-SESSION-TIMEOUT)47