[20111220]tnsnames.ora的定位.txt
1.跟踪在linux下sqlplus的执行过程,可以很容易定位tnsnames.ora的定位过程。
$ export TNS_ADMIN=/tmp
$ strace -o findtnsnames.txt sqlplus scott/xxxx@noexist
$ grep -i tnsname findtnsnames.txt
access("/home/oracle/.tnsnames.ora", F_OK) = -1 ENOENT (No such file or directory)
access("/tmp/tnsnames.ora", F_OK) = -1 ENOENT (No such file or directory)
access("/etc/tnsnames.ora", F_OK) = -1 ENOENT (No such file or directory)
access("/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora", F_OK) = 0
stat("/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora", {st_mode=S_IFREG|0644, st_size=423, ...}) = 0
open("/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora", O_RDONLY) = 9
stat("/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora", {st_mode=S_IFREG|0644, st_size=423, ...}) = 0
stat("/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora", {st_mode=S_IFREG|0644, st_size=423, ...}) = 0
stat("/u01/app/oracle/product/11.2.0/db_1/network/admin/tnsnames.ora", {st_mode=S_IFREG|0644, st_size=423, ...}) = 0
可以确定在linux下,查询路径按照这个顺序:
/home/oracle/.tnsnames.ora => /tmp/tnsnames.ora(TNS_ADMIN) => /etc/tnsnames.ora => $ORACLE_HOME/network/admin/tnsnames.ora
2.windows下我们可以使用sysinternal自带的procmon.exe 工具:
set TNS_ADMIN=D:\tmp
sqlplus scott/btbtms@noexist
查询tnsnames.ora,发现如下:
首先打开c:\tnsnames.ora=>d:\tmp\tnsnames.ora(TNS_ADMIN) => D:\oracle\product\10.2.0\db_1\NETWORK\ADMIN\tnsnames.ora