環境:Win Server 2008 R2 + Oracle 11.2.0.1
故障:客戶反映數據庫連接不上,本機sysdba和網絡連接都連接不上。
一、確認故障
二、排查原因
一、確認故障
1.1 服務器嘗試sysdba登錄
``` PS C:\Users\Administrator> sqlplus / as sysdbaSQL*Plus: Release 11.2.0.1.0 Production on 星期四 2月 18 09:39:14 2016
Copyright (c) 1982, 2010, Oracle. All rights reserved.
ERROR:
ORA-12560: TNS: 協議適配器錯誤
<h2 id="1.2">1.2 服務器嘗試通過網絡連接</h2>
PS C:\Users\Administrator> sqlplus system/oracle@xxoradb
SQL*Plus: Release 11.2.0.1.0 Production on 星期四 2月 18 09:34:01 2016
Copyright (c) 1982, 2010, Oracle. All rights reserved.
ERROR:
ORA-12518: TNS: 監聽程序無法分發客戶機連接
<h1 id="2">二、排查原因</h1>
<h2 id="2.1"> 2.1 ORA-12560錯誤初步排查原因 </h2>
ORA-12560錯誤官方說明:
$ oerr ora 12560
12560, 00000, "TNS:protocol adapter error"
// *Cause: A generic protocol adapter error occurred.
// *Action: Check addresses used for proper protocol specification. Before
// reporting this error, look at the error stack and check for lower level
// transport errors. For further details, turn on tracing and reexecute the
// operation. Turn off tracing when the operation is complete.
MOS相關文檔:Bequeath connection fails with ORA-12560 on Windows (文檔 ID 1986438.1)
可能原因:
> Environmental variables are not set correctly. This is a common issue on Windows.
> The following commands do not show proper settings:
> echo %ORACLE_HOME%
> echo %ORACLE_SID%
> echo %PATH%
解決方法:
> Please do the following:
>
> set ORACLE_HOME= <<<<< enter the Oracle Home path here
> set ORACLE_SID= <<<<< enter the Oracle SID name here
> set PATH=%PATH%; <<<<< add the path of %ORACLE_HOME%/bin <<<<< this is the directory where "sqlplus.exe" exists
> echo %ORACLE_HOME% <<<<< this verifies the Oracle home value
> echo %ORACLE_SID% <<<<< this verifies the Oracle SID value
可是<font color="red">目前情況是,環境變量ORACLE_SID設置沒有問題。而Windows環境,ORACLE_HOME並不需要在環境變量中設置,而是在注冊表中</font>
關於這個ORACLE_HOME環境變量的問題可參考MOS的另一篇文章:How to Set or Switch Oracle Homes on Windows (Doc ID 969581.1)
由於業務目前已經是中斷狀態,所以可以重啟監聽和數據庫服務,檢查注冊表信息,但問題依舊。
這里實際走了彎路,因為sqlplus命令是正常使用的,所以在環境變量方面就沒多想PATH的問題。
<h2 id="2.2">2.2 ORA-12518錯誤排查原因 </h2>
ORA-12518錯誤官方說明:
$ oerr ora 12518
12518, 00000, "TNS:listener could not hand off client connection"
// *Cause: The process of handing off a client connection to another process
// failed.
// *Action: Turn on listener tracing and re-execute the operation. Verify
// that the listener and database instance are properly configured for
// direct handoff. If problem persists, call Oracle Support.
// *Comment: The problem can be worked around by configuring dispatcher(s)
// to specifically handle the desired presentation(s), and connecting
// directly to the dispatcher, bypassing the listener.
查看當前監聽配置文件:
listener.ora Network Configuration File: D:\app\Administrator\product\11.2.0\dbhome_1\network\admin\listener.ora
Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = D:\app\Administrator\product\11.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:D:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll")
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = WIN-1XXXXXXXXXX)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC521))
)
)
ADR_BASE_LISTENER = D:\app\Administrator
修改監聽配置文件加入靜態監聽配置內容:
listener.ora Network Configuration File: D:\app\Administrator\product\11.2.0\dbhome_1\network\admin\listener.ora
Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = D:\app\Administrator\product\11.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:D:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll")
)
(SID_DESC =
(GLOBAL_DBNAME = xxoradb)
(ORACLE_HOME = D:\app\Administrator\product\11.2.0\dbhome_1)
(SID_NAME = xxoradb)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = WIN-1XXXXXXXXXX)(PORT = 1521))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC521))
)
)
ADR_BASE_LISTENER = D:\app\Administrator
重啟監聽后再測試,發現加入靜態監聽后可以連接到數據庫了,同時服務器上的PL/SQL工具也可以正常連接到數據庫了。
C:\Users\Administrator>sqlplus system/oracle@xxoradb
SQL*Plus: Release 11.2.0.1.0 Production on 星期四 2月 18 10:52:24 2016
Copyright (c) 1982, 2010, Oracle. All rights reserved.
連接到:
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>
<font color="red">這樣,就先解決了客戶端網絡連接的問題。</font>
<h2 id="2.3">2.3 ORA-12560錯誤再次排查原因</h2>上面解決了客戶端的連接問題,但問題還沒有完美解決,因為目前本地sysdba仍然還是無法登陸,依然報錯ORA-12560:
C:\Users\Administrator>sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期四 2月 18 10:59:11 2016
Copyright (c) 1982, 2010, Oracle. All rights reserved.
ERROR:
ORA-12560: TNS: 協議適配器錯誤
請輸入用戶名:
<font color="red">這時候就懷疑可能是機器上安裝了多個Oracle程序導致,也就是說這個sqlplus命令可能是某個客戶端的sqlplus程序,</font>
下面驗證下是不是這個情況:
看到Oracle產品目錄下,11.2.0文件夾下有多個文件夾存在
D:\app\Administrator\product\11.2.0>dir
驅動器 D 中的卷沒有標簽。
卷的序列號是 0A43-E08A
D:\app\Administrator\product\11.2.0 的目錄
2016/01/26 12:26
2016/01/26 12:26
2016/01/26 12:35
2016/01/26 12:23
2016/01/26 12:25
0 個文件 0 字節
5 個目錄 200,137,936,896 可用字節
看起來的確安裝有多個Oracle軟件,從命名規則來看,應該是1個客戶端,兩個DB。
查看當前系統注冊表中ORACLE_HOME的值為`D:\app\Administrator\product\11.2.0\dbhome_1`
那么我們使用的sqlplus程序是不是這個路徑下的呢?
進一步查看系統環境變量PATH的值,
D:\app\Administrator\product\11.2.0\client_1\BIN;D:\app\Administrator\product\11.2.0\dbhome_1\BIN;D:\app\Administrator\product\11.2.0\dbhome_1;C:\Program Files (x86)\Common Files\NetSarang;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\
<font color="red">果然第一個查找路徑是客戶端的,不是我們想要的服務端程序路徑,第二個路徑才是。</font>
現在問題就明朗了,我們把客戶端的這個路徑`D:\app\Administrator\product\11.2.0\client_1\BIN;`刪掉。
然后重新打開cmd,發現已經可以正常sysdba登錄
C:\Users\Administrator>sqlplus / as sysdba
SQL*Plus: Release 11.2.0.1.0 Production on 星期四 2月 18 11:16:53 2016
Copyright (c) 1982, 2010, Oracle. All rights reserved.
連接到:
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>
最后,再確認下,PL/SQL等工具也可以重新正常登錄。至此,問題完美解決。