The following configuration settings can help us to detect connection leaks:
- removeAbandoned: This flag should be true. It means that abandoned connections are removed if they exceed removeAbandonedTimeout.
- removeAbandonedTimeout: This is in seconds. A connection is considered abandoned if it's running more than removeAbandonedTimeout. The value depends on the longest running query in your applications.
So, in order to get optimal pool sizing, we need to modify our configuration to meet one of following conditions:
<Resource type="javax.sql.DataSource" name="jdbc/TestDB" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/TestDB" username="test" ...