1、 概念
使用数据库资源管理对系统进行管理,包括使用资源计划、资源使用者组和资源计划指令。包括资源使用者组、资源计划、资源计划指令
2、 建立一个资源计划过程
授予admin权限
execute dbms_resource_manager_privs.grant_system_privilege(grantee_name => 'pptest',privilege_name => 'ADMINISTER_RESOURCE_MANAGER',admin_option => FALSE);
创建资源组
SQL> execute dbms_resource_manager.create_consumer_group('VIP','VIP USER');
PL/SQL procedure successfully completed
SQL> execute dbms_resource_manager.create_consumer_group('gen','gen user');
PL/SQL procedure successfully completed
创建资源计划
execute dbms_resource_manager.create_plan('PLAN_TEST','TEST');
为资源计划分配资源分配方法(CPU,重点法)
execute dbms_resource_manager.create_pending_area;
SQL> execute dbms_resource_manager.create_plan_directive(plan => 'PLAN_TEST',group_or_subplan => 'vip',comment => 'cpu resource use',cpu_p1 => 100);
SQL> execute dbms_resource_manager.create_plan_directive('plan_test','gen','cpu resource gen user',cpu_p2=> 100);
SQL> execute dbms_resource_manager.create_plan_directive('plan_test','other_groups',comment => 'other user',cpu_p3 => 100);
为资源计划分配资源分配方法(活动会话)
execute dbms_resource_manager.create_pending_area;
execute dbms_resource_manager.update_plan_directive(plan => 'PLAN_TEST',group_or_subplan => 'vip',new_active_sess_pool_p1 => 100(此资源组允许100个活动会话,new_queueing_p1 => 60(秒为单位));
execute DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
为资源计划分配资源分配方法(预计最大执行时间)
当预计执行时间大于预计时间,语句将不会执行。
SQL> execute dbms_resource_manager.create_pending_area;
PL/SQL procedure successfully completed
SQL> execute dbms_resource_manager.update_plan_directive(plan => 'PLAN_TEST',group_or_subplan => 'vip',new_max_est_exec_time => 1000);
PL/SQL procedure successfully completed
SQL> execute DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
PL/SQL procedure successfully completed
分配用户到资源组
1、 设置用户可以切换的组的权限
execute dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name => 'ppzhu',consumer_group => 'gen',grant_option => false);
2、 设置用户的初始化组
execute dbms_resource_manager.set_initial_consumer_group(user => 'ppzhu',consumer_group => 'gen');
启动当前资源管理器
alter system set resource_manager_plan='plan_test' scope=both;
查看资源计划组的设置。
select * from dba_rsrc_plan_directives where PLAN='PLAN_TEST';
3、 使用映射,让某个用户的会话都属于某个资源组
execute dbms_resource_manager.create_pending_area;
execute dbms_resource_manager.set_consumer_group_mapping(dbms_resource_manager.oracle_user,'test','high');
execute dbms_resource_manager.submit_pending_area;