allanbatista
8/28/2018 - 3:06 PM

Set MAX timeout IDLE postgres connection

This set max time to close connection in postgres connections

[https://www.postgresql.org/docs/9.6/static/runtime-config-client.html#GUC-IDLE-IN-TRANSACTION-SESSION-TIMEOUT](Postgres 9.6 Documentation)

Change max default timeout

SET SESSION idle_in_transaction_session_timeout = '5min';

Force Close connections

SELECT pg_terminate_backend(pid)
    FROM pg_stat_activity
    WHERE datname = 'database_name'
      AND pid <> pg_backend_pid()
      AND state = 'idle'