title: PGBouncer IDLE Connections not Closing on Postgres
body: <p>We have a setup where we are running 6 PgBouncer processes and our performance benchmarks degrade linearly with time. The longer PgBouncer has been running, the longer the connections to Postgres exist results in slower response times for the benchmark.  We have a multi-tenant schema separated database with 2000+ relations.  We are configured for Transaction Mode pooling right now. Over time, we see the memory footprint of each Postgres process climb and climb and climb, and again, this results in poorer performance.</p>
  <p>We have tried to be more aggressive in cleaning up idle connections with the following settings:</p>
  <pre><code>min_pool_size=0
  
  server_idle_timeout=30 (seconds)
  
  server_lifetime=120 (seconds)
  </code></pre>
  <p>The problem we see is that invariably we still end up with lots of idle connections in Postgres.  When we monitor PgBouncer with &quot;show pools&quot;, we see sv_idle count going up and down so we are assuming that the settings are working in PgBouncer, but this is not translating to fewer idle connections in Postgres.  It's as if PgBouncer is really not terminating the sessions to Postgres.</p>
  <p>I have looked around quite a bit for a solution and tested several different options - but have not been able to get any where. I read elsewhere about cron jobs to remove idle connections from Postgres but I really do not want to do that in Production and would rather have PgBouncer clear these idle connections out fully.</p>
  <p>We are on Postgres 9.6 and using PgBouncer version 1.15</p>
  <p>Any help is appreciated.</p>
  <p>/**</p>
  <p>should have pointed this out in the original comment - we have multiple PgBouncers running and we are using Unix Sockets to do this. We are not sure if this is having an impact on Postgres leaving connections behind.</p>
  <p>**/</p>
  <p>Thanks</p>