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 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?

| improve this answer | |

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

| improve this answer | |
  • Do you know of a parameter for the following states: idle in transaction (aborted) or disabled ? – Stephan Sep 29 '17 at 20:50
  • @Stephan: I would assume "idle in transaction (aborted)" is covered by the mentioned option. – a_horse_with_no_name Sep 29 '17 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.