熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Oracle >> 正文

關於JDBC客戶端如何連接ORACLE數據庫RAC的負載均衡

2022-06-13   來源: Oracle 

  這篇文章主要介紹如何使用jdbc配置連接數據庫(oracle的RAC配置的數據庫)達到負載均衡的情況該例子是以個NODE的情況說明希望對大家有所幫助

  我的問題是我需要設置oraclex的thin客戶端連接到oracle的RAC環境上

  注:這樣連接可以通過RAC自動平衡負載

  原文如下:

  Hi Tom

  I couldnt find this information easily on the net  So Im submitting it here
and hope you make it available for anyone else looking for this information

  My problem was I needed to configure the Oracle x thin driver (type IV) to
connect to an Oracle Real Application Cluster (RAC) environment

  For example assuming you have a database called RAC_DB with two nodes node
and node

  You would need to configure your tnsnamesora with the following information in
the following way:

  RAC_DB =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = node)(PORT = ))
      (ADDRESS = (PROTOCOL = TCP)(HOST = node)(PORT = ))
      (LOAD_BALANCE = yes)
      (FAILOVER = on)
    )
    (CONNECT_DATA =
      (SERVICE_NAME = RAC_DB)
      (FAILOVER_MODE = (TYPE = SELECT)
                       (METHOD = BASIC)
                       (RETRIES = )
                       (DELAY = )
      )
    )
  )

  Now if you start a SQL*PLUS session then you should see a connection on the
node instance  If you start another SQL*PLUS session then Oracle should
connect you to the node instance (automatic load balancing)  Its actually
pretty cool to see the first time

  To pass this same information to the Oracles JDBC thin driver you essentially
concatenate a shorten version of the tnsnames information above and pass this to
the driver

  String userid = scott;
  String password = tiger;

  String tnsnames_info =
    (DESCRIPTION=(ADDRESS_LIST= +
    (ADDRESS=(PROTOCOL=TCP)(HOST=node)(PORT=)) +
    (ADDRESS=(PROTOCOL=TCP)(HOST=node)(PORT=)) +
    (LOAD_BALANCE=yes)(FAILOVER=on)) +
    (CONNECT_DATA=(SERVICE_NAME=rac_db))) ;

  String url = jdbc:oracle:thin:@ + tnsnames_info;

  DriverManagerregisterDriver(new oraclejdbcOracleDriver());
  Connection dbConnection = DriverManagergetConnection(url userid password);

  Thats it  If your application creates multiple connection to the database
then you should see these connections load balance across the two instances

  One last note Oracle only supports connection to a RAC configuration with the
i drivers so you should try to get the latest Oracle JDBC thin driver

  HTH
Peter

  
and we said

  you made it really hard  you just needed the service!  the load balancing and
all could be/should be setup on the listener side!

  you have one listener both databases register with it as a service

  that would be another option

  Reviews

  
I think we tried that and it didnt work  September
Reviewer:  Peter Tran  from Houston TX USA

  Hi Tom

  Im pretty sure we tried that but it didnt work with the thin driver  That
approach will work if you use the OCI driver but not with the thin driver

  Please send me an example of what you mean or what files I should configure to
test it out

  Im always opened to easier options

  Thanks
Peter

  Followup:
you need to set up mts and a single listener thats it

  pmon on each of the rac instances will tell the listener about the load and away
it goes  you might not see the round robin right off (both are not yet
loaded) so itll be an unbalanced load balance initially but as the system
ramps itll balance out

  
Unknown territory  September
Reviewer:  Peter Tran  from Houston TX USA

  Im sorry but I really lost you with that last recommendation  Rather than
frustrate you with my ignorance can you recommend the Oracle documentation that
I should read to brush up on this information?

  Ill read this first and come back with questions if Im still lost

  For example I dont understand why you want me to setup the database as MTS
Why cant I use dedicated server mode?

  Thanks for the quick response

  Peter

  Followup:
in order for a single listener to service many instances on different
machines the listener must be servicing shared server connections the
listener cannot fork/exec a dedicated server since the listener may well not
be running on the machine the instance is on  it needs to know dispatcher
addresses to redirect the client request to

  htm

  it is just inherit in the architecture


From:http://tw.wingwit.com/Article/program/Oracle/201311/17131.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.