ORACLE使用Resource Manage管理资源

ORACLE使用Resource Manage管理资源

一、利用dbms_resource_manager.create_plan_directive 可以指定各个组的资源的分配,包括session_pool,cpu,并行度, undo pool ,切换组 等信息

1.DBA 可以为每个组设定active session pool,每个cousumer group 同时并发的session 数量,如果超过 了这个数量则会自动进行排队。
active session pool parameter:
active_sess_pool_p1 ,该consumer group 的并发session 上限 default 1000000
queueing_p1:session 在队列中等待的时间上限,超过该时间则会自动cancel. default 1000000 秒

2. oracle resource manager 可以评估事务最大执行时间,可以设定max_est_exec_time ,如果resource manager 评估的时间超过了这个时间,系统将不会执行,避免占用过

多的系统资源。

3. automotic consumer group switch :
directive 参数:
switch_group : group switch to ,default is null.
swtich_time : active time 活动时间,过了这个时间就会自动切换到其他组中,default 1000000
swtich_estimate : true-> oracle 使用在切换前的评估执行时间,如果评估时间大于switch_time ,则直接切换,否则就是达到了switch_time 后才进行切换。 DEFAUL :

FALSE

4. undo pool 的限额
限制某个consumer group 的undo size : 如果大于的话,则会阻止DML 的执行default :1000000kB


二、实例
1.创建计划,CPU资源分配,虽大session数,等待时间。
--每个resource manager计划必须包含一条针对用户组other groups的指令
--other groups 可以理解收容了被当前活动计划排斥的用户
--active_sess_pool_p1 活动会话池方法
--dba在不限制实际登陆数的情况下能够限制一个用户组能够同时运行的语句数。
--活动会话被定义为运行查询的会话或未提交事务当中的会话

dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.create_plan( 'MAX_PLAN', 'max_plan');--创建计划
dbms_resource_manager.create_plan_directive(
    plan => 'MAX_PLAN',
    group_or_subplan => 'MAX_GROUP',
    comment => '',
    cpu_p1 => 90, cpu_p2 => NULL, cpu_p3 => NULL, cpu_p4 => NULL,
    cpu_p5 => NULL, cpu_p6 => NULL, cpu_p7 => NULL, cpu_p8 => NULL,
    parallel_degree_limit_p1 => NULL,
    active_sess_pool_p1 => 5,
    queueing_p1 => 10,
    switch_group => '',
    switch_time => NULL,
    switch_estimate => false,
    max_est_exec_time => NULL,
    undo_pool => NULL,
    max_idle_time => NULL,
    max_idle_blocker_time => NULL,
    switch_time_in_call => NULL
);
MAX_GROUP组用户使用90%的CPU资源,最多5个回话,超过五个的回话将等待,最多等待实践10秒。
dbms_resource_manager.create_plan_directive(
    plan => 'MAX_PLAN',
    group_or_subplan => 'OTHER_GROUPS',
    comment => '',
    cpu_p1 => NULL, cpu_p2 => 100, cpu_p3 => NULL, cpu_p4 => NULL,
    cpu_p5 => NULL, cpu_p6 => NULL, cpu_p7 => NULL, cpu_p8 => NULL,
    parallel_degree_limit_p1 => NULL,
    active_sess_pool_p1 => 5,
    queueing_p1 => 10,
    switch_group => '',
    switch_time => NULL,
    switch_estimate => false,
    max_est_exec_time => NULL,
    undo_pool => NULL,
    max_idle_time => NULL,
    max_idle_blocker_time => NULL,
    switch_time_in_call => NULL
);
OTHER_GROUPS组用户使用除分配给MAX_GROUP组用户以外的所有CPU资源,最多5个回话,超过五个的回话将等待,最多等待实践10秒。
dbms_resource_manager.create_plan_directive(
    plan => 'MAX_PLAN',
    group_or_subplan => 'SYSTEM_PLAN',
    comment => '',
    cpu_p1 => 10, cpu_p2 => NULL, cpu_p3 => NULL, cpu_p4 => NULL,
    cpu_p5 => NULL, cpu_p6 => NULL, cpu_p7 => NULL, cpu_p8 => NULL
);
SYSTEM_PLAN组用户使用10%的CPU资源。
dbms_resource_manager.submit_pending_area();
--This procedure lets you submit pending changes for the resource manager.
--It clears the pending area after validating and committing the changes (if valid).
dbms_resource_manager.switch_plan( plan_name => 'MAX_PLAN', sid => 'orcl' );
END;
--------------------------------------------------------------------------------
 

2.更新计划-使用者组可用最大撤销表空间
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.update_plan_directive(
   plan => 'MAX_PLAN',
   group_or_subplan => 'MAX_GROUP',
   new_comment => '',
   new_cpu_p1 => 90, new_cpu_p2 => 100, new_cpu_p3 => NULL, new_cpu_p4 => NULL,
   new_cpu_p5 => NULL, new_cpu_p6 => NULL, new_cpu_p7 => NULL, new_cpu_p8 => NULL,
   new_parallel_degree_limit_p1 => NULL,
   new_active_sess_pool_p1 => NULL,
   new_queueing_p1 => NULL,
   new_switch_group => NULL,
   new_switch_time => NULL,
   new_switch_estimate => false,
   new_max_est_exec_time => NULL,
   new_undo_pool => 3,--指定为3KB
   new_max_idle_time => NULL,
   new_max_idle_blocker_time => NULL,
   new_switch_time_in_call => NULL
);
dbms_resource_manager.submit_pending_area();
END;
MAX_GROUP组用户分配90%的CPU资源,最多使用3K的UNDO,超过将阻止DML操作。
--修改使用者组可用最大撤销表空间
--指定使用者组可以生成的最大还原空间
--如果超出则报如下异常


3.更新计划-指定最大估计执行时间
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.update_plan_directive(
   plan => 'MAX_PLAN',
   group_or_subplan => 'MAX_GROUP',
   new_comment => '',
   new_cpu_p1 => 90, new_cpu_p2 => 100, new_cpu_p3 => NULL, new_cpu_p4 => NULL,
   new_cpu_p5 => NULL, new_cpu_p6 => NULL, new_cpu_p7 => NULL, new_cpu_p8 => NULL,
   new_parallel_degree_limit_p1 => NULL,
   new_active_sess_pool_p1 => NULL,
   new_queueing_p1 => NULL,
   new_switch_group => NULL,
   new_switch_time => NULL,
   new_switch_estimate => false,
   new_max_est_exec_time => 1,
   new_undo_pool => NULL,
   new_max_idle_time => NULL,
   new_max_idle_blocker_time => NULL,
   new_switch_time_in_call => NULL
);
dbms_resource_manager.submit_pending_area();
END;
--指定最大估计执行时间。如果数据库估计SQL会超过指定的限制,将不执行SQL,并返回一个错误。
--如果超出则报如下异常


4.更新计划-修改最大会话数的限制
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.update_plan_directive(
   plan => 'MAX_PLAN',
   group_or_subplan => 'MAX_GROUP',
   new_comment => '',
   new_cpu_p1 => 90, new_cpu_p2 => 100, new_cpu_p3 => NULL, new_cpu_p4 => NULL,
   new_cpu_p5 => NULL, new_cpu_p6 => NULL, new_cpu_p7 => NULL, new_cpu_p8 => NULL,
   new_parallel_degree_limit_p1 => NULL,
   new_active_sess_pool_p1 => 2,--最大会话数
   new_queueing_p1 => 1,--激活队列中等待的时间
   new_switch_group => NULL,
   new_switch_time => NULL,
   new_switch_estimate => false,
   new_max_est_exec_time => NULL,
   new_undo_pool => NULL,
   new_max_idle_time => NULL,
   new_max_idle_blocker_time => NULL,
   new_switch_time_in_call => NULL
);
dbms_resource_manager.submit_pending_area();
END;
--指定对使用者组中同时处于活动状态的最大会话数的限制。其它所有会话将在激活队列中等待。
--同时打开长时间三个大作业跑跑 报错。。
如果激活队列中等待的时间设置成ulimited 那就永远挂了

 

6.更新计划-修改最大空闲时间
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.update_plan_directive(
    plan => 'MAX_PLAN',
    group_or_subplan => 'MAX_GROUP',
    new_comment => '',
    new_cpu_p1 => 90, new_cpu_p2 => 100, new_cpu_p3 => NULL, new_cpu_p4 => NULL,
    new_cpu_p5 => NULL, new_cpu_p6 => NULL, new_cpu_p7 => NULL, new_cpu_p8 => NULL,
    new_parallel_degree_limit_p1 => NULL,
    new_active_sess_pool_p1 => NULL,
    new_queueing_p1 => NULL,
    new_switch_group => NULL,
    new_switch_time => NULL,
    new_switch_estimate => false,
    new_max_est_exec_time => NULL,
    new_undo_pool => NULL,
    new_max_idle_time => 1,
    new_max_idle_blocker_time => 3,
    new_switch_time_in_call => NULL
);
dbms_resource_manager.submit_pending_area();
END;
--最大空闲时间的标准 执行前一条语句后空闲的时间。
--空闲时间:指的是服务器进程空闲时间而不是用户进程空闲时间。
--max_idle_blocker_time的先决条件是设置了max_idle_time???
--v$session SECONDS_IN_WAIT如果wait_class是idle则是空闲的时间

 

5.更新计划-修改最大并行度

BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.update_plan_directive(
   plan => 'MAX_PLAN',
   group_or_subplan => 'MAX_GROUP',
   new_comment => '',
   new_cpu_p1 => 90, new_cpu_p2 => 100, new_cpu_p3 => NULL, new_cpu_p4 => NULL,
   new_cpu_p5 => NULL, new_cpu_p6 => NULL, new_cpu_p7 => NULL, new_cpu_p8 => NULL,
   new_parallel_degree_limit_p1 => 2,
   new_active_sess_pool_p1 => NULL,
   new_queueing_p1 => NULL,
   new_switch_group => NULL,
   new_switch_time => NULL,
   new_switch_estimate => false,
   new_max_est_exec_time => NULL,
   new_undo_pool => NULL,
   new_max_idle_time => NULL,
   new_max_idle_blocker_time => NULL,
   new_switch_time_in_call => NULL
);
dbms_resource_manager.submit_pending_area();
END;
启用并行需完成如下操作:
检查并行执行服务池是否开启
SQL> show parameter parallel_max
NAME                                TYPE       VALUE
------------------------------------ ----------- ------------------------------
parallel_max_servers                integer    20

检查自动指定并行度参数是否开启(或使用hint指定)
SQL> show parameter parallel_auto
NAME                                TYPE       VALUE
------------------------------------ ----------- ------------------------------
parallel_automatic_tuning           boolean    FALSE
alter table tab_name parallel[noparallel];为表开启并行
alter session enable parallel dml;为指定会话开启并行。


7.更新计划-修改使用者组切换指令
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.update_plan_directive(
   plan => 'MAX_PLAN',
   group_or_subplan => 'MAX_GROUP',
   new_comment => '',
   new_cpu_p1 => 90, new_cpu_p2 => 100, new_cpu_p3 => NULL, new_cpu_p4 => NULL,
   new_cpu_p5 => NULL, new_cpu_p6 => NULL, new_cpu_p7 => NULL, new_cpu_p8 => NULL,
   new_parallel_degree_limit_p1 => NULL,
   new_active_sess_pool_p1 => NULL,
   new_queueing_p1 => NULL,
   new_switch_group => 'KILL_SESSION',--'CANCEL_SQL',
   new_switch_time => NULL,
   new_switch_estimate => false,
   new_max_est_exec_time => NULL,
   new_undo_pool => NULL,
   new_max_idle_time => NULL,
   new_max_idle_blocker_time => NULL,
   new_switch_time_in_call => 6
);
dbms_resource_manager.submit_pending_area();
END;
--指定在采取所选操作之前会话在使用者组中可以执行的最长时间。要选择所采取的操作,可以选择中断会话,取消当前SQL操作,或者切换到其它使用者组。如果选择切换到其它

使用者组,请使用'调用后切换回原始组'复选框指定是否在调用后切换回来。选择调用后切换回原始组,对于中间层服务器使用会话池的3层应用程序非常有用。
-- switch_time_in_call一个会话的最长执行时间
--通过对执行时间的限制 进一步操作是否切换或终止
超出限定时间则报错:
ORA-00040:已超过活动时间限制-调用中止
ORA-06512:在line 7

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值