title: Django ORM leaves idle connections on Postgres DB
body: <p>Recently, my Django app has been crashing frequently due to database connection errors:</p>
  
  <pre><code>OperationalError: FATAL:  sorry, too many clients already
  </code></pre>
  
  <p>When I go into the app database, I see that indeed there are nearly 100 open connections, all with the same query (executed by the Django ORM) and all in the <code>idle</code> state.</p>
  
  <p>I have been manually doing <code>SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE state = 'idle';</code> but I am perplexed as to why this is happening. Can anyone shed any insight into what is happening here?</p>
  
  <p>My Django database settings do not stray from the defaults (I have not defined <code>CONN_MAX_AGE</code> or anything of that nature).</p>
  
  <p>What could cause this? I'm not doing any advanced Django queries. Is this something that can be solved with a Django setting or perhaps some PostgreSQL configuration? Any advice is appreciated.</p>