存在多个tnsnames文件也会引起连接错误

来源:互联网 发布:js 小于或等于 编辑:程序博客网 时间:2024/04/29 15:46

今天处理了一个tnsnames文件配置的问题,让我又想起一个跟tnsnames文件相关的知识点

tnsnames文件是可以存在多个路径下面,oracle会根据顺序选择

下面我们模拟一下

$HOME/.tnsnames.ora

/etc/tnsnames.ora

$ORACLE_HOME/network/admin/tnsnames.ora+++我们默认都会去配置这个文件

这三个位置的优先顺序


首先,把正确的tnsnames配置文件都存放在上述三个地方

[oracle@localhost admin]$ ll $HOME/.tnsnames.ora
-rw-r----- 1 oracle oinstall 175 Dec 26 22:02 /home/oracle/.tnsnames.ora
[oracle@localhost admin]$ ll /etc/tnsnames.ora
-rw-r----- 1 oracle oinstall 175 Dec 26 22:02 /etc/tnsnames.ora
[oracle@localhost admin]$ ll /opt/app/oracle/product/11.2.0/network/admin/tnsnames.ora 
-rw-r----- 1 oracle oinstall 175 Dec 26 21:59 /opt/app/oracle/product/11.2.0/network/admin/tnsnames.ora

+++正常是可以访问

[oracle@localhost admin]$ sqlplus scott/tiger@goolen
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 26 22:03:10 2013
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> 
SQL> exit


++++第一,我们把$HOME/.tnsnames.ora 文件改错,再次连接

[oracle@localhost admin]$ sqlplus scott/tiger@goolen
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 26 22:03:29 2013
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified

++++连接报错

++++删除$HOME/.tnsnames.ora后,可以正常连接

[oracle@localhost admin]$ rm -rf $HOME/.tnsnames.ora
[oracle@localhost admin]$ sqlplus scott/tiger@goolen
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 26 22:03:47 2013
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> exit

+++++以上说明在三个路径中$HOME/.tnsnames.ora 是最优先选择的


+++第二,我们再把/etc/tnsnames.ora文件改错

[oracle@localhost admin]$ sqlplus scott/tiger@goolen
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 26 22:04:04 2013
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified

+++连接报错

+++删除/etc/tnsnames.ora

[oracle@localhost admin]$ sqlplus scott/tiger@goolen
SQL*Plus: Release 11.2.0.1.0 Production on Thu Dec 26 22:04:45 2013
Copyright (c) 1982, 2009, Oracle.  All rights reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL> exit

++++删除后连接正常

+++++以上说明,在三个路径当中,/etc/tnsnames.ora优先顺序排第二

+++而我们默认配置的$ORACLE_HOME/network/admin/tnsnames.ora 其实排在了第三

+++如果前面的路径下存在tnsnames文件,但是我们只是变更了$ORACLE_HOME/network/admin/tnsnames.ora的话,会很容易引起连接错误

+++在遇到此类问题的时候,大家不要忘记了检查一下以上路径是否有tnsnames文件存在


+++补充,tnsnames不止可以存在以上三个路径

1.$HOME/.tnsnames.ora 
2.$TNS_ADMIN/tnsnames.ora 
3./var/opt/oracle/tnsnames.ora or /etc/tnsnames.ora 
4.$ORACLE_HOME/network/admin/tnsnames.ora

有兴趣的同学可以试试



0 0
原创粉丝点击