We are using SpringBoot 2.1.x version so Hikari is the default DataSource implementation. However, I am not sure how to configure Hikari settings to auto reconnect to our Oracle database after database maintenance/restart or network connection issue.
We have the following hikari settings but it does not seem to help.
account.datasource.url: jdbc:oracle:thin:#myserver:1521:DEV
account.datasource.username: user
account.datasource.password: xxxx
account.datasource.driverClassName: oracle.jdbc.driver.OracleDriver
account.datasource.hikari.connection-timeout: 30000
account.datasource.hikari.maximum-pool-size: 3
account.datasource.hikari.idle-timeout: 60000
account.datasource.hikari.max-lifetime: 1800000
account.datasource.hikari.minimum-idle: 2
It failed to reconnect after network connection to the database got restored.
Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30033ms.
Any other account.datasource.hikari.xxxxx will help to auto reconnect to the database ?
From the HikariCP docs:
connectionTestQuery
If your driver supports JDBC4 we strongly
recommend not setting this property. This is for "legacy" drivers that
do not support the JDBC4 Connection.isValid() API. This is the query
that will be executed just before a connection is given to you from
the pool to validate that the connection to the database is still
alive. Again, try running the pool without this property, HikariCP
will log an error if your driver is not JDBC4 compliant to let you
know. Default: none
So I'd suggest verifying that your JDBC Driver is actually JDBC4 compliant. If it's not - set the above property.
Related
I'm using Quarkus and have a project with two default datasources connecting to the same database, one uses JDBC (Agroal) for a postgres copy operation, the other uses reactive (PgPool) for all other sql operations.
There's an option in quarkus QUARKUS_DATASOURCE_JDBC_POOLING_ENABLED that can be set to false to disable connection pooling for JDBC datasource. So my question is:
Does reactive and JDBC datasources share the same connection pool? If I disable the JDBC pooling, will it affect the reactive connection pool?
Is there a way to verify such behavior?
Thank you all.
Trying to figure out the behavior between reactive and JDBC datasource regarding connection pooling. Expecting that turning off the pooling for JDBC via the config QUARKUS_DATASOURCE_JDBC_POOLING_ENABLED will not impact reactive connection pool.
We're using JDBC Connection through Hikari CP to connect to Apache Phoenix & we're facing "HConnection-Closed" Issues. It's because of stale connections present in the pool and the pool does not get cleared until we restart the applications.
Has anyone faced something like above (may not be same DB)?
Is there any recommended approach to connect to Phoenix from Spring applications?
I want a database connection that has gone idle to be dropped once its maxLifetime has been reached.
How can we do this in spring boot/hikari? Is this achieved with these 2 properties?
idleTimeout
maxLifetime
How can I check that idle connections are actually being dropped? Any logs I can activate?
What should be the ideal values?
read Hikari documentation
check DB activity via SQL (there you can see all transaction statistics)
add logging
try locally with Postgres in Docker
I configured Hikari following this tutorial: https://www.baeldung.com/spring-boot-hikari
When Spring Boot starts Hikari starts too, as follows in the next image:
Is it possible to configure Hikari to start when the first ReST request is being received?
Quoted from Hikari's official document on Github:
connectionTestQuery
If your driver supports JDBC4 we strongly recommend not setting this property. This is for "legacy" drivers that do not support the JDBC4
Connection.isValid() API. This is the query that will be executed just
before a connection is given to you from the pool to validate that the
connection to the database is still alive. Again, try running the pool
without this property, HikariCP will log an error if your driver is
not JDBC4 compliant to let you know. Default: none
As documentation:
"For a pooling DataSource to be created, we need to be able to verify that a valid Driver class is available, so we check for that before doing anything. In other words, if you set spring.datasource.driver-class-name=com.mysql.jdbc.Driver, then that class has to be loadable."(https://docs.spring.io/spring-boot/docs/2.1.6.RELEASE/reference/htmlsingle/)
I'm currently trying to set-up Apache Ignite with C3P0 as my JDBC Connection pool, but I noticed that since the Ignite driver doesn't support transactions, C3P0's not usable.
Has anyone had any luck getting a JDBC connection pool going with the Ignite driver? Suggestions?
EDIT:
Updating with exactly why C3P0 doesn't work with Ignite's JDBC Driver
So take a look at this line of code
To create a new pooled connection, C3P0 attempts to set transaction isolation through the connection/driver.
That eventually leads us to this line of code in the Ignite driver, which basically tells us that the Ignite driver doesn't support SQL transactions.
Ignite itself DOES support transactions as specified here but it appears the JDBC implementation does not.
So I need an alternative to C3P0 if I want to set up a JDBC connection pool; any suggestions?
It turns out the JDBC driver for Apache Ignite isn't currently JDBC compliant. Specifically the part that breaks it is that it doesn't have transaction support. As a result, your typical JDBC-pool implementation won't work with the Ignite Driver
There's now a ticket for this here: https://issues.apache.org/jira/browse/IGNITE-4191
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("org.apache.ignite.IgniteJdbcDriver");
ds.setUrl("jdbc:ignite:cfg://cache=default#file:///the/path/to/ignite-config.xml");
ds.setInitialSize(2);
ds.setMinIdle(2);
Try BasicDataSource http://commons.apache.org/proper/commons-dbcp/configuration.html