您好,登錄后才能下訂單哦!
本篇內容介紹了“怎么用pending area創建資源計劃”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
兩個DBMS包
DBMS_RESOURCE_MANAGER 管理資源計劃
DBMS_RESOURCE_MANAGER_PRIVS 給用戶授予管理資源的權限
plan schema:
包括一個頂計劃和下面的子計劃和消耗組
自計劃的配額也是以100%為基礎來分配的
創建簡單的資源計劃:
CREATE_SIMPLE_PLAN里最多可以建8個組
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_SIMPLE_PLAN(SIMPLE_PLAN => 'simple_plan1',
CONSUMER_GROUP1 => 'mygroup1', GROUP1_CPU => 80,
CONSUMER_GROUP2 => 'mygroup2', GROUP2_CPU => 20);
END;
這種方式不需要創建pending area.
用pending area創建資源計劃
在創建資源計劃前,必須創建pending area,創建資源計劃后,必須驗證并提交pending area
創建pending_area
EXEC DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA;
驗證
EXEC DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA;
提交(提交后會自動釋放pending area)
EXEC DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA;
手動釋放
EXEC DBMS_RESOURCE_MANAGER.CLEAR_PENDING_AREA;
資源計劃的參數
PLAN 資源計劃名稱
COMMENT 描述
CPU_MTH CPU分配方式,包括EMPHASIS(按百分比)和RATIO(按比例,幾比幾比幾)。其中EMPHASIS是默認的
ACTIVE_SESS_POOL_MTH 最多可以有多少個活動session,默認為ACTIVE_SESS_POOL_ABSOLUTE
PARALLEL_DEGREE_LIMIT_MTH 并行度,默認 PARALLEL_DEGREE_LIMIT_ABSOLUTE
QUEUEING_MTH 隊列資源分配方式,決定哪些session先執行。默認FIFO_TIMEOUT
創建資源計劃
EXEC DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'great_bread', COMMENT => 'great plan');
修改資源計劃
EXEC DBMS_RESOURCE_MANAGER.UPDATE_PLAN(PLAN => 'great_bread', NEW_COMMENT => 'great plan for great bread');
刪除資源計劃
EXEC DBMS_RESOURCE_MANAGER.DELETE_PLAN(PLAN => 'great_bread'); --只刪除計劃,不刪除對應的資源組
級聯刪除用DELETE_PLAN_CASCADE
Ratio策略
決定在一個level里各資源組可以得到的CPU比例。
下面給Gold service,Silver service,Bonze service,Lowest service設置了10比5比2比1的比例.
如果當前只有gold service 和 sliver service存在,則它倆按10比5來分配。
DBMS_RESOURCE_MANAGER.CREATE_PLAN
(PLAN => 'service_level_plan',
CPU_MTH -> 'RATIO',
COMMENT => 'service level plan');
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE
(PLAN => 'service_level_plan',
GROUP_OR_SUBPLAN => 'GOLD_CG',
COMMENT => 'Gold service level customers',
CPU_P1 => 10);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE
(PLAN => 'service_level_plan',
GROUP_OR_SUBPLAN => 'SILVER_CG',
COMMENT => 'Silver service level customers',
CPU_P1 => 5);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE
(PLAN => 'service_level_plan',
GROUP_OR_SUBPLAN => 'BRONZE_CG',
COMMENT => 'Bonze service level customers',
CPU_P1 => 2);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE
(PLAN => 'service_level_plan',
GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
COMMENT => 'Lowest priority sessions',
CPU_P1 => 1);
創建資源消耗組
參數:
CONSUMER_GROUP 名稱
COMMENT 描述
CPU_MTH CPU分配方式,默認為ROUND_ROBIN,使用ROUND_ROBIN cheduler來session正確執行。還有RUN_TO_COMPLETION選項
特殊資源消耗組(無法修改和刪除)
DEFAULT_CONSUMER_GROUP 所有未明確指定消耗組的用戶和session的默認消耗組。
OTHER_GROUPS 不能被明確指定給用戶,應用于所有不在當前plan schema中的消耗組的用戶。
同時,還有ORACLE提供的SYSTEM_PLAN 資源計劃下的SYS_GROUP和LOW_GROUP兩個消耗組
創建消耗組
創建之前必須創建pending area
EXEC DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP (CONSUMER_GROUP => 'sales', COMMENT => 'retail and wholesale sales');
修改消耗組
UPDATE_CONSUMER_GROUP
刪除消耗組
DELETE_CONSUMER_GROUP
創建資源計劃指令 resource plan directives
資源計劃指令將消耗組分配到資源計劃中,并為各種分配方式指定參數
參數:
PLAN 計劃名稱
GROUP_OR_SUBPLAN 消耗組活子計劃名稱
COMMENT 備注
CPU_P1到CPU_P8 對于EMPHASIS方式,指定當前級別的百分比,對于RATIO,指定分配比例,RATIO只對CPU_P1有效,對后面的級別不適用。
ACTIVE_SESS_POOL_P1 最大活動session數,默認UNLIMITED
QUEUEING_P1 隊列中的超時時間,默認UNLIMITED
PARALLEL_DEGREE_LIMIT_P 并行度,默認UNLIMITED
SWITCH_GROUP
SWITCH_TIME
SWITCH_ESTIMATE
MAX_EST_EXEC_TIME
UNDO_POOL
MAX_IDLE_TIME session的最大空閑時間
MAX_IDLE_BLOCKER_TIME 被阻塞的session的最大空閑時間
SWITCH_TIME_IN_CALL
創建resource plan directive
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (
PLAN => 'great_bread',
GROUP_OR_SUBPLAN => 'sales',
COMMENT => 'sales group',
CPU_P1 => 60,
PARALLEL_DEGREE_LIMIT_P1 => 4);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (
PLAN => 'great_bread',
GROUP_OR_SUBPLAN => 'market',
COMMENT => 'marketing group',
CPU_P1 => 20);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (
PLAN => 'great_bread',
GROUP_OR_SUBPLAN => 'develop',
COMMENT => 'development group',
CPU_P1 => 20);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (
PLAN => 'great_bread',
GROUP_OR_SUBPLAN =>'OTHER_GROUPS',
COMMENT => 'this one is required',
CPU_P1 => 0,
CPU_P2 => 100);
END;
修改resource plan directive
EXEC DBMS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTIVE (
PLAN => 'great_bread',
GROUP_OR_SUBPLAN => 'develop',
NEW_CPU_P1 => 15);
刪除
DELETE_PLAN_DIRECTIVE
管理消耗組
用到的存儲過程
SET_CONSUMER_GROUP_MAPPING
SET_CONSUMER_GROUP_MAPPING_PRI
改變正在執行的session的消耗組
可以不用踢出session的情況下改變CPU等配額。
參數是session的 sid,serial#和消耗組名稱
EXEC DBMS_RESOURCE_MANAGER.SWITCH_CONSUMER_GROUP_FOR_SESS (
'17',
'12345',
'high_priorty');
改變用戶的消耗組
EXEC DBMS_RESOURCE_MANAGER.SWITCH_CONSUMER_GROUP_FOR_USER (
'scott',
'low_group');
用DBMS_SESSION包切換消耗組
如果被授予過switch權限,用戶可以改變自己的消耗組
參數:
NEW_CONSUMER_GROUP 新組
OLD_CONSUMER_GROUP 老組(這個是OUT型的參數)
INITIAL_GROUP_ON_ERROR 切換發生錯誤的時候的行為,TRUE表示切換錯誤的時候,用戶切換到初始消耗組,FALSE表示發生錯誤就報錯
例子:
SET serveroutput on
DECLARE
old_group varchar2(30);
BEGIN
DBMS_SESSION.SWITCH_CURRENT_CONSUMER_GROUP('sales', old_group, FALSE);
DBMS_OUTPUT.PUT_LINE('OLD GROUP = ' || old_group);
END;
允許用戶將自己切換到指定消耗組
EXEC DBMS_RESOURCE_MANAGER_PRIVS.GRANT_SWITCH_CONSUMER_GROUP (
'scott',
'bug_batch_group(組名)', TRUE(SCOTT也可以授權別人切換到該組));
收回切換權限
EXEC DBMS_RESOURCE_MANAGER_PRIVS.REVOKE_SWITCH_CONSUMER_GROUP (
'scott',
'bug_batch_group');
將session自動映射到消耗組
通過session的屬性和消耗組自動連接,分為login attributes和runtime attributes兩種屬性
使用的存儲過程:
SET_CONSUMER_GROUP_MAPPING
SET_CONSUMER_GROUP_MAPPING_PRI
創建映射
參數:
ATTRIBUTE
VALUE
CONSUMER_GROUP
其中ATTRIBUTE支持的屬性:
Login屬性:
ORACLE_USER
SERVICE_NAME
CLIENT_OS_USER
CLIENT_PROGRAM
CLIENT_MACHINE
Runtime屬性:
MODULE_NAME
MODULE_NAME_ACTION
SERVICE_MODULE
SERVICE_MODULE_ACTION
例子:
將sys映射到backup_cg
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA();
DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING
(DBMS_RESOURCE_MANAGER.ORACLE_USER, 'sys', 'backup_cg');
DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
設置session屬性作為映射條件時的優先級
其中必須制定EXPLICIT ,并且EXPLICIT 必須為1
BEGIN
DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING_PRI(
EXPLICIT => 1,
SERVICE_MODULE_ACTION => 2,
SERVICE_MODULE => 3,
MODULE_NAME_ACTION => 4,
MODULE_NAME => 5,
SERVICE_NAME => 6,
ORACLE_USER => 7,
CLIENT_PROGRAM => 8,
CLIENT_OS_USER => 9,
CLIENT_MACHINE => 10);
END;
使資源計劃生效
ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = 'mydb_plan';
加上FORCE:可以禁止scheduler自動切換資源計劃
ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = 'FORCE:mydb_plan';
下面是官方文檔給出的一個練習例子
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA();
DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'bugdb_plan', COMMENT => 'Resource plan/method for bug users sessions');
DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'maildb_plan', COMMENT => 'Resource plan/method for mail users sessions');
DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'mydb_plan', COMMENT => 'Resource plan/method for bug and mail users sessions');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Online_group', COMMENT => 'Resource consumer group/method for online bug users sessions');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Batch_group', COMMENT => 'Resource consumer group/method for batch job bug users sessions');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Bug_Maint_group', COMMENT => 'Resource consumer group/method for users sessions for bug db maint');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Users_group', COMMENT => 'Resource consumer group/method for mail users sessions');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Postman_group', COMMENT => 'Resource consumer group/method for mail postman');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Mail_Maint_group', COMMENT => 'Resource consumer group/method for users sessions for mail db maint');
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'Online_group',
COMMENT => 'online bug users sessions at level 1', CPU_P1 => 80, CPU_P2=> 0,
PARALLEL_DEGREE_LIMIT_P1 => 8);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'Batch_group',
COMMENT => 'batch bug users sessions at level 1', CPU_P1 => 20, CPU_P2 => 0,
PARALLEL_DEGREE_LIMIT_P1 => 2);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'Bug_Maint_group',
COMMENT => 'bug maintenance users sessions at level 2', CPU_P1 => 0, CPU_P2 => 100,
PARALLEL_DEGREE_LIMIT_P1 => 3);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
COMMENT => 'all other users sessions at level 3', CPU_P1 => 0, CPU_P2 => 0,
CPU_P3 => 100);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'Postman_group',
COMMENT => 'mail postman at level 1', CPU_P1 => 40, CPU_P2 => 0,
PARALLEL_DEGREE_LIMIT_P1 => 4);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'Users_group',
COMMENT => 'mail users sessions at level 2', CPU_P1 => 0, CPU_P2 => 80,
PARALLEL_DEGREE_LIMIT_P1 => 4);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'Mail_Maint_group',
COMMENT => 'mail maintenance users sessions at level 2', CPU_P1 => 0, CPU_P2 => 20,
PARALLEL_DEGREE_LIMIT_P1 => 2);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
COMMENT => 'all other users sessions at level 3', CPU_P1 => 0, CPU_P2 => 0,
CPU_P3 => 100);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'mydb_plan',
GROUP_OR_SUBPLAN => 'maildb_plan',
COMMENT=> 'all mail users sessions at level 1', CPU_P1 => 30);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'mydb_plan',
GROUP_OR_SUBPLAN => 'bugdb_plan',
COMMENT => 'all bug users sessions at level 1', CPU_P1 => 70);
DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
例子2
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA();
DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'erp_plan', COMMENT => 'Resource plan/method for ERP Database');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'oltp', COMMENT => 'Resource consumer group/method for OLTP jobs');
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'batch', COMMENT => 'Resource consumer group/method for BATCH jobs');
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'erp_plan',
GROUP_OR_SUBPLAN => 'oltp', COMMENT => 'OLTP sessions', CPU_P1 => 80,
SWITCH_GROUP => 'batch', SWITCH_TIME => 3,SWITCH_ESTIMATE => TRUE,
UNDO_POOL => 200);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'erp_plan',
GROUP_OR_SUBPLAN => 'batch', COMMENT => 'BATCH sessions', CPU_P2 => 100,
ACTIVE_SESS_POOL_P1 => 5, QUEUEING_P1 => 600,
MAX_EST_EXEC_TIME => 3600);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'erp_plan',
GROUP_OR_SUBPLAN => 'OTHER_GROUPS', COMMENT => 'mandatory', CPU_P3 => 100);
DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
監控、調整resource manager
查看用戶消耗組權限
下例中,SCOTT可以對應MARKET和SALES兩個組,他可以講別的用戶分派到SALES組,MARKET和SALES兩個都不是SCOTT的初始組
SELECT * FROM DBA_RSRC_CONSUMER_GROUP_PRIVS; GRANTEE GRANTED_GROUP GRANT_OPTION INITIAL_GROUP ------------------------------ ------------------------------ ------------ ------------- PUBLIC DEFAULT_CONSUMER_GROUP YES YES PUBLIC LOW_GROUP NO NO SCOTT MARKET NO NO SCOTT SALES YES NO SYSTEM SYS_GROUP NO YES
查看數據庫中定義的資源計劃
SQL> SELECT PLAN,COMMENTS,STATUS FROM DBA_RSRC_PLANS; PLAN COMMENTS STATUS ----------- ------------------------------------------------------- ------ SYSTEM_PLAN Plan to give system sessions priority ACTIVE BUGDB_PLAN Resource plan/method for bug users sessions ACTIVE MAILDB_PLAN Resource plan/method for mail users sessions ACTIVE MYDB_PLAN Resource plan/method for bug and mail users sessions ACTIVE GREAT_BREAD Great plan for great bread ACTIVE ERP_PLAN Resource plan/method for ERP Database ACTIVE
查看活動的session的消耗組
SQL> SELECT SID,SERIAL#,USERNAME,RESOURCE_CONSUMER_GROUP FROM V$SESSION; SID SERIAL# USERNAME RESOURCE_CONSUMER_GROUP ----- ------- ------------------------ -------------------------------- . . . 11 136 SYS SYS_GROUP 13 16570 SCOTT SALES
查看當前活動的計劃
SQL> ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = mydb_plan; System altered. SQL> SELECT NAME, IS_TOP_PLAN FROM V$RSRC_PLAN; NAME IS_TO ------------------------------------- MYDB_PLAN TRUE MAILDB_PLAN FALSE BUGDB_PLAN FALSE
View | Description |
---|---|
DBA_RSRC_CONSUMER_GROUP_PRIVS USER_RSRC_CONSUMER_GROUP_PRIVS | DBA view lists all resource consumer groups and the users and roles to which they have been granted. USER view lists all resource consumer groups granted to the user. |
DBA_RSRC_CONSUMER_GROUPS | Lists all resource consumer groups that exist in the database. |
DBA_RSRC_MANAGER_SYSTEM_PRIVS USER_RSRC_MANAGER_SYSTEM_PRIVS | DBA view lists all users and roles that have been granted Database Resource Manager system privileges. USER view lists all the users that are granted system privileges for the DBMS_RESOURCE_MANAGER package. |
DBA_RSRC_PLAN_DIRECTIVES | Lists all resource plan directives that exist in the database. |
DBA_RSRC_PLANS | Lists all resource plans that exist in the database. |
DBA_RSRC_GROUP_MAPPINGS | Lists all of the various mapping pairs for all of the session attributes |
DBA_RSRC_MAPPING_PRIORITY | Lists the current mapping priority of each attribute |
DBA_USERS USERS_USERS | DBA view contains information about all users of the database. Specifically, for the Database Resource Manager, it contains the initial resource consumer group for the user. USER view contains information about the current user, and specifically, for the Database Resource Manager, it contains the current user's initial resource consumer group. |
V$ACTIVE_SESS_POOL_MTH | Displays all available active session pool resource allocation methods. |
V$BLOCKING_QUIESCE | Lists all sessions that could potentially block a quiesce operation. Includes sessions that are active and not in the SYS_GROUP consumer group. |
V$PARALLEL_DEGREE_LIMIT_MTH | Displays all available parallel degree limit resource allocation methods. |
V$QUEUEING_MTH | Displays all available queuing resource allocation methods. |
V$RSRC_CONS_GROUP_HISTORY | For each entry in the view V$RSRC_PLAN_HISTORY, contains an entry for each consumer group in the plan showing the cumulative statistics for the consumer group. |
V$RSRC_CONSUMER_GROUP | Displays information about active resource consumer groups. This view can be used for tuning. |
V$RSRC_CONSUMER_GROUP_CPU_MTH | Displays all available CPU resource allocation methods for resource consumer groups. |
V$RSRC_PLAN | Displays the names of all currently active resource plans. |
V$RSRC_PLAN_CPU_MTH | Displays all available CPU resource allocation methods for resource plans. |
V$RSRC_PLAN_HISTORY | Shows when Resource Manager plans were enabled or disabled on the instance. It helps you understand how resources were shared among the consumer groups over time. |
V$RSRC_SESSION_INFO | Displays Resource Manager statistics for each session. Shows how the session has been affected by the Resource Manager. Can be used for tuning. |
V$SESSION | Lists session information for each current session. Specifically, lists the name of the resource consumer group of each current session. |
“怎么用pending area創建資源計劃”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。