ORACLE使用Resource Manage管理資源
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