Oracle

將 SQLcl 與 EZconnect 和多個主機名一起使用 (ADDRESS_LIST=)

  • March 26, 2019

這是我們的經典tnsnames.ora

test1=
(DESCRIPTION=
   (CONNECT_TIMEOUT=4)
   (TRANSPORT_CONNECT_TIMEOUT=3)
   (ENABLE=BROKEN)
   (ADDRESS_LIST=
       (ADDRESS=(PROTOCOL=TCP)(HOST=example1.example.com)(PORT=1521))
       (ADDRESS=(PROTOCOL=TCP)(HOST=example2.example.com)(PORT=1521))
   )
   (CONNECT_DATA=
       (SERVER=DEDICATED)
       (SERVICE_NAME=EXAMPLE.EXAMPLE.DBS)
   )
)

我使用這個 SQLcl 命令:

sql -nohistory -noupdates -S $username/$password@$hostname:$port/$servicename @$filename

如何指定多個主機名?不止一個?它是某種主動被動集群(Exadata)。

在第一個答案後編輯:

我在 shell 腳本中添加了(在這個 dir 中tnsnames.ora):

TNS_ADMIN=/example/example

我打電話$sqlcl -nohistory -noupdates -S $username/$password@"MY-DB" @$filename並取回錯誤:

./script.sh
 USER          = MY_USER
 URL           = jdbc:oracle:thin:@MY-DB
 Error Message = IO Error: Unknown host specified
 USER          = MY_USER
 URL           = jdbc:oracle:thin:@MY-DB:1521/MY-DB
 Error Message = IO Error: Invalid connection string format, a valid format is: "host:port:sid"

EZconnect 不適合這樣的事情。

SQLcl 也可以使用tnsnames.ora。只需創建一個並使用它:

sql -nohistory -noupdates -S $username/$password@test1 ...

或者,如果您真的想將所有這些東西作為命令行參數提供,您也可以這樣做:

sql -nohistory -noupdates -S $username/$password@"(DESCRIPTION= (CONNECT_TIMEOUT=4) (TRANSPORT_CONNECT_TIMEOUT=3) (ENABLE=BROKEN) (ADDRESS_LIST= (ADDRESS=(PROTOCOL=TCP)(HOST=example1.example.com)(PORT=1521)) (ADDRESS=(PROTOCOL=TCP)(HOST=example2.example.com)(PORT=1521))) (CONNECT_DATA= (SERVER=DEDICATED) (SERVICE_NAME=EXAMPLE.EXAMPLE.DBS)))" ...

使用 tnsnames.ora:

[oracle@o71 ~]$ export JAVA_HOME=/u01/app/oracle/product/19.0.0/dbhome_1/jdk
[oracle@o71 ~]$ export PATH=/home/oracle/sqlcl/bin:$JAVA_HOME/bin:$PATH
[oracle@o71 ~]$ export TNS_ADMIN=/u01/app/oracle/product/19.0.0/dbhome_1/network/admin
[oracle@o71 ~]$ cat /u01/app/oracle/product/19.0.0/dbhome_1/network/admin/tnsnames.ora
MIN19=
 (DESCRIPTION =
   (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.71)(PORT = 1521))
   (CONNECT_DATA =
     (SERVER = DEDICATED)
     (SERVICE_NAME =  min19_o71)
   )
 )

[oracle@o71 ~]$ sql bp/bp@min19

SQLcl: Release 18.4 Production on Tue Mar 26 09:28:11 2019

Copyright (c) 1982, 2019, Oracle.  All rights reserved.

Last Successful login time: Tue Mar 26 2019 09:28:12 +01:00

Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.2.0.0.0


SQL>

引用自:https://dba.stackexchange.com/questions/233029