Postgres sessions are idle with query = COMMIT or ROLLBACK : <p>I have a Postgres 9.5 database for a web-based Java application.  Sometimes, the number of sessions suddenly spikes up due to a long running query, and these sessions are not cleared immediately.  When I check pg_stat_activity, query column shows COMMIT or ROLLBACK with a stage of idle.   This is causing Postgres to hit high thresholds of max_connections, which can possibly cause Production outage.</p>

<p>query | ROLLBACK
state | idle
count | 167</p>

<p>query | COMMIT
state | idle
count | 280</p>

<ol>
<li>What are these COMMIT/ROLLBACK idle sessions? </li>
<li>How can I get these idle sessions to clear immediately?  </li>
<li>How can I reduce the number of these idle sessions from being created?</li>
</ol>

<p>Thanks</p>
