Global timeout examples persist server changes and terminate sessions or transactions
Source references: 1The recommended solution uses `ALTER SYSTEM` to set a 30-second idle-in-transaction timeout and a 10-minute idle-session timeout, then reloads configuration. These are persistent server-wide changes, not temporary settings for the connection being diagnosed; terminated idle transactions roll back.
Legitimate interactive transactions, migrations, administration tools, or pooled sessions may disconnect or roll back unexpectedly, causing application errors, failed work, and outages.
The recommended code uses `ALTER SYSTEM` and reloads configuration, making a server-level change rather than limiting it to the diagnosed session. Once active, idle-in-transaction connections are terminated after 30 seconds and fully idle connections after 10 minutes; uncommitted work in the former rolls back and all applications on the instance may be affected. Users can require workload/pool assessment, session- or role-scoped alternatives, production approval, and a rollback plan.
**Correct (automatic cleanup of idle connections):**```sql-- Terminate connections idle in transaction after 30 secondsalter system set idle_in_transaction_session_timeout = '30s';-- Terminate completely idle connections after 10 minutesalter system set idle_session_timeout = '10min';-- Reload configurationselect pg_reload_conf();```