Some clients connect to our postgresql database but leave the connections opened. Is it possible to tell Postgresql to close those connection after a certain amount of inactivity ?
TL;DR
IF you're using a Postgresql version >=
9.2
THEN use the solution I came up withIF you don't want to write any code
THEN use arqnid's solutionIF you don't want to write any code
AND you're using a Postgresql version >=14
THEN use Laurenz Albe's solution
pg_stat_activity
) and usepg_terminate_backend
to kill old ones. Easily expressed in a simple query. I'm not sure ifpg_terminate_backend
was available in the pretty-ancient 8.3, though. – Supenpg_stat_activity
table i have lots ofidle
connections that's runningSELECT 1
orSHOW TRANSACTION ISOLATION LEVEL
. Then when I run a second load test, the number kept growing, does this mean that the idle connections were not re-used during second test? Can i use the same solution here to fix it? – Family