DB Does Not Reconnect After Connection Drop - spring

I have an application using SpringData, HikariCP and Oracle 11. When the connection to the DB drops and comes back the application is unable to communicate with the DB unless the application is restarted. I tried adding the following properties as some suggested on similar questions but they did not solve the problem.
spring.datasource.remove-abandoned=true
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
Any ideas?

These properties are NOT for hikaricp. so they are not in effect.
Refer HikariCP for the supported properties.

For Oracle i think SELECT 1 isn't the appropriate Query.
Can you try :
SELECT 1 FROM any_existing_table WHERE 1=0

Related

Specify v$session.program for R2DBC Oracle connection

I was trying to set the v$session.program at the connection from a R2DBC Oracle connection (within a Spring application)
For now I've tried this but without success.
ConnectionFactories.get(ConnectionFactoryOptions.parse(dbUrl).mutate().option(Option.valueOf("v$session.program"), "PROGRAMNAME").build());
Would this be possible to set in any way?
Thanks for help.
Oracle R2DBC 0.4.0 does not support the v$session properties as ConnectionFactoryOptions. However, I think it should, so I'll be adding support for that in the next release of Oracle R2DBC.
If anyone needs a temporary workaround, these properties can be set as JVM system properties. System properties will bypass Oracle R2DBC's connection property filter.

Set JDBC cursor type with Spring

We have developed a Spring Boot Java application which access a DB2 database.
Now the system has been live for some time, we see the DB2 database crash every few weeks, which has caused us to review what cursor settings we have used.
This is where I have struggled - I just cant seem to find a way to influence the JDBC cursor types through Spring. And I worry that we may now need to rewrite the application with direct JDBC calls in order to be able to influence the cursor settings.
I am not a spring developer but have worked extensively with JDBC over the years which is why I have been asked to look at this.

Socket timeout property for db2jcc4 driver for db2 database using Hikari CP

I am connecting to Db2 database through spring boot application (2.1.2 release).. Hikari cp is the connection pool.. Db2 jdbc driver is db2jcc4 4.26.14 . I am receiving Error code - 4499:connection is reset message after my application runs for few days. On restart it starts working fine.
Found in one of the thread setting the socket timeout property may help. Can some one please let me know how to set the socket timeout property for db2 driver.
I have set maxLifetime as 130000, idleTimeout as 120000, ConnectionTimeout as 300000, minimumIdle as 0,maxPoolSize as 10.
Any help will be really appreciated to solve this issue.
Thanks in Advance.
At db2jcc4.jar level, different kinds of timeout settings are availble , and may depend on the target Db2-server-platform and Db2-server-version and HA configuration. Your question omits these facts about your environment.
Examples of settable attributes at db2jcc4.jar level for recent versions of this driver include these below:
blockingReadConnectionTimeout
commandTimeout
connectionTimeout
keepAliveTimeout
loginTimeout
memberConnectTimeout
queryTimeoutInterruptProcessingMode
timerLevelForQueryTimeOut
Detailed study is needed to comprehend these, and the related settings (and how they relate to Hikari level configuration), as well as comprehensive test coverage.
Documentation below:
https://www.ibm.com/support/knowledgecenter/SSEPGG_11.5.0/com.ibm.db2.luw.apdv.java.doc/src/tpc/imjcc_r0052038.html

spring boot datasource tomcat jdbc properties not working

I have a Spring Boot application (version 1.5.1.RELEASE) and I am using spring-boot-starter-data-jpa as a dependency to manage my database. I am using postgres as my database and configured it using the below properties.
spring.datasource.url=${POSTGRES_URL}
spring.datasource.username=${POSTGRES_USER}
Now when I run my tests which are almost 120, I get too many client already open error for abou 10 test cases while starting the test case itself and it fails.(remaining 100 test cases pass with success as they are able to get a connection to database)
First thing I did is increased my default postgres max connections count from 100 to 200 in the postgres server config file and my tests pass successfully after this change.
Now I investigated a bit and tried setting the parameters for connection pooling properties such as :
spring.datasource.tomcat.max-active=200
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.max-wait=10000
However these properties do not work and the tests fails again giving the same error as above. I tried reading from multiple different blogs and spring documentation for setting the connection pool properties but did not find what might be going wrong with me.
I also think that if I set the above property spring.datasource.tomcat.max-active to 100 connections it should work with the help of tomcat jdbc pooling as i think in current scenario it is trying to open a new connection to database for each test case and I am in a fear that this same scenario might happen when I deploy this code to production environment and a new connection will be opened to the database for each request.
Does anyone have faced this problem before or is there something wrong I am doing.
Thanks in advance for the help.
Try upgrading Spring boot version, 1.5.10-RELEASE is the current version.
Also, I found the connection pool properties for my application were not being applied when the property prefix tomcat was included. If you are still having issues try removing that.
i.e.
spring.datasource.tomcat.max-active=200
Becomes
spring.datasource.max-active=200
See https://artofcode.wordpress.com/2017/10/19/spring-boot-configuration-for-tomcats-pooling-data-source

Configure JDBC oracle specific property v$session.program using Jboss and JPA (hibernate)

I'd like to set the v$session.program Oracle property in order to have information available in the session table. I'm using JPA with a jndi XA datasource created with an oracle-xa-ds.xml deployed in the deploy folder of Jboss, and therefore I haven't access to the constructor of the Connection.
I have access to the Connection object, in JPA 2 using unwrap, in JPA 1 by casting JPA to Hibernate classes, but there are no properties setter (only Client Info properties that are the way to proceed starting JDBC 4.0).
So my question is, using JPA (with Hibernate) using Jboss 4.2 :
Is it possible to configure the v$session.program in the persistence.xml ?
Is it possible to configure the v$session.program in the oracle-ds.xml ?
Is their any other approach to the solution ?
Thank you for any valuable comments and answers !
I had the same Problem today, after much fiddeling and reading documentation finally I had the Eureka moment:
Add following parameter:
<xa-datasource-property name="connectionProperties">v$session.program=YourUniqueName</xa-datasource-property>
Thats all.
I'm pretty sure this must be documented somewhere but here is what we can find in the JBoss wiki:
How To Specify "PROGRAM" Oracle Connection Property
JBoss Version: JBoss 4.0.3 SP1, Oracle DB Version: 10g
To be able to distinguish the JDBC
connections on the Oracle server side,
which are created by different JBoss
instances, Oracle's PROGRAM connection
property might be set within the
Oracle specific JDBC datasource config
file by using the following tags:
<connection-property name="v$session.program">ADistinguishedNameForPROGRAMProperty</connection-property>
i.e.
...
<connection-url>AConnectionURL</connection-url>
<connection-property name="v$session.program">ADistinguishedNameForPROGRAMProperty</connection-property>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
...
That way the DBAs can have proper
granularity in:
AWRs
v$session view
Other tools which are checking/evaluating PROGRAM connection
property

Resources