今天在论坛上看到一个贴子,问题是客户端sqlplus连接数据库很慢:
实验环境操作系统:Windows Server 2008 R2,加入AD域环境数据库:Oracle 11.2.0.4
问题描述:1、从客户端使用sqlplus
xxx/ssss@yyy的方式连接数据库,第一次连数据库时很慢,基本上要几十秒才能连接到数据库,接下来几次连接很正常,但过会儿再连接数据库又变慢了2、数据库的日志文件中,有大量的WARNING: inbound connection timed out
(ORA-3136)错误信息排除过程:
1、查了ORA-03136的错误,根据网上查找的资料,把数据库服务的监听添加了如下参数LSNRCTL> set inbound_connect_timeout 0
并保存,此时,数据库中不在报ORA-03136的错误了,但是,从客户端连接到2、客户端连接数据库服务时,数据库的那台主机的硬件负载都不高;3、服务器的监听文件和客户端的tnsname.ora中的主机地址都是使用ip地址4、在服务器上使用sqlplus xxx/ssss@yyy尝试连接多次,速度正常,感觉服务器端没问题5、从客户端ping服务器的监听地址,没有丢包现像6、在客户端使用tnsping测试到服务器的解析也很快,毫秒以内7、通过5和6的测试,感觉客户端到服务器的网络是正常的8、继续查询,在网上发现这篇文章和我的情况类似,sqlnet.ora中的SQLNET.AUTHENTICATION_SERVICES的值为none
9、再次使用sqlplus测试从客户端测试到服务端的连接,速度正常,几秒内连接成功10、尝试把那个值再改成NTS,故障又再次出现
问题分析:
在sqlnet.ora的SQLNET.AUTHENTICATION_SERVICES设置,如果设置NTS,则优先使用Windows验证,然后使用Oracle验证;而设置none,则只使用Oracle验证。由于我测试的环境加入了AD域,所以如果优先Windows验证,则Oracle会通过远程的AD域服务器进行验证,验证失败后再进行Oracle验证,所以速度会很慢;
解决问题:
将sqlnet.ora的SQLNET.AUTHENTICATION_SERVICES值设置为none
问题分析到这里,不经让我想起去年遇到一个同样类似的问题:通过sqlplus远程连接Oracle数据库的时,有时候能够连接上,有什么就连接不上?(如下图所示)
以下是Oracle11g官方文档关于sqlnet.ora的说明:
************************************************************************************************************************************
Thesqlnet.orafile
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 thesqlnet.orafile.These
parameters specify whether clients are allowed or denied access based on the
protocol.
Thesqlnet.orafile
enables you to do the following:
·
Specify the client domain to append
to unqualified names
·
Prioritizes
·
Enable logging and tracing features
·
Route connections through specific
processes
·
Configure parameters for
·
Use protocol-specific parameters to
restrict access to the database
By
default, thesqlnet.orafile
is located in theORACLE_HOME/network/admindirectory.
Thesqlnet.orafile
can also be stored in the directory specified by theTNS_ADMINenvironment
variable.
************************************************************************************************************************************
从描述中看出,该文件是控制客户端访问数据库服务器的,可以设定多种参数进行访问控制。关于其他参数的详细配置请参考官方文档;而接触到的最多的参数是 sqlnet.authentication_services,官方说明如下:
************************************************************************************************************************************
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 eithernoneor to one of the authentication
methods.
Default
None
Note:
When installing the database with Database Configuration Assistant
(DBCA), this parameter may be set tontsin thesqlnet.orafile.
Values
·
Authentication Methods Available
with Oracle Net Services:
o nonefor
no authentication methods, including Microsoft Windows native operating system
authentication. WhenSQLNET.AUTHENTICATION_SERVICESis
set tonone, a valid
user name and password can be used to access the database.
o allfor
all authentication methods.
o ntsfor
Microsoft Windows native operating system authentication.
·
Authentication Methods Available
with Oracle Advanced Security:
o kerberos5for
Kerberos authentication.
o radiusfor
RADIUS authentication.
o tcpsfor
SSL authentication.
************************************************************************************************************************************
从参数的说明可以了解到提供两种服务,net服务和高级安全服务。高级安全服务参数这里不讨论了,讨论一下 none / all / nts三个参数的作用。
设定sqlnet.authentication_services:
none:作用是不允许通过os系统用户登录数据库,需要提供用户名及密码;
all:作用是允许所有的登录方式;
nts:作用是windows的本地操作系统用户认证;
注:需要说明的是该用户名和密码是指具有sysdba权限的用户;在linux上若用系统用户oracle登录数据库需要设定为all或者不加该字段;
关于通过SQLNET.ora文件限制IP地址访问的问题请参考盖大师的博客:
作者:SEian.G(苦练七十二变,笑对八十一难)
ITPUB:http://blog.itpub.net/31015730/
51CTO:http://seiang.blog.51cto.com/