简体   繁体   English

当数据库连接中断时,如何对 Oracle 和 grails 项目进行自动池重新连接?

[英]How to do an automatic pooled reconnection on an Oracle and a grails project when a database connection is interrupted?

I have a project that used a grails framework 3.X and Oracle DB, and the project is deployed on tomcat 9.0.X.我有一个项目使用了 grails 框架 3.X 和 Oracle DB,该项目部署在 tomcat 9.0.X 上。

There is a DB connection problem on the project that the DB connection is interrupted and then the project can't reconnect with the DB automatically when the connection, firewall or any network configuration between the project and DB has changed;项目存在DB连接问题,当项目与DB之间的连接、防火墙或任何网络配置发生变化时,DB连接中断,项目无法自动重新连接DB; or the settings of the DB have changed or the DB has restarted.或 DB 的设置已更改或 DB 已重新启动。 Because of that, nowadays, I manually redeploy the project on a tomcat sever when this problem is happening.因此,如今,当发生此问题时,我在 tomcat 服务器上手动重新部署项目。

In order to fix the problem, I tried many changes, but the issue hasn't disappeared yet.为了解决这个问题,我尝试了很多改变,但问题还没有消失。 For example, I changed properties of a dataSource configuration on application.yml and tried different versions of OJDBC driver.例如,我在 application.yml 上更改了 dataSource 配置的属性,并尝试了不同版本的 OJDBC 驱动程序。

The interrupted connection can reconnect automatically when I changed the value of "pool" to false from true on application.yml.当我在 application.yml 上将“pool”的值从 true 更改为 false 时,中断的连接可以自动重新连接。 But, I think that "pool: false" configuration has negative consequences because a DB connection operation is an expensive.但是,我认为“pool:false”配置会产生负面影响,因为数据库连接操作很昂贵。 For instance, to reach a maximum connection limit, ...例如,要达到最大连接限制,...

So, my question is that how to do an automatic pooled reconnection on an Oracle DB and a grails project when a DB connection is interrupted?所以,我的问题是,当数据库连接中断时,如何对 Oracle 数据库和 grails 项目进行自动池重新连接?

My current configuration on application.yml (maybe some properties are changed because of the test):我在 application.yml 上的当前配置(可能因为测试而改变了一些属性):

dataSources:
    dataSource:
        pooled: true
        jmxExport: true
        driverClassName: oracle.jdbc.OracleDriver

environments:
    development:
        dataSources:
            dataSource:
                logSql: false
                dbCreate: update
                url: jdbc:oracle:thin:@localdomain:1521/test
                username: test
                password: test
                properties:
                    maxActive: 50
                    maxIdle: 25
                    minIdle: 1
                    initialSize: 5
                    numTestsPerEvictionRun: 3
                    maxWait: 1000
                    testOnBorrow: true
                    testWhileIdle: true
                    testOnReturn: true
                    minEvictableIdleTimeMillis: 1000
                    timeBetweenEvictionRunsMillis: 1000
                    validationQuery: SELECT 1 FROM DUAL
                    validationQueryTimeout: 5
                    validationInterval: 5
                    removeAbandoned: true
                    removeAbandonedTimeout: 5
    production:
        dataSources:
            dataSource:
                dbCreate: none
                jndiName: "java:comp/env/testDs"
                properties:
                    maxActive: 50
                    maxIdle: 25
                    minIdle: 1
                    initialSize: 5
                    numTestsPerEvictionRun: 3
                    maxWait: 1000
                    testOnBorrow: true
                    testWhileIdle: true
                    testOnReturn: true
                    minEvictableIdleTimeMillis: 1000
                    timeBetweenEvictionRunsMillis: 1000
                    validationQuery: SELECT 1 FROM DUAL
                    validationQueryTimeout: 5
                    validationInterval: 5
                    removeAbandoned: true
                    removeAbandonedTimeout: 5

you can try set validationQuery properties is null, check validationQuery properties is confilct other properties.您可以尝试设置validationQuery 属性为null,检查validationQuery 属性是否与其他属性冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Intellij IDEA在Grails 3项目中连接到Oracle数据库? - How to Connect to Oracle Database in Grails 3 Project with Intellij IDEA? 我是否正确关闭了这个 Oracle 池连接? - Am I closing this Oracle pooled connection correctly? 您将不立即使用池化数据库连接的情况称为什么? - What do you call a situation where the pooled database connection is not used immediately? 如何禁用与Oracle DB的自动重新连接? - How to disable auto reconnection to oracle DB? 如何将CopyManager与连接池数据源一起使用? - How to use CopyManager with connection pooled DataSource? Java项目的不稳定Oracle数据库连接 - Unstable Oracle Database connection for Java-project MySQL/Hibernate - 如何调试不断下降的 MySQL 池连接? - MySQL/Hibernate - How do I debug a MySQL pooled connection that keeps dropping? 使用oracle jdbc连接时如何获取数据库模式名称? - How to get database schema name when using oracle jdbc connection? 数据库 session 上下文中的更改通过池连接重用持续存在 - Changes in database session context persists with pooled connection reuse 对数据库 session 上下文的更改随着池连接重用而持续存在 - Changes to database session context persists with pooled connection reuse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM