0

我使用 TNS 字符串作为我的 Grails 数据源的 url,带有两个 oracle DB(ora01、ora02)。它在正常操作期间连接到 db 服务正常。这是配置:

dbString = "jdbc:oracle:thin:@(DESCRIPTION = 
                  (ADDRESS_LIST = 
                        (LOAD_BALANCE = ON) 
                        (ADDRESS = (PROTOCOL = TCP)(HOST = ora01.foo)(PORT = 1521)) 
                        (ADDRESS = (PROTOCOL = TCP)(HOST = ora02.bar)(PORT = 1521))
                  ) 
                  (CONNECT_DATA = (SERVICE_NAME = orastage)))"

dataSource 
{
    pooled = true
    driverClassName = "oracle.jdbc.OracleDriver"
    username = foo
    password = bar
    url = dbString
    logSql = false
}   

当 DBA 关闭 ora01 并重新启动 ora02 时,Grails 应用程序没有意识到并抛出 JDBC 错误:

2013-04-26 11:41:35,428 ERROR JDBCTransaction - JDBC commit failed
java.sql.SQLRecoverableException: No more data to read from socket
at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1142)
at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1099)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:288)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C7Ocommoncall.doOCOMMIT(T4C7Ocommoncall.java:75)
at oracle.jdbc.driver.T4CConnection.doCommit(T4CConnection.java:565)
at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:3851)
at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:3857)
at org.apache.commons.dbcp.DelegatingConnection.commit(DelegatingConnection.java:334)

我的配置看起来好吗?我假设 Grails 可以将 TNS 字符串作为数据源 URL,因为它在我们尝试使数据库失败之前连接正常 - 这是正确的吗?就像应用程序仍在尝试连接到死数据库而不是尝试其他节点。我需要让 Grails 做任何特定的事情来切换到现在工作的节点吗?

4

1 回答 1

0

尝试(FAILOVER=ON)在描述中使用。

dbString = "jdbc:oracle:thin:@(DESCRIPTION = 
                  (ADDRESS_LIST = 
                        (LOAD_BALANCE = ON) 
                        (FAILOVER=ON)
                        (ADDRESS = (PROTOCOL = TCP)(HOST = ora01.foo)(PORT = 1521)) 
                        (ADDRESS = (PROTOCOL = TCP)(HOST = ora02.bar)(PORT = 1521))
                  ) 
                  (CONNECT_DATA = (SERVICE_NAME = orastage)))"
于 2013-04-26T13:52:51.437 回答