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中進行填寫,每次登錄數據庫服務器時手工完成數據庫環境變量的指定,這種方法雖然增加了鍵盤的敲擊,但它更直觀、更有保 障。


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