今天在論壇上看到一個貼子,問題是客戶端sqlplus連接數(shù)據(jù)庫很慢:http://www.itpub.net/thread-2090550-1-1.html,之后根據(jù)問題的描述與分析,在測試環(huán)境做了一下測試,將我的虛擬主機加入域環(huán)境,進行測試;之后就聯(lián)想到去年我所遇到類似的一個問題:http://www.itpub.net/thread-2072574-1-1.html
實驗環(huán)境
操作系統(tǒng):Windows Server 2008 R2,加入AD域環(huán)境
數(shù)據(jù)庫:Oracle 11.2.0.4
問題描述:
1、從客戶端使用sqlplus
xxx/ssss@yyy 的方式連接數(shù)據(jù)庫,第一次連數(shù)據(jù)庫時很慢,基本上要幾十秒才能連接到數(shù)據(jù)庫,接下來幾次連接很正常,但過會兒再連接數(shù)據(jù)庫又變慢了
2、數(shù)據(jù)庫的日志文件中,有大量的WARNING: inbound connection timed out
(ORA-3136) 錯誤信息
排除過程:
1、查了ORA-03136的錯誤,根據(jù)網(wǎng)上查找的資料,把數(shù)據(jù)庫服務的監(jiān)聽添加了如下參數(shù)
LSNRCTL> set inbound_connect_timeout 0
并保存,此時,數(shù)據(jù)庫中不在報ORA-03136的錯誤了,但是,從客戶端連接到oracle數(shù)據(jù)庫服務器還是存在很慢的問題
2、客戶端連接數(shù)據(jù)庫服務時,數(shù)據(jù)庫的那臺主機的硬件負載都不高;
3、服務器的監(jiān)聽文件和客戶端的tnsname.ora中的主機地址都是使用ip地址
4、在服務器上使用sqlplus xxx/ssss@yyy嘗試連接多次,速度正常,感覺服務器端沒問題
5、從客戶端ping服務器的監(jiān)聽地址,沒有丟包現(xiàn)像
6、在客戶端使用tnsping測試到服務器的解析也很快,毫秒以內(nèi)
7、通過5和6的測試,感覺客戶端到服務器的網(wǎng)絡是正常的
8、繼續(xù)查詢,在網(wǎng)上發(fā)現(xiàn)這篇文章和我的情況類似,http://blog.csdn.net/jaray/article/details/36008871后來根據(jù)這個文章上的方法,修改了服務器上的sqlnet.ora中的SQLNET.AUTHENTICATION_SERVICES的值為none
9、再次使用sqlplus 測試從客戶端測試到服務端的連接,速度正常,幾秒內(nèi)連接成功
10、嘗試把那個值再改成NTS,故障又再次出現(xiàn)
問題分析:
在sqlnet.ora的SQLNET.AUTHENTICATION_SERVICES設置,如果設置NTS,則優(yōu)先使用Windows驗證,然后使用Oracle驗證;而設置none,則只使用Oracle驗證。由于我測試的環(huán)境加入了AD域,所以如果優(yōu)先Windows驗證,則Oracle會通過遠程的AD域服務器進行驗證,驗證失敗后再進行Oracle驗證,所以速度會很慢;
解決問題:
將sqlnet.ora的SQLNET.AUTHENTICATION_SERVICES值設置為none
問題分析到這里,不經(jīng)讓我想起去年遇到一個同樣類似的問題:通過sqlplus遠程連接Oracle數(shù)據(jù)庫的時,有時候能夠連接上,有什么就連接不上?(如下圖所示)
以下是Oracle11g官方文檔關(guān)于sqlnet.ora的說明:
************************************************************************************************************************************
The sqlnet.ora file is the profile configuration file. It resides on the client machines and the database server. Profiles are stored and implemented using this file. The database server can be configured with access control parameters in the sqlnet.ora file. These parameters specify whether clients are allowed or denied access based on the protocol.
The sqlnet.ora file enables you to do the following:
· Specify the client domain to append to unqualified names
· Prioritize naming methods
· Enable logging and tracing features
· Route connections through specific processes
· Configure parameters for external naming
· Configure Oracle Advanced Security
· Use protocol-specific parameters to restrict access to the database
By default, the sqlnet.ora file is located in the ORACLE_HOME/network/admin directory. The sqlnet.ora file can also be stored in the directory specified by the TNS_ADMIN environment variable.
************************************************************************************************************************************
從描述中看出,該文件是控制客戶端訪問數(shù)據(jù)庫服務器的,可以設定多種參數(shù)進行訪問控制。關(guān)于其他參數(shù)的詳細配置請參考官方文檔;而接觸到的最多的參數(shù)是 sqlnet.authentication_services,官方說明如下:
************************************************************************************************************************************
Purpose
To enable one or more authentication services. If authentication has been installed, then it is recommended that this parameter be set to either noneor to one of the authentication methods.
Default
None
Note:
When installing the database with Database Configuration Assistant (DBCA), this parameter may be set to nts in the sqlnet.ora file.
Values
· Authentication Methods Available with Oracle Net Services:
o none for no authentication methods, including Microsoft Windows native operating system authentication. WhenSQLNET.AUTHENTICATION_SERVICES is set to none, a valid user name and password can be used to access the database.
o all for all authentication methods.
o nts for Microsoft Windows native operating system authentication.
· Authentication Methods Available with Oracle Advanced Security:
o kerberos5 for Kerberos authentication.
o radius for RADIUS authentication.
o tcps for SSL authentication.
************************************************************************************************************************************
從參數(shù)的說明可以了解到提供兩種服務,net服務和高級安全服務。高級安全服務參數(shù)這里不討論了,討論一下 none / all / nts三個參數(shù)的作用。
設定sqlnet.authentication_services:
注:需要說明的是該用戶名和密碼是指具有sysdba權(quán)限的用戶;在linux上若用系統(tǒng)用戶oracle登錄數(shù)據(jù)庫需要設定為all或者不加該字段;
關(guān)于通過SQLNET.ora文件限制IP地址訪問的問題請參考蓋大師的博客:
http://www.eygle.com/archives/2008/01/sqlnetora_ip_limit.html
作者:SEian.G(苦練七十二變,笑對八十一難)
ITPUB:http://blog.itpub.net/31015730/
51CTO:http://seiang.blog.51cto.com/