JDBC Oracle瘦客户端故障转移到第二个数据库 [英] JDBC Oracle Thin Client to Fail Over to Second DB
问题描述
我已阅读到可以设置JDBC瘦客户端连接字符串,以便我的Java程序将首先尝试连接到第一个数据库,然后,如果出现问题,它将尝试连接到第二个数据库. /p>
但是实际上这是没有发生的.
如果我使用以下字符串:
jdbc:oracle:thin:@(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = site1)
(PORT = 1521)
)
(ADDRESS =
(PROTOCOL = TCP)
(HOST = site2)
(PORT = 1521)
)
)
(FAILOVER=ON)
(FAILOVER_MODE=
(TYPE=SELECT)
(METHOD=BASIC)
(RETRIES=20)
(DELAY=3)
)
(LOAD_BALANCE = OFF)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = MYDB)
)
)
现在我知道site1
处于关闭状态,而site2
处于打开状态.如果我在列表中首先指定site2
,那么我会建立连接(就像我希望尝试连接到site2
一样).但是,当我先放置site1
时,会得到与尝试直接连接到site1
相同的错误-这是:
java.util.concurrent.ExecutionException:
java.lang.RuntimeException:
java.sql.SQLException:
ORA-01033: ORACLE initialization or shutdown in progress
Oracle瘦客户端是否要求第一个数据库在连接上工作,并且仅在连接期间出现问题时才进行故障转移?我想要的是让应用程序在与第一个服务器的连接失败时尝试下一个服务器(我可以使用try { ... } catch { ... }
应用程序逻辑来做到这一点,但希望驱动程序为我处理细节).
您使用与SID相同的service_name. 即使您停止服务MYDB,它也总是会由于SID而找到它. 主数据库处于挂载模式,因此可以解释您得到的错误.
创建一个新的service_name(而不是您的SID)并使用该servicename进行连接
例如:service_name = MYDB_CLIENT
I've read that I can set up a JDBC thin client connection string so that my Java program will attempt to connect to the first database first then, if there's a problem, it will attempt to connect to the second database.
However this isn't happening in practice.
If I use the following string:
jdbc:oracle:thin:@(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(PROTOCOL = TCP)
(HOST = site1)
(PORT = 1521)
)
(ADDRESS =
(PROTOCOL = TCP)
(HOST = site2)
(PORT = 1521)
)
)
(FAILOVER=ON)
(FAILOVER_MODE=
(TYPE=SELECT)
(METHOD=BASIC)
(RETRIES=20)
(DELAY=3)
)
(LOAD_BALANCE = OFF)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = MYDB)
)
)
Now I know that site1
is down and site2
is up. If I specify site2
first in my list then I get a connection (just like I'd expect if I just tried to connect to site2
). However when I put site1
first I get the same error as if I tried to connect directly to site1
- which is:
java.util.concurrent.ExecutionException:
java.lang.RuntimeException:
java.sql.SQLException:
ORA-01033: ORACLE initialization or shutdown in progress
Does the Oracle thin client require the first database to be working on connect and only failover if something goes wrong during the connection? What I want is for the application to try the next server if the connection to the first server fails (which I could do using try { ... } catch { ... }
application logic but would prefer the driver to take care of the details for me).
Your using the same service_name as your SID. Even if you stop the service MYDB, it'll always find it because of the SID. primary db is in mount mode, so that explains the error you get.
Create a new service_name (other than your SID) and connect on that servicename
For instance: service_name = MYDB_CLIENT
这篇关于JDBC Oracle瘦客户端故障转移到第二个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!