Is it possible to configure PostgreSQL to automatically close idle connections?
Finally, I have a solution.
I'll use the tool PgBouncer with its parameter server_idle_timeout.



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: 

How to close idle connections in PostgreSQL automatically?