On 15/06/2015 15:35, Daniel Mikusa wrote: > On Mon, Jun 15, 2015 at 4:42 AM, Jose María Zaragoza <[email protected]> > wrote: > >> Hello: >> >> >> I'm using Tomcat 7.0.59 and PostgreSQL JDBC driver 9.4-1201-jdbc4 >> >> The context.xml settings are >> >> >> <Resource auth="Container" type="javax.sql.DataSource" >> factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" > > driverClassName="org.postgresql.Driver" >> initialSize="0" maxActive="100" maxIdle="20" >> maxWait="10000" mindIdle="0" >> name="datasource/bbdd" password="fake" >> removeAbandoned="true" >> >> >> url="jdbc:postgresql://localhost:9999,localhost:5432,localhost:5433/bbdd?LoginTimeout=3&loadBalanceHosts=false" >> username="foo" validationQuery="SELECT 1" >> testOnBorrow="true" timeBetweenEvictionRunsMillis="0"/> >> >> >> I've configured JDBC driver in failover mode ( as you can see in URL >> definition ) >> >> When I test this configuration ( I stop/start databases but , at >> least, there is one running ) , sometimes I'm getting this error >> message: >> >> >> org.apache.ibatis.exceptions.PersistenceException: >> ### Error querying database. Cause: >> org.postgresql.util.PSQLException: This connection has been closed. >> >> How is it possible if testOnBorrow="true" and validationQuery="SELECT 1" ? >> > > Try setting validationInterval to a lower value. It defaults to 30s, which > means it will only run the query once per 30s. > > http://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html#Tomcat_JDBC_Enhanced_Attributes
I was about to ask what on earth you were talking about since DBCP has no concept of validation interval but you are correct. Despite the use of DBCP in the subject, the OP isn't using DBCP at all. Ignore my previous comments on this thread. They were only valid for DBCP, not Tomcat's jdbc-pool implementation (which is what the OP is actually using). Mark > > >> How I can debug if validationQuery is working as I want ? >> > > 1.) Start Tomcat, make sure the app is working. > 2.) Stop the DB. > 3.) Your app should stop working, since it can't get a connection. Also, > any pooled connections will now be bad. > 4.) Start the DB. > 5.) Your app should be working again. If the pool is configured properly > as your app requests connections, it should remove the bad connections and > replace them with new ones. > > Dan > > > >> >> >> Thanks and regards >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
