Clients connect to our PostgreSQL 8.3 database but leave the connections opened. Is it possible to configure PostgreSQL to close those connections after a certain amount of inactivity?
Finally, I have a solution.
I'll use the tool PgBouncer with its parameter
Another approach would consist in using some cron-like tool running a query periodically to find idle connections.
Once those idle connections are found, a simple call to
pg_terminate_backend will close them.
See an in depth description of this approach in the anwser of the following question:
Since Postgres 9.5 you can configure a timeout for connection in the state "idle in transaction" - which is a bit different just "idle" but typically "idle in transaction" connection generate more problems
See the manual for details: idle_in_transaction_session_timeout