jdbc對oracle RAC方式的支援
阿新 • • 發佈:2019-01-06
1)JDBC連線的配置方式
,既然資料庫本身已經支援了RAC,那麼只要在JDBC連線字串中將RAC的配置加上去即可, 根據資料和目前的業務需求,我們的針對HOST=10.87.25.37這臺主機的資料庫例項的JDBC連線字串應該這樣配置
URL="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
(HOST=10.87.25.37)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)
(HOST=10.87.25.38)(PORT=1521))
(HOST=10.87.25.39)(PORT=1521))
(FAILOVER=on)(LOAD_BALANCE=off))
(CONNECT_DATA= (SERVICE_NAME=bidwb)))"
這個連線配置表示只支援failover,不支援loadbalance.根據藍色字串可以表示.即按照順序,使用該JDBC字串獲取的連線,將根據配置的主機的先後順序,依次進行failover
即如果在10.87.25.37資料庫例項不能被訪問,那麼就轉到10.87.25.38執行,如果10.87.25.38也資料庫例項不能被訪問,那麼就轉到10.87.25.39執行
同理
對於HOST=10.87.25.38這臺主機的資料庫例項的JDBC連線字串應該這樣配置
URL="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
(HOST=10.87.25.38)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)
(HOST=10.87.25.39)(PORT=1521))
(HOST=10.87.25.37)(PORT=1521))
(FAILOVER=on)(LOAD_BALANCE=off))
(CONNECT_DATA= (SERVICE_NAME=bidwb)))"
對於HOST=10.87.25.39這臺主機的資料庫例項的JDBC連線字串應該這樣配置
URL="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)
(HOST=10.87.25.39)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)
(HOST=10.87.25.37)(PORT=1521))
(HOST=10.87.25.38)(PORT=1521))
(FAILOVER=on)(LOAD_BALANCE=off))
(CONNECT_DATA= (SERVICE_NAME=bidwb)))"
即只是各個Host的順序不同
2)本地服務名連線的配置方式
對於HOST=10.87.25.37這臺主機的資料庫例項的本地服務名應該這樣配置
37bidwb =
(DESCRIPTION =
(ADDRESS_LIST=
(ADDRESS= (PROTOCOL = TCP)(HOST = 10.87.25.37)(PORT = 1521))
(ADDRESS= (PROTOCOL = TCP)(HOST = 10.87.25.38)(PORT = 1521))
(ADDRESS= (PROTOCOL = TCP)(HOST = 10.87.25.39)(PORT = 1521))
(FAILOVER = on)
(LOAD_BALANCE = off)
)
(CONNECT_DATA= (SERVICE_NAME = bidwb))
)對於HOST=10.87.25.38這臺主機的資料庫例項的本地服務名應該這樣配置
37bidwb =
(DESCRIPTION =
(ADDRESS_LIST=
(ADDRESS= (PROTOCOL = TCP)(HOST = 10.87.25.38)(PORT = 1521))
(ADDRESS= (PROTOCOL = TCP)(HOST = 10.87.25.39)(PORT = 1521))
(ADDRESS= (PROTOCOL = TCP)(HOST = 10.87.25.37)(PORT = 1521))
(FAILOVER = on)
(LOAD_BALANCE =off)
)
(CONNECT_DATA= (SERVICE_NAME = bidwb))
)對於HOST=10.87.25.39這臺主機的資料庫例項的本地服務名應該這樣配置
37bidwb =
(DESCRIPTION =
(ADDRESS_LIST=
(ADDRESS= (PROTOCOL = TCP)(HOST = 10.87.25.39)(PORT = 1521))
(ADDRESS= (PROTOCOL = TCP)(HOST = 10.87.25.37)(PORT = 1521))
(ADDRESS= (PROTOCOL = TCP)(HOST = 10.87.25.38)(PORT = 1521))
(FAILOVER = on)
(LOAD_BALANCE = off)
)
(CONNECT_DATA= (SERVICE_NAME =bidwb))
)配置方式與JDBC連線字串大同小異 配置也表示只支援failover,不支援loadbalance.根據藍色字串可以表示.即按照順序,使用該JDBC字串獲取的連線,將根據配置的主機的先後順序,依次進行failover. 測試方式也應該分為兩種,一種是測試JDBC連線字串,一種是測試本地服務名. 測試JDBC連線字串可以通過儲存過程任務來執行,這也是我們最初的測試目標. 我們可以通過關閉資料庫監聽的方式,看是否能夠自動地failover.,例如一個儲存過程本來是 在37 Oracle上執行,現在關閉37 Oracle的監聽,測試該儲存過程仍否能夠正常執行. 一種是測試本地連線字串,這種應該沒問題,因為是oracle本身的客戶端來支援,可以通過 OCI抽取或Oracle裝載來測試,測試方式與上類似