sqlplus "/as sysdba" TNS:net service name is incorrectly specified

官方的解释
ORA-12162: TNS:net service name is incorrectly specified
Cause: The connect descriptor corresponding to the net service name in TNSNAMES.ORA or in the directory server (Oracle Internet Directory) is incorrectly specified.
Action: If using local naming make sure there are no syntax errors in the corresponding connect descriptor in the TNSNAMES.ORA file. If using directory naming check the information provided through the administration used for directory naming.
-------------------------------------------------------------------------------------------------

故障现象(我的测试环境是linux5.4  oracle版本10.2.0.1)
本文所要描述的故障与这个通用的问题描述不同,在数据库服务器端使用TNSNAMES.ORA中记录的连接串连接没有问题,但如若未指定连接串,将会报出ORA-12162错误。

1)使用system用户尝试登录系统,此时便会收到报错如下信息

$ sqlplus system/sys
SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jun 7 05:06:46 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specifie
Enter user-name:

2)使用sysdba身份登陆会得到同样的错误信息
$ sqlplus / as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jun 7 05:06:46 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specifie
Enter user-name:

2)使用@orcl登陆会得到同样的错误信息

$ sqlplus / @orcl as sysdba

SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jun 7 05:06:46 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specifie
Enter user-name:

-------------------------------------------------------------------------------------------------

故障原因

诡异的故障背后的原因竟然是那样的基础:ORACLE_SID没有指定!
确认系统当前的ORACLE_HOME和ORACLE_SID环境变量
$ echo $ORACLE_HOME
信息显示 /oracle/app/oracle/product/10.2.0/db_1
$ echo $ORACLE_SID

信息显示 (没信息)

可见,此时只设置了ORACLE_HOME环境变量,但ORACLE_SID此时为空,这就是该问题的真实原因。或者不生效
-------------------------------------------------------------------------------------------------

故障处理

$ export ORACLE_SID=ora10g
$ echo $ORACLE_SID
显示信息 orcl
$ sqlplus / as sysdba


SQL*Plus: Release 10.2.0.1.0 - Production on Thu Jun 7 05:06:46 2012
Copyright (c) 1982, 2005, Oracle.  All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL>

哈哈,登陆成功。

-------------------------------------------------------------------------------------------------

小结
这个案例给我们的启迪是什么?
1)系统默认的错误提示信息有时不具有参考价值。而且,某些情况下这些错误提示还可能给我们带来误导。原因很简单,系统默认的错误提示信息不可能囊括所有故障现象;
2)任何系统级别的设置问题都有可能导致数据库系统出现异常;
3)在遇到故障的时候,我们需要沉着冷静。有些时候可能需要我们Check最原始的信息,切莫想当然。

建 议:为了避免出现文章中提到的问题,第一,可以将ORACLE_SID等环境变量写入到系统
.bash_profile中,但需要确保系统.bash_profile文件内容的有 效性;第二,不在.bash_profile中进行填写,每次登录数据库服务器时手工完成数据库环境变量的指定,这种方法虽然增加了键盘的敲击,但它更直观、更有保 障。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章