oracle profile Idle_time设置(修改Oracle 数据库连接参数)

  1.  sgcrm5*sgcrm5-/home/oracle >sqlplus / as sysdba  
  2.   
  3. SQL*Plus: Release 11.1.0.6.0 - Production on Mon Oct 15 14:38:25 2012  
  4.   
  5. Copyright (c) 19822007, Oracle.  All rights reserved.  
  6.   
  7.   
  8. Connected to:  
  9. Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - 64bit Production  
  10. With the Partitioning, OLAP, Data Mining and Real Application Testing options  
  11.   
  12. sys@129.100.253.79> show parameter resource_limit  
  13.   
  14. NAME                                 TYPE        VALUE  
  15. ------------------------------------ ----------- ------------------------------  
  16. resource_limit                       boolean     FALSE  
  17. sys@129.100.253.79> alter system set resource_limit=true scope=both;  
  18.   
  19. System altered.  
  20.   
  21. Elapsed: 00:00:00.08  
  22. sys@129.100.253.79> select username,profile from DBA_USERS  
  23.   2  ;  
  24.   
  25. USERNAME                       PROFILE  
  26. ------------------------------ ------------------------------  
  27. 9959                           DEFAULT  
  28. SCOTT                          DEFAULT  
  29. SPOTLIGHT                      DEFAULT  
  30. SPATIAL_WFS_ADMIN_USR          DEFAULT  
  31. MDDATA                         DEFAULT  
  32. XS$NULL                        DEFAULT  
  33. APEX_PUBLIC_USER               DEFAULT  
  34. TSMSYS                         DEFAULT  
  35. DIP                            DEFAULT  
  36. SPATIAL_CSW_ADMIN_USR          DEFAULT  
  37. ORACLE_OCM                     DEFAULT  
  38. OWBSYS                         DEFAULT  
  39. EXFSYS                         DEFAULT  
  40. FLOWS_030000                   DEFAULT  
  41. FLOWS_FILES                    DEFAULT  
  42. WK_TEST                        DEFAULT  
  43. DBSNMP                         MONITORING_PROFILE  
  44. WMSYS                          DEFAULT  
  45. ORDSYS                         DEFAULT  
  46. WKSYS                          WKSYS_PROF  
  47. XDB                            DEFAULT  
  48. OLAPSYS                        DEFAULT  
  49. SI_INFORMTN_SCHEMA             DEFAULT  
  50. ORDPLUGINS                     DEFAULT  
  51. WKPROXY                        DEFAULT  
  52. MDSYS                          DEFAULT  
  53. SYSMAN                         DEFAULT  
  54. CTXSYS                         DEFAULT  
  55. ANONYMOUS                      DEFAULT  
  56. SYS                            DEFAULT  
  57. SYSTEM                         DEFAULT  
  58. MGMT_VIEW                      DEFAULT  
  59. OUTLN                          DEFAULT  
  60.   
  61. 33 rows selected.  
  62.   
  63. Elapsed: 00:00:00.05  
  64. sys@129.100.253.79> select distinct(profile) from dba_profiles;  
  65.   
  66. PROFILE  
  67. ------------------------------  
  68. WKSYS_PROF  
  69. DEFAULT  
  70. MONITORING_PROFILE  
  71. PROFILE9959  
  72.   
  73. Elapsed: 00:00:00.01  
  74. sys@129.100.253.79> SELECT name, value  
  75.   2  FROM gv$parameter  
  76.   3  WHERE name = 'resource_limit';  
  77.   
  78. NAME  
  79. --------------------------------------------------------------------------------  
  80. VALUE  
  81. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------  
  82. resource_limit  
  83. TRUE  
  84.   
  85.   
  86. Elapsed: 00:00:00.01  
  87. sys@129.100.253.79> alter user system profile PROFILE9959;  
  88.   
  89. User altered.  
  90.   
  91. Elapsed: 00:00:00.07  
  92. sys@129.100.253.79>   

 

注意:

设置完成后,对已经连上的会话不起作用,对新连上的会话才会生效。

动态地使用alter system或使用初始化参数resource_limit使资源限制生效。该改变对密码资源无效,密码资源总是可用。

 

数据库profile中设置IDLE_TIME后,如果会话超过这个限制,PMON进程会:

[sql]  view plain  copy
 print ?
  1. * Mark the V$SESSION as SNIPED  
  2.  * Clean up the database resources for the session  
  3.  * Remove the V$SESSION entry  

经常会有SNIPED状态的会话,这些会话不活动了,但却占用了用户的会话数: 

select sid,serial#,paddr,username,status from v$session where status = 'SNIPED';

 

这里我们看到的现象是v$session中,会话没有被清理。最好的情况是,当用户再次尝试连接该会话时,会收到ORA-02396错误,然后会话被清理。

尝试用alter system kill session,v$session中标记为KILLED,v$process、os process都是不清理的。

[python]  view plain  copy
 print ?
  1. select type,s.username,s.status,s.machine,s.program,'alter system kill session ' ||''''''||s.sid||','||s.serial# || ''';' oracle_level_kill,paddr from v$session s where status = 'KILLED'  
  2. select 'kill -9 '||spid unix_level_kill from v$process where addr='07000002309E5BE8';  

OS上kill -9,会话被清理。
 

[python]  view plain  copy
 print ?
  1. DROP PROFILE PROFILE9959 CASCADE;  
  2.   
  3. CREATE PROFILE PROFILE9959 LIMIT  
  4.   SESSIONS_PER_USER UNLIMITED  
  5.   CPU_PER_SESSION UNLIMITED  
  6.   CPU_PER_CALL UNLIMITED  
  7.   CONNECT_TIME UNLIMITED  
  8.   IDLE_TIME 120  
  9.   LOGICAL_READS_PER_SESSION UNLIMITED  
  10.   LOGICAL_READS_PER_CALL UNLIMITED  
  11.   COMPOSITE_LIMIT UNLIMITED  
  12.   PRIVATE_SGA UNLIMITED  
  13.   FAILED_LOGIN_ATTEMPTS 10  
  14.   PASSWORD_LIFE_TIME 180  
  15.   PASSWORD_REUSE_TIME UNLIMITED  
  16.   PASSWORD_REUSE_MAX UNLIMITED  
  17.   PASSWORD_LOCK_TIME 1  
  18.   PASSWORD_GRACE_TIME 7  
  19.   PASSWORD_VERIFY_FUNCTION NULL;  

profile:配置文件的名称。Oracle数据库以以下方式强迫资源限制:

1.如果用户超过了connect_time或idle_time的会话资源限制,数据库就回滚当前事务,并结束会话。用户再次执行命令,数据库则返回一个错误,

2.如果用户试图执行超过其他的会话资源限制的操作,数据库放弃操作,回滚当前事务并立即返回错误。用户之后可以提交或回滚当前事务,必须结束会话。

提示:可以将一条分成多个段,如1小时(1/24天)来限制时间,可以为用户指定资源限制,但是数据库只有在参数生效后才会执行限制。

Unlimited:分配该profile的用户对资源使用无限制,当使用密码参数时,unlimited意味着没有对参数加限制。

Default:指定为default意味着忽略对profile中的一些资源限制,Default profile初始定义对资源不限制,可以通过alter profile命令来改变。

Resource_parameter部分

 Session_per_user:指定限制用户的并发会话的数目。

Cpu_per_session:指定会话的CPU时间限制,单位为百分之一秒。

Cpu_per_call:指定一次调用(解析、执行和提取)的CPU时间限制,单位为百分之一秒。

Connect_time:指定会话的总的连接时间,以分钟为单位。

Idle_time:指定会话允许连续不活动的总的时间,以分钟为单位,超过该时间,会话将断开。但是长时间运行查询和其他操作的不受此限制。

Logical_reads_per_session:指定一个会话允许读的数据块的数目,包括从内存和磁盘读的所有数据块。

Logical_read_per_call:指定一次执行SQL(解析、执行和提取)调用所允许读的数据块的最大数目。

Private_sga:指定一个会话可以在共享池(SGA)中所允许分配的最大空间,以字节为单位。(该限制只在使用共享服务器结构时才有效,会话在SGA中的私有空间包括私有的SQL和PL/SQL,但不包括共享的SQL和PL/SQL)。

Composite_limit:指定一个会话的总的资源消耗,以service units单位表示。Oracle数据库以有利的方式计算cpu_per_session,connect_time,logical_reads_per_session和private-sga总的service units

Password_parameter部分:

Failed_login_attempts:指定在帐户被锁定之前所允许尝试登陆的的最大次数。

Password_life_time:指定同一密码所允许使用的天数。如果同时指定了password_grace_time参数,如果在grace period内没有改变密码,则密码会失效,连接数据库被拒绝。如果没有设置password_grace_time参数,默认值unlimited将引发一个数据库警告,但是允许用户继续连接。

Password_reuse_time和password_reuse_max:这两个参数必须互相关联设置,password_reuse_time指定了密码不能重用前的天数,而password_reuse_max则指定了当前密码被重用之前密码改变的次数。两个参数都必须被设置为整数。

1.如果为这两个参数指定了整数,则用户不能重用密码直到密码被改变了password_reuse_max指定的次数以后在password_reuse_time指定的时间内。

如:password_reuse_time=30,password_reuse_max=10,用户可以在30天以后重用该密码,要求密码必须被改变超过10次。

2.如果指定了其中的一个为整数,而另一个为unlimited,则用户永远不能重用一个密码。

3.如果指定了其中的一个为default,Oracle数据库使用定义在profile中的默认值,默认情况下,所有的参数在profile中都被设置为unlimited,如果没有改变profile默认值,数据库对该值总是默认为unlimited。

4.如果两个参数都设置为unlimited,则数据库忽略他们。

Password_lock_time:指定登陆尝试失败次数到达后帐户的缩定时间,以天为单位。

Password_grace_time:指定宽限天数,数据库发出警告到登陆失效前的天数。如果数据库密码在这中间没有被修改,则过期会失效。

Password_verify_function:该字段允许将复杂的PL/SQL密码验证脚本做为参数传递到create profile语句。Oracle数据库提供了一个默认的脚本,但是自己可以创建自己的验证规则或使用第三方软件验证。 对Function名称,指定的是密码验证规则的名称,指定为Null则意味着不使用密码验证功能。如果为密码参数指定表达式,则该表达式可以是任意格式,除了数据库标量子查询。

 可以参考:http://psoug.org/reference/profiles.html

转自:http://blog.csdn.net/rgb_rgb/article/details/8073030

=============================================================================================================

使用resource_limit及profile限制用户连接

 
   数据库性能是一个永恒的话题,那就是如何使用更少的资源以达到更高效的性能。 Oracle 系统参数RESOURCE_LIMIT是一个用于控制用户对于数据库资源使用的参数,当值为true的时候即为启用,否则禁用。该参数结合profile来可以控制多种资源的使用,如CPU_PER_SESSION, CONNECT_TIME,LOGICAL_READS_PER_SESSION,
PRIVATE_SGA等等从而达到到节省资源来实现高效性能。本文描述了数据资源限制并演示了IDLE_TIME及SESSIONS_PER_USER的用法。
 
1、数据库资源限制的主要步骤
Implemented by 
     * Setting RESOURCE_LIMIT = TRUE in the database startup parameter file (spfile or pfile) 
     * Creating or modifying existing user profiles (DBA_PROFILES) to have one or more resource limit
     * Assigning a profile to a user whose resources are wished to be limited
It could happen that if the idle_time has been set on the DEFAULT profile, this can lead to an MTS dispatchers being set to 'sniped' and then getting 'cleaned up' via the shell script.
The removal of the dispatcher will result in other sessions 'dying' .In that case, If you are to implement resource limits, may be advisable to create new profiles that be assigned to users and not to change the characteristics of DEFAULT.
Alternatively, if you do change DEFAULT, ensure that all the properties that you have affected have been fully tested in a development environment.
用户超出限制后的完成的动作
When a resource limit is exceeded (for example IDLE_TIME) ... PMON does the following 
     * Mark the V$SESSION as SNIPED 
     * Clean up the database resources for the session
     * Remove the V$SESSION entry
 
2、资源限制的配置
[sql] 
--演示环境  
SQL> select * from v$version where rownum<2;  
  
BANNER  
--------------------------------------------------------------------------------  
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production  
  
--查看参数resource_limit  
SQL> show parameter resource_limit  
  
NAME                                 TYPE        VALUE  
------------------------------------ ----------- ------------------------------  
resource_limit                       boolean     FALSE  
  
--修改参数resource_limit为true  
SQL> alter system set resource_limit=true;  
  
System altered.  
  
SQL> show parameter resource_limit  
  
NAME                                 TYPE        VALUE  
------------------------------------ ----------- ------------------------------  
resource_limit                       boolean     TRUE  
  
--创建profile,其idle_time为3分钟  
SQL> create profile app_user limit idle_time 3;   
  
Profile created.  
  
--修改profile,限制每个用户只能开一个session  
SQL> alter profile app_user limit sessions_per_user 1;  
  
Profile altered.  
  
--将用户指派给特定的profile  
SQL> alter user scott profile app_user;  
  
User altered.  
  
--查看刚刚创建的profile,查询结果中的RESOURCE_NAME都可以作相应的设置或修改  
SQL> select * from dba_profiles where profile='APP_USER';  
  
PROFILE                        RESOURCE_NAME                    RESOURCE LIMIT  
------------------------------ -------------------------------- -------- ----------------------------------------  
APP_USER                       COMPOSITE_LIMIT                  KERNEL   DEFAULT  
APP_USER                       SESSIONS_PER_USER                KERNEL   1  
APP_USER                       CPU_PER_SESSION                  KERNEL   DEFAULT  
APP_USER                       CPU_PER_CALL                     KERNEL   DEFAULT  
APP_USER                       LOGICAL_READS_PER_SESSION        KERNEL   DEFAULT  
APP_USER                       LOGICAL_READS_PER_CALL           KERNEL   DEFAULT  
APP_USER                       IDLE_TIME                        KERNEL   3  
APP_USER                       CONNECT_TIME                     KERNEL   DEFAULT  
APP_USER                       PRIVATE_SGA                      KERNEL   DEFAULT  
APP_USER                       FAILED_LOGIN_ATTEMPTS            PASSWORD DEFAULT  
APP_USER                       PASSWORD_LIFE_TIME               PASSWORD DEFAULT  
APP_USER                       PASSWORD_REUSE_TIME              PASSWORD DEFAULT  
APP_USER                       PASSWORD_REUSE_MAX               PASSWORD DEFAULT  
APP_USER                       PASSWORD_VERIFY_FUNCTION         PASSWORD DEFAULT  
APP_USER                       PASSWORD_LOCK_TIME               PASSWORD DEFAULT  
APP_USER                       PASSWORD_GRACE_TIME              PASSWORD DEFAULT  
  
16 rows selected.  
3、演示资源被限制的情形
[sql] 
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  
  
--获得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来进行释放

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值