你好,游客 登录 注册 搜索
背景:
阅读新闻

使用 resource_limit 及 profile 限制用户连接

[日期:2013-06-27] 来源:Linux社区  作者:Robinson [字体:大 中 小]

3、演示资源被限制的情形

C:\Users\robinson.cheng>sqlplus scott/tiger@oradb1

SQL*Plus: Release 11.2.0.1.0 Production on Wed Jun 26 18:12:10 2013

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

SQL> host            ----->开启一个session
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\robinson.cheng>sqlplus scott/tiger@oradb1  --->尝试开启另一个sessioin

SQL*Plus: Release 11.2.0.1.0 Production on Wed Jun 26 18:12:21 2013

Copyright (c) 1982, 2010, Oracle.  All rights reserved.

ERROR:
ORA-02391: exceeded simultaneous SESSIONS_PER_USER limit  --->此时收到资源被限制的提示
Enter user-name:

--在服务器端查看session的情形,3分钟后用户scott 的session的状态被置为SNIPED
SQL> @comm_sess_users;

+----------------------------------------------------+
| User Sessions (All)                                |
+----------------------------------------------------+

Instance    SID Serial ID    Status Oracle User    O/S User  O/S PID Session Program        Terminal            Machine
--------- ------ --------- --------- ----------- ------------ -------- --------------------- ---------- -------------------
oradb          1        5  INACTIVE        SYS      oracle 10090    sqlplus@node1.szdb.co      pts/1      node1.szdb.com
              35        7    ACTIVE          HR        robin 10171    sqlplus@SZDB (TNS V1-      pts/2                SZDB
              40      237    SNIPED      SCOTT Robinson.Che 13282    sqlplus.exe                PC39    2GOTRADESZ\PC39

--Author : Robinson
--Blog  : http://www.linuxidc.com

--获得session的spid
SQL> @my_spid_from_sid
Enter value for input_sid: 40

  SID    SERIAL# SPID
------ ---------- -------------------------------------
    40        237 13282

--此时的时间为20:17:54
SQL> ho date
Wed Jun 26 20:17:54 CST 2013

--查看scott对应的server process,其进程的启动时间为18:12,过了1个多小时,进程依旧没有被释放   
SQL> ho ps -ef | grep 13282 | grep -v grep
oracle  13282    1  0 18:12 ?        00:00:00 oracleoradb (LOCAL=NO)

--下面调用shell脚本来杀掉对应的进程
SQL> host
[oracle@node1 ~]$ ./kill_sniped.sh oradb
13282
[oracle@node1 ~]$ ps -ef | grep 13282 | grep -v grep

--清除服务器进程的shell脚本
[oracle@node1 ~]$ more kill_sniped.sh
#!/bin/sh
export ORACLE_SID=$1
tmpfile=/tmp/tmp.$$
sqlplus -S /nolog <<EOF
connect / as sysdba
set head off feedback off
spool $tmpfile
select p.spid from v\$process p,v\$session s
where s.paddr=p.addr
and s.status='SNIPED';
spool off
EOF
for x in `cat $tmpfile | grep "^[0123456789]"`
                do
                kill -9 $x
done
rm $tmpfile

4、注意事项
NOTE:

      If you are running in a shared server environment, you need to be careful not to accidentally kill your dispatchers and/or shared servers. In Oracle 10.2 (or higher) a dedicated connections V$SESSION + V$PROCESS + OS Process can be cleaned up with
      ALTER SYSTEM DISCONNECT SESSION '<SID>,<SERIAL>' IMMEDIATE
At this point in versions prior to 10.2 and for shared server connections the only solution is to kill the session at the OS level (see Kill and ORAKILL above)
    * Windows : use the orakill command .... orakill <ORACLE SID> <Thread ID> (see Note 69882.1 for details)

On occasions we see conditions where a database session has a V$SESSION.STATUS = SNIPED ... and the entry never goes away . This condition can be achieved by implementing Database Resource Limits + Profiles without DCD and allow the database session to exceed the limit in the profile

5、小结
a、参数RESOURCE_LIMIT = TRUE用于启用数据库资源配置限制
b、profile用于实现资源配置,创建profile或修改已存在的profile来调整各个具体资源配置
c、将profile指派给那些需要限制的用户
d、一旦被限制的用户超出所设定的阀值将收到资源配置相关的错误提示
e、被限制资源的session状态变成sniped
f、被限制资源的session对应的server process并没有被释放,需要手动释放或结合sqlnet.expire_date来进行释放
g、Reference:[ID 601605.1]  Oracle 角色、配置文件  http://psoug.org/reference/profiles.html

更多Oracle相关信息见Oracle 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=12

linux
相关资讯       profile  resource_limit 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款