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

php中文网
发布: 2016-06-07 16:00:13
原创
1616人浏览过

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之后查看数据库会话信息:

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

成功登陆后在数据库里面看到创建了两个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语句的时候自动的重新登陆了。

稿定抠图
稿定抠图

AI自动消除图片背景

稿定抠图 80
查看详情 稿定抠图

下面是SQLPLUS的情况:

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

11:37:26登陆成功后,为SQLPLUS创建了一个SESSION,

1分钟没操作后会话变成了SNIPED状态。

再次到该会话操作时,收到如下报错:

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

从上一张图片可以看出,从后台看SQLPLUS的SESSION已经被KILL。

由此可以判断,PROFILE IDLE_TIME对SQLPLUS有效,对PL/SQL无效跟客户端有很大关系。

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号