본문 바로가기
FullStack/41. WEB.WAS

[Tomcat] WAS JDBC를 사용한 오라클 이중화 설정

by nakanara 2020. 10. 14.
반응형

일반적으로 DB 이중화에 따른 설정을 WAS에는 하지 않았는데, 그 이중화 설정을 WAS에서 처리할 일이 생겼다.

  • 일반적인 JDBC 설정

(CommonDBCP2에서는 maxActive -> maxTotal, maxWait -> maxWaitMillis로 변경)

<Resource name="datasource" 
    auth="Container"
    type="javax.sql.DataSource" 
    driverClassName="oracle.jdbc.driver.OracleDriver"
    url="jdbc:oracle:thin:@//192.168.x.x:1521/orcl"
    username="user" 
    password="password" 
    maxTotal="10" 
    maxIdle="5"
    maxWaitMillis ="-1"/>

 

  • 이중화에 따른 JDBC 설정

아래 설정 부분을 URL 부분에 한줄로 작성

jdbc:oracle:thin @(
DESCRIPTION= 
    (ADDRESS_LIST= 
        (ADDRESS=(PROTOCOL=TCP)(HOST=dbserv1)(PORT=1521) ) 
        (ADDRESS=(PROTOCOL=TCP)(HOST=dbserv2)(PORT=1521) ) 
        (LOAD_BALANCE=yes) 
        (FAILOVER=yes) 
        (CONNECT_DATA= 
            (SERVER=DEDICATED) 
            (SERVICE_NAME=DBServiceName) 
            (FAILOVER_MODE= 
                (TYPE=SELECT)(METHOD=BASIC)(RETRY=180)(DELAY=5) 
            ) 
        ) 
    ) 
) 
<Resource name="datasource" 
    auth="Container"
    type="javax.sql.DataSource" 
    driverClassName="oracle.jdbc.driver.OracleDriver"
    url="jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=dbserv1)(PORT=1521) ) (ADDRESS=(PROTOCOL=TCP)(HOST=dbserv2)(PORT=1521) ) ... )"
    username="user" 
    password="password" 
    maxTotal="10" 
    maxIdle="5"
    maxWaitMillis ="-1"/>

Commons DBCP 이해하기 : https://d2.naver.com/helloworld/5102792

#tomcat #jdbc #oracle

반응형