您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

使用Oracle PROFILE控制会话空闲时间

2024/4/17 23:16:50发布14次查看
oracle推荐profile和sqlnet.expire_time一起使用,但由于pl/sql工具本身的特点,它会在session的状态变成sniped(profile idle_ti
客户想实现对会话空闲时间的控制,下面是做的一个例子。
microsoft windows [版本 6.1.7601]
版权所有 (c) 2009 microsoft corporation。保留所有权利。
c:\users\liubinglin>sqlplus sys/oracle123@localhost:1521/hello as sysdba
sql*plus: release 11.2.0.3.0 production on 星期二 4月 14 08:42:55 2015
copyright (c) 1982, 2011, oracle.  all rights reserved.
连接到:
oracle database 11g enterprise edition release 11.2.0.3.0 - production
with the partitioning, olap, data mining and real application testing options
sql> create profile test_profile limit idle_time 1;  表示允许的空闲时间为1分钟。
配置文件已创建
sql> set linesize 200
sql> select * from dba_profiles where profile='test_profile';
profile                        resource_name                    resource limit
------------------------------ -------------------------------- -------- ----------------------------------------
test_profile                  composite_limit                  kernel  default
test_profile                  sessions_per_user                kernel  default
test_profile                  cpu_per_session                  kernel  default
test_profile                  cpu_per_call                    kernel  default
test_profile                  logical_reads_per_session        kernel  default
test_profile                  logical_reads_per_call          kernel  default
test_profile                  idle_time                        kernel  1
test_profile                  connect_time                    kernel  default
test_profile                  private_sga                      kernel  default
test_profile                  failed_login_attempts            password default
test_profile                  password_life_time              password default
profile                        resource_name                    resource limit
------------------------------ -------------------------------- -------- ----------------------------------------
test_profile                  password_reuse_time              password default
test_profile                  password_reuse_max              password default
test_profile                  password_verify_function        password default
test_profile                  password_lock_time              password default
test_profile                  password_grace_time              password default
已选择16行。
sql> show parameter resource
name                                type        value
------------------------------------ ----------- ------------------------------
resource_limit                      boolean    false
resource_manager_cpu_allocation      integer    4
resource_manager_plan                string
sql> alter system set resource_limit =true;    对profile中kernel类型的项目进行控制需要将该参数设置为true,password类型的项目不受此参数限制。
系统已更改。
sql> create user test111 identified by test111 default tablespace users temporary tablespace temp profile test_profile;
用户已创建。
sql> grant connect,resource to test111;
授权成功。
另外窗口开一个会话:
c:\users\liubinglin>sqlplus test111/test111@localhost:1521/hello
sql*plus: release 11.2.0.3.0 production on 星期二 4月 14 08:55:49 2015
copyright (c) 1982, 2011, oracle.  all rights reserved.
连接到:
oracle database 11g enterprise edition release 11.2.0.3.0 - production
with the partitioning, olap, data mining and real application testing options
sql> create table test (id number);
create table test (id number)
*
第 1 行出现错误:
ora-02396: 超出最大空闲时间, 请重新连接
空闲一分钟后再操作就会收到上面的报错。 
但是客户说以上的方法只是适用于sqlplus,对pl/sql工具无效,下面讨论一下为什么对pl/sql无效。
使用test111登陆pl/sql之后查看数据库会话信息:
成功登陆后在数据库里面看到创建了两个session,可以看到session的login时间是11:17:09和11:17:28两个时间点。由于没有执行任何sql,登陆成功后的session状态是inactive的。
idle_time设置的为1分钟,1分钟后两个会话的状态变成了sniped,表示会话已经过期。
当在pl/sql中执行任何sql语句的时候,pl/sql没有报错,成功执行。
但是从后台看,登陆时间变成了11:20:47和11:20:51,状态又变成了inactive。
说明在pl/sql执行sql语句的时候自动的重新登陆了。
下面是sqlplus的情况:
11:37:26登陆成功后,为sqlplus创建了一个session,
1分钟没操作后会话变成了sniped状态。
再次到该会话操作时,收到如下报错:
从上一张图片可以看出,从后台看sqlplus的session已经被kill。
由此可以判断,profile idle_time对sqlplus有效,对pl/sql无效跟客户端有很大关系。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product