PostgreSQL 9.6 has many new features that can help the administrator to reduce work and make systems more robust.
One of those features is the idle_in_transaction_session_timeout function.