Oracle-Database Resource Manager(DBRM)
Oracle Database Resource Manager
Oracle資源管理器(Oracle Database Resource Manager,以下簡稱DBRM)管理資料庫的資源分配。
DBRM解決哪些問題
作業系統決策資料庫資源分配的缺陷
由作業系統決策資料庫資源分配時,可能會遇到以下問題:
- 過度的資源開銷
- 當伺服器程序數量很大時,在Oracle資料庫伺服器程序之間進行作業系統上下文切換會導致過多開銷。
- 低效的排程
- 作業系統使用暫存器排程資料庫服務,這樣做效率很低
- 資源分配不當
- 作業系統平均分配資源給所有的活動程序,不能判斷任務的優先順序
- 不能管理特定的資料庫資源
- 管理並行和活動會話
DBRM解決的問題
-
限制同一組內成員並行度
-
為不同的使用者或應用分配不同的CPU時間
-
監控資源
-
限制每個會話的PGA記憶體量
-
限制會話的空閒時間
-
根據負載需求,允許資料庫使用不同的資源計劃
資源管理組成元素
通過DBMS_RESOURCE_MANAGER 包建立和管理以下元素
元素 | 描述 |
---|---|
Resource consumer group(資源消費者組) | 根據資源需求將會話分組,資源管理器(DBRM)將資源分配給資源消費組,而不是為單獨會話分配資源 |
Resource plan(資源計劃) | 如何將資源分配給資源消費者組的一系列指令規則 |
Resource plan directive(資源計劃指令) | 將資源消費者組與特定計劃相關聯,並指定如何將資源分配給該資源消費者組。 |
Resource consumer group(資源使用者組)
資源使用者組(使用者組)是一組使用者會話,這些會話根據其處理需求進行分組。任何活動的資源計劃中最多隻能有28個資源使用者組。
系統預設資源消費組,他們不能修改或刪除,如下:
- SYS_GROUP:為使用者帳戶SYS或SYSTEM建立的會話的初始資源使用者組
- OTHER_GROUPS:給未分配給資源消費組成員的會話的資源消費組
- ORA$AUTOTASK:
_ORACLE_BACKGROUND_GROUP_
:
檢視資源使用者組
select name from v$rsrc_consumer_group where con_id = 1;
Resource Plan Directives(資源計劃指令)
資源管理器根據屬於當前活動資源計劃的一組資源計劃指令將資源分配給使用者組。指令可以通過多種方式限制使用者組的資源分配。例如,它可以控制使用者組獲得的CPU佔總CPU的百分比,並且可以限制使用者組中活動會話的總數。
Resource plan(資源計劃)
資源計劃是指令的容器,這些指令指定了如何將資源分配給資源使用者組。
資源管理器管理許可權
需要授權 ADMINISTER_RESOURCE_MANAGER 系統許可權
許可權管理
通過DBMS_RESOURCE_MANAGER_PRIVS包的過程給使用者或角色進行授權和回收 ADMINISTER_RESOURCE_MANAGER 系統許可權
Procedure | 描述 |
---|---|
GRANT_SYSTEM_PRIVILEGE |
Grants the ADMINISTER_RESOURCE_MANAGER system privilege to a user or role. |
REVOKE_SYSTEM_PRIVILEGE |
Revokes the ADMINISTER_RESOURCE_MANAGER system privilege from a user or role. |
示例
授權資源管理器的管理許可權給HR使用者
BEGIN
DBMS_RESOURCE_MANAGER_PRIVS.GRANT_SYSTEM_PRIVILEGE(
GRANTEE_NAME => 'HR',
PRIVILEGE_NAME => 'ADMINISTER_RESOURCE_MANAGER',
ADMIN_OPTION => FALSE);
END;
/
將會話分配給資源使用者組
會話的兩種屬性型別:
- login attributes
- run-time attributes
建立使用者組對映規則
通過DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING過程將會話屬性/值對對映到使用者組
PROCEDURE SET_CONSUMER_GROUP_MAPPING
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
ATTRIBUTE VARCHAR2 IN
VALUE VARCHAR2 IN
CONSUMER_GROUP VARCHAR2 IN DEFAULT
Parameter | Description |
---|---|
ATTRIBUTE |
The session attribute type, specified as a package constant |
VALUE |
The value of the attribute |
CONSUMER_GROUP |
The consumer group to map to for this attribute/value pair |
ATTRIBUTE引數列舉值:
Attribute | Type | Description |
---|---|---|
ORACLE_USER |
Login | The Oracle Database user name |
SERVICE_NAME |
Login | The database service name used by the client to establish a connection |
CLIENT_OS_USER |
Login | The operating system user name of the client that is logging in |
CLIENT_PROGRAM |
Login | The name of the client program used to log in to the server |
CLIENT_MACHINE |
Login | The name of the computer from which the client is making the connection |
CLIENT_ID |
Login | The client identifier for the session The client identifier session attribute is set by the DBMS_SESSION.SET_IDENTIFIER procedure. |
MODULE_NAME |
Run-time | The module name in the currently running application as set by the DBMS_APPLICATION_INFO.SET_MODULE procedure or the equivalent OCI attribute setting |
MODULE_NAME_ACTION |
Run-time | A combination of the current module and the action being performed as set by either of the following procedures or their equivalent OCI attribute setting:DBMS_APPLICATION_INFO.SET_MODULE DBMS_APPLICATION_INFO.SET_ACTION The attribute is specified as the module name followed by a period (.), followed by the action name ( module_name.action_name ). |
SERVICE_MODULE |
Run-time | A combination of service and module names in this form: service_name.module_name |
SERVICE_MODULE_ACTION |
Run-time | A combination of service name, module name, and action name, in this form: service_name.module_name.action_name |
ORACLE_FUNCTION |
Run-time | An RMAN or Data Pump operation. Valid values are DATALOAD , BACKUP , and COPY . There are predefined mappings for each of these values. If your session is performing any of these functions, it is automatically mapped to a predefined consumer group. |
示例
通過以下PL / SQL塊使使用者SCOTT每次登入時都對映到DEV_GROUP使用者組:
-- 1. 建立 pending area
exec dbms_resource_manager.create_pending_area;
-- 2. 建立對映規則
BEGIN
DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING
(DBMS_RESOURCE_MANAGER.ORACLE_USER, 'SCOTT', 'DEV_GROUP');
END;
/
-- 3. validate pending area
exec dbms_resource_manager.validate_pending_area;
-- 4. 提交 pending area
exec dbms_resource_manager.submit_pending_area;
萬用字元
SET_CONSUMER_GROUP_MAPPING過程支援萬用字元
%
:表示多個字元_
: 表示單個字元\
:表示轉移字元
萬用字元只支援以下屬性:
CLIENT_OS_USER
CLIENT_PROGRAM
CLIENT_MACHINE
MODULE_NAME
MODULE_NAME_ACTION
SERVICE_MODULE
SERVICE_MODULE_ACTION
修改或刪除使用者組對映規則
修改對映規則
執行SET_CONSUMER_GROUP_MAPPING過程將屬性/值對指定給一個新使用者組
刪除對映規則
執行SET_CONSUMER_GROUP_MAPPING過程將屬性/值對指定給NULL使用者組
建立對映規則優先順序
使用SET_CONSUMER_GROUP_MAPPING_PRI過程將每個屬性的優先順序設定為從1(最重要)到12(最不重要)的唯一整數。
以下示例說明了這種優先順序設定:
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,
CLIENT_ID => 11);
END;
/
SET_CONSUMER_GROUP_MAPPING_PRI要求包含偽屬性EXPLICIT作為引數,且必須設定為1。
示例
為了說明對映規則優先順序是如何工作的,設定以下對映規則
-- 1. 建立 pending area
exec dbms_resource_manager.create_pending_area;
-- 2. 建立對映規則
-- rule 1
BEGIN
DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING
(DBMS_RESOURCE_MANAGER.ORACLE_USER, 'SCOTT', 'DEV_GROUP');
END;
/
-- 2.2 rule 2
BEGIN
DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING
(DBMS_RESOURCE_MANAGER.MODULE_NAME, 'EOD_REPORTS', 'LOW_PRIORITY');
END;
/
-- 優先順序
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,
CLIENT_ID => 11);
END;
/
-- 3. validate pending area
exec dbms_resource_manager.validate_pending_area;
-- 4. 提交 pending area
exec dbms_resource_manager.submit_pending_area;
在SCOTT的連線會話中使用DBMS_APPLICATION_INFO.SET_MODULE過程設定module name為'EOD_REPORTS',此刻,就會將該會話分配到'LOW_PRIORITY'使用者組。因為module name的對映規則比使用者名稱的對映規則優先順序高。
通過DBA_RSRC_MAPPING_PRIORITY 檢視檢視會話對映規則的順序
select * from DBA_RSRC_MAPPING_PRIORITY;
手動切換使用者組
提供2個過程實現切換使用者組:
- DBMS_RESOURCE_MANAGER.SWITCH_CONSUMER_GROUP_FOR_SESS
- 調整單個連線會話的優先順序
- DBMS_RESOURCE_MANAGER.SWITCH_CONSUMER_GROUP_FOR_USER
- 使用者的所有會話
切換指定會話到使用者組
SWITCH_CONSUMER_GROUP_FOR_SESS過程使指定的會話立即移入指定的資源使用者組。實際上,此過程可以提高或降低會話的優先順序。
PROCEDURE SWITCH_CONSUMER_GROUP_FOR_SESS
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
SESSION_ID NUMBER IN
SESSION_SERIAL NUMBER IN
CONSUMER_GROUP VARCHAR2 IN
例子
將會話(17,12345)切換到HIGH_PRIORITY使用者組
BEGIN
DBMS_RESOURCE_MANAGER.SWITCH_CONSUMER_GROUP_FOR_SESS ('17', '12345', 'HIGH_PRIORITY');
END;
/
切換使用者的所有會話
SWITCH_CONSUMER_GROUP_FOR_USER過程更改與指定使用者名稱有關的所有會話的資源使用者組。
PROCEDURE SWITCH_CONSUMER_GROUP_FOR_USER
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
USER VARCHAR2 IN
CONSUMER_GROUP VARCHAR2 IN
例子
將屬於使用者HR的所有會話切換到LOW_GROUP使用者組
BEGIN
DBMS_RESOURCE_MANAGER.SWITCH_CONSUMER_GROUP_FOR_USER ('HR', 'LOW_GROUP');
END;
/
授權使用者或應用程式切換使用者組
賦予DBMS_SESSION.SWITCH_CURRENT_CONSUMER_GROUP過程的執行許可權,可以讓使用者或程式切換當前的使用者組。
PROCEDURE SWITCH_CURRENT_CONSUMER_GROUP
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
NEW_CONSUMER_GROUP VARCHAR2 IN
OLD_CONSUMER_GROUP VARCHAR2 OUT
INITIAL_GROUP_ON_ERROR BOOLEAN IN
過程的引數含義
Parameter | Description |
---|---|
NEW_CONSUMER_GROUP |
使用者要切換到的消費者組。 |
OLD_CONSUMER_GROUP |
返回使用者切換到的使用者組的名稱。 |
INITIAL_GROUP_ON_ERROR |
控制切換錯誤的行為: 如果為TRUE,則在發生錯誤的情況下,使用者將切換到初始使用者組。如果為FALSE,則會引發錯誤。 |
例子
SET serveroutput on
DECLARE
old_group varchar2(30);
BEGIN
DBMS_SESSION.SWITCH_CURRENT_CONSUMER_GROUP('BATCH_GROUP', old_group, FALSE);
DBMS_OUTPUT.PUT_LINE('OLD GROUP = ' || old_group);
END;
/
自動切換使用者組
以下是這種自動會話切換型別涉及的資源計劃指令屬性。
SWITCH_GROUP
SWITCH_TIME
SWITCH_ESTIMATE
SWITCH_IO_MEGABYTES
SWITCH_IO_REQS
SWITCH_FOR_CALL
SWITCH_IO_LOGICAL
SWITCH_ELAPSED_TIME
授予和撤銷切換特權
DBMS_RESOURCE_MANAGER_PRIVS過程可以授權或回收 使用者,角色,PUBLIC 的切換許可權。
Procedure | Description |
---|---|
GRANT_SWITCH_CONSUMER_GROUP |
Grants permission to a user, role, or PUBLIC to switch to a specified resource consumer group. |
REVOKE_SWITCH_CONSUMER_GROUP |
Revokes permission for a user, role, or PUBLIC to switch to a specified resource consumer group. |
OTHER_GROUPS擁有授予PUBLIC的切換許可權
授權切換許可權
向用戶SCOTT授予切換到使用者組OLTP的特權,並且它可以給其它使用者授予切換特權
BEGIN
DBMS_RESOURCE_MANAGER_PRIVS.GRANT_SWITCH_CONSUMER_GROUP (
GRANTEE_NAME => 'SCOTT',
CONSUMER_GROUP => 'OLTP',
GRANT_OPTION => TRUE);
END;
/
回收切換特權
回收使用者SCOTT切換到使用者組OLTP的特權
BEGIN
DBMS_RESOURCE_MANAGER_PRIVS.REVOKE_SWITCH_CONSUMER_GROUP (
REVOKEE_NAME => 'SCOTT',
CONSUMER_GROUP => 'OLTP');
END;
/
資源管理器管理的資源型別
- CPU
- Exadata I/O
- Parallel Execution Servers
- Program Global Area (PGA)
- Runaway Queries
- Active Session Pool with Queuing
- Undo Pool
- Idle Time Limit
CPU
資源管理器分配尚未使用的CPU資源給使用者組,也可以限制特定使用者組CPU資源
管理屬性
使用管理屬性MGMT_Pn(其中n是1到8之間的整數)來指定多個級別的CPU資源分配。例如,使用MGMT_P1指令屬性指定級別1的CPU資源分配,並使用MGMT_P2指令屬性指定級別2的資源分配。
使用限制(Utilization Limit)
使用UTILIZATION_LIMIT屬性為資源使用者組的CPU利用率指定上限。
Program Global Area (PGA)
通過配置DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE過程的session_pga_limit引數值限制使用者組中每個連線會話的PGA資源。
資源計劃
建立簡單的資源計劃
使用DBMS_RESOURCE_MANAGER.CREATE_SIMPLE_PLAN過程建立資源計劃
示例
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_SIMPLE_PLAN(simple_plan => 'SIMPLE_PLAN1'
,consumer_group1 => 'MYGROUP1'
,group1_percent => 80
,consumer_group2 => 'MYGROUP2'
,group2_percent => 20);
END;
/
建立複雜的資源計劃
流程步驟
- 建立暫存區域(Create a pending area)
- 使用CREATE_PENDING_AREA過程完成
- 建立、修改或刪除使用者組(Create, modify, or delete consumer groups)
- 使用CREATE_CONSUMER_GROUP過程完成
- 將會話對映到使用者組(Map sessions to consumer groups)
- 使用SET_CONSUMER_GROUP_MAPPING過程完成
- 建立資源計劃(Create the resource plan)
- 使用CREATE_PLAN完成
- 建立資源計劃指令(Create resource plan directives)
- 使用CREATE_PLAN_DIRECTIVE完成
- 驗證暫存區域(Validate the pending area)
- 使用VALIDATE_PENDING_AREA完成
- 提交暫存區域(Submit the pending area)
- 使用SUBMIT_PENDING_AREA完成
- 清理暫存區域
- 使用CLEAR_PENDING_AREA完成
詳細過程
Pending area
Pending area:暫掛區域是暫存區域,可以在其中建立新的資源計劃,更新現有計劃或刪除計劃,而不會影響當前正在執行的應用程式。
建立暫存區域
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA();
END;
/
建立資源使用者組
- 過程的引數
PROCEDURE CREATE_CONSUMER_GROUP
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
CONSUMER_GROUP VARCHAR2 IN
COMMENT VARCHAR2 IN DEFAULT
CPU_MTH VARCHAR2 IN DEFAULT
MGMT_MTH VARCHAR2 IN DEFAULT
CATEGORY VARCHAR2 IN DEFAULT
- 引數說明
引數名稱 | 描述 |
---|---|
CONSUMER_GROUP |
Name to assign to the consumer group. |
COMMENT |
註解 |
CPU_MTH |
不推薦使用。請使用MGMT_MTH。 |
MGMT_MTH |
用於在消費者組中的會話之間分配CPU的資源分配方法。預設使用輪詢方式( 'ROUND-ROBIN' ),它使用迴圈排程程式來確保公平執行會話。另一個方式是 'RUN-TO-COMPLETION' ,它指定長時間執行的會話排在其他會話之前。這樣有助於長時間執行的會話(例如批處理)更快地完成。 |
- 示例
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP (
CONSUMER_GROUP => 'OLTP',
COMMENT => 'OLTP applications');
END;
/
-- 相當於
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP (
CONSUMER_GROUP => 'OLTP',
COMMENT => 'OLTP applications',
MGMT_MTH => 'ROUND-ROBIN');
END;
/
對映會話到使用者組
- 過程
PROCEDURE SET_CONSUMER_GROUP_MAPPING
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
ATTRIBUTE VARCHAR2 IN
VALUE VARCHAR2 IN
CONSUMER_GROUP VARCHAR2 IN DEFAULT
- 引數說明
引數名稱 | Description |
---|---|
ATTRIBUTE |
會話屬性型別 |
VALUE |
屬性值 |
CONSUMER_GROUP |
資源消費者組的名稱 |
- 示例
- 將使用者OE的會話對映到OLTP使用者組
BEGIN
DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING(
ATTRIBUTE => DBMS_RESOURCE_MANAGER.ORACLE_USER,
VALUE => 'OE',
CONSUMER_GROUP => 'OLTP');
END;
/
建立資源計劃
- 過程定義
PROCEDURE CREATE_PLAN
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
PLAN VARCHAR2 IN
COMMENT VARCHAR2 IN DEFAULT
CPU_MTH VARCHAR2 IN DEFAULT
ACTIVE_SESS_POOL_MTH VARCHAR2 IN DEFAULT
PARALLEL_DEGREE_LIMIT_MTH VARCHAR2 IN DEFAULT
QUEUEING_MTH VARCHAR2 IN DEFAULT
MGMT_MTH VARCHAR2 IN DEFAULT
SUB_PLAN BOOLEAN IN DEFAULT
MAX_IOPS NUMBER IN DEFAULT
MAX_MBPS NUMBER IN DEFAULT
- 引數說明
引數名稱 | Description |
---|---|
PLAN |
計劃名稱 |
COMMENT |
註解 |
CPU_MTH |
不推薦使用。請使用MGMT_MTH。 |
ACTIVE_SESS_POOL_MTH |
活動會話池資源分配方法。ACTIVE_SESS_POOL_ABSOLUTE是預設的唯一方法。 |
PARALLEL_DEGREE_LIMIT_MTH |
用於指定PARALLEL_DEGREE_LIMIT_ABSOLUTE上的限制的資源分配方法是預設且唯一方法。 |
QUEUEING_MTH |
排隊資源分配方法。控制從佇列中刪除非活動會話並將其新增到活動會話池。FIFO_TIMEOUT是預設且唯一可用的方法。 |
MGMT_MTH |
用於指定每個消費者組或子計劃獲得多少CPU的資源分配方法。'EMPHASIS'(預設方法)適用於使用百分比指定CPU如何在消費者組之間分配的單級或多級計劃。'RATIO' 適用於使用比率指定CPU分配方式的單級計劃。 |
SUB_PLAN |
如果為TRUE,則該計劃不能用作頂級計劃;它只能用作子計劃。預設值為FALSE。 |
- 示例
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PLAN(
PLAN => 'DAYTIME',
COMMENT => 'More resources for OLTP applications');
END;
/
建立資源計劃指令
- 過程定義
PROCEDURE CREATE_PLAN_DIRECTIVE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
PLAN VARCHAR2 IN
GROUP_OR_SUBPLAN VARCHAR2 IN
COMMENT VARCHAR2 IN DEFAULT
CPU_P1 NUMBER IN DEFAULT
CPU_P2 NUMBER IN DEFAULT
CPU_P3 NUMBER IN DEFAULT
CPU_P4 NUMBER IN DEFAULT
CPU_P5 NUMBER IN DEFAULT
CPU_P6 NUMBER IN DEFAULT
CPU_P7 NUMBER IN DEFAULT
CPU_P8 NUMBER IN DEFAULT
ACTIVE_SESS_POOL_P1 NUMBER IN DEFAULT
QUEUEING_P1 NUMBER IN DEFAULT
PARALLEL_DEGREE_LIMIT_P1 NUMBER IN DEFAULT
SWITCH_GROUP VARCHAR2 IN DEFAULT
SWITCH_TIME NUMBER IN DEFAULT
SWITCH_ESTIMATE BOOLEAN IN DEFAULT
MAX_EST_EXEC_TIME NUMBER IN DEFAULT
UNDO_POOL NUMBER IN DEFAULT
MAX_IDLE_TIME NUMBER IN DEFAULT
MAX_IDLE_BLOCKER_TIME NUMBER IN DEFAULT
SWITCH_TIME_IN_CALL NUMBER IN DEFAULT
MGMT_P1 NUMBER IN DEFAULT
MGMT_P2 NUMBER IN DEFAULT
MGMT_P3 NUMBER IN DEFAULT
MGMT_P4 NUMBER IN DEFAULT
MGMT_P5 NUMBER IN DEFAULT
MGMT_P6 NUMBER IN DEFAULT
MGMT_P7 NUMBER IN DEFAULT
MGMT_P8 NUMBER IN DEFAULT
SWITCH_IO_MEGABYTES NUMBER IN DEFAULT
SWITCH_IO_REQS NUMBER IN DEFAULT
SWITCH_FOR_CALL BOOLEAN IN DEFAULT
MAX_UTILIZATION_LIMIT NUMBER IN DEFAULT
PARALLEL_TARGET_PERCENTAGE NUMBER IN DEFAULT
PARALLEL_QUEUE_TIMEOUT NUMBER IN DEFAULT
PARALLEL_SERVER_LIMIT NUMBER IN DEFAULT
UTILIZATION_LIMIT NUMBER IN DEFAULT
SWITCH_IO_LOGICAL NUMBER IN DEFAULT
SWITCH_ELAPSED_TIME NUMBER IN DEFAULT
SHARES NUMBER IN DEFAULT
PARALLEL_STMT_CRITICAL VARCHAR2 IN DEFAULT
SESSION_PGA_LIMIT NUMBER IN DEFAULT
PQ_TIMEOUT_ACTION VARCHAR2 IN DEFAULT
- 引數說明
引數 | 描述 |
---|---|
PLAN |
Name of the resource plan to which the directive belongs. |
GROUP_OR_SUBPLAN |
Name of the consumer group or subplan to which to allocate resources. |
COMMENT |
Any comment. |
CPU_P1 |
Deprecated. Use MGMT_P1 . |
CPU_P2 |
Deprecated. Use MGMT_P2 . |
CPU_P3 |
Deprecated. Use MGMT_P3 . |
CPU_P4 |
Deprecated. Use MGMT_P4 . |
CPU_P5 |
Deprecated. Use MGMT_P5 . |
CPU_P6 |
Deprecated. Use MGMT_P6 . |
CPU_P7 |
Deprecated. Use MGMT_P7 . |
CPU_P8 |
Deprecated. Use MGMT_P8 . |
ACTIVE_SESS_POOL_P1 |
Specifies the maximum number of concurrently active sessions for a consumer group. Other sessions await execution in an inactive session queue. Default is UNLIMITED . |
QUEUEING_P1 |
Specifies time (in seconds) after which a session in an inactive session queue (waiting for execution) times out and the call is aborted. Default is UNLIMITED . |
PARALLEL_DEGREE_LIMIT_P1 |
Specifies a limit on the degree of parallelism for any operation. Default is UNLIMITED . |
SWITCH_GROUP |
Specifies the consumer group to which a session is switched if switch criteria are met.If the group name is CANCEL_SQL , then the current call is canceled when switch criteria are met. If the group name is CANCEL_SQL , then the SWITCH_FOR_CALL parameter is always set to TRUE , overriding the user-specified setting.If the group name is KILL_SESSION , then the session is killed when switch criteria are met.If the group name is LOG_ONLY , then information about the session is recorded in real-time SQL monitoring, but no specific action is taken for the session.If NULL , then the session is not switched and no additional logging is performed. The default is NULL . An error is returned if this parameter is set to NULL and any other switch parameter is set to non-NULL .Note: The following consumer group names are reserved: CANCEL_SQL , KILL_SESSION , and LOG_ONLY . An error results if you attempt to create a consumer group with one of these names. |
SWITCH_TIME |
Specifies the time (in CPU seconds) that a call can execute before an action is taken. Default is UNLIMITED . The action is specified by SWITCH_GROUP . |
SWITCH_ESTIMATE |
If TRUE , the database estimates the execution time of each call, and if estimated execution time exceeds SWITCH_TIME , the session is switched to the SWITCH_GROUP before beginning the call. Default is FALSE .The execution time estimate is obtained from the optimizer. The accuracy of the estimate is dependent on many factors, especially the quality of the optimizer statistics. In general, you should expect statistics to be no more accurate than ± 10 minutes. |
MAX_EST_EXEC_TIME |
Specifies the maximum execution time (in CPU seconds) allowed for a call. If the optimizer estimates that a call will take longer than MAX_EST_EXEC_TIME , the call is not allowed to proceed and ORA-07455 is issued. If the optimizer does not provide an estimate, this directive has no effect. Default is UNLIMITED .The accuracy of the estimate is dependent on many factors, especially the quality of the optimizer statistics. |
UNDO_POOL |
Sets a maximum in kilobytes (K) on the total amount of undo for uncommitted transactions that can be generated by a consumer group. Default is UNLIMITED . |
MAX_IDLE_TIME |
Indicates the maximum session idle time, in seconds. Default is NULL , which implies unlimited. |
MAX_IDLE_BLOCKER_TIME |
Indicates the maximum session idle time of a blocking session, in seconds. Default is NULL , which implies unlimited. |
SWITCH_TIME_IN_CALL |
Deprecated. Use SWITCH_FOR_CALL . |
MGMT_P1 |
For a plan with the MGMT_MTH parameter set to EMPHASIS , specifies the CPU percentage to allocate at the first level. For MGMT_MTH set to RATIO , specifies the weight of CPU usage. Default is NULL for all MGMT_P n parameters. |
MGMT_P2 |
For EMPHASIS , specifies CPU percentage to allocate at the second level. Not applicable for RATIO . |
MGMT_P3 |
For EMPHASIS , specifies CPU percentage to allocate at the third level. Not applicable for RATIO . |
MGMT_P4 |
For EMPHASIS , specifies CPU percentage to allocate at the fourth level. Not applicable for RATIO . |
MGMT_P5 |
For EMPHASIS , specifies CPU percentage to allocate at the fifth level. Not applicable for RATIO . |
MGMT_P6 |
For EMPHASIS , specifies CPU percentage to allocate at the sixth level. Not applicable for RATIO . |
MGMT_P7 |
For EMPHASIS , specifies CPU percentage to allocate at the seventh level. Not applicable for RATIO . |
MGMT_P8 |
For EMPHASIS , specifies CPU percentage to allocate at the eighth level. Not applicable for RATIO . |
SWITCH_IO_MEGABYTES |
Specifies the number of megabytes of physical I/O that a session can transfer (read and write) before an action is taken. Default is UNLIMITED . The action is specified by SWITCH_GROUP . |
SWITCH_IO_REQS |
Specifies the number of physical I/O requests that a session can execute before an action is taken. Default is UNLIMITED . The action is specified by SWITCH_GROUP . |
SWITCH_FOR_CALL |
If TRUE , a session that was automatically switched to another consumer group (according to SWITCH_TIME , SWITCH_IO_MEGABYTES , or SWITCH_IO_REQS ) is returned to its original consumer group when the top level call completes. Default is NULL . |
PARALLEL_QUEUE_TIMEOUT |
Specifies the maximum time, in seconds, that a parallel statement can wait in the parallel statement queue before it is timed out. |
PARALLEL_SERVER_LIMIT |
Specifies the maximum percentage of the parallel execution server pool that a particular consumer group can use. The number of parallel execution servers used by a particular consumer group is counted as the sum of the parallel execution servers used by all sessions in that consumer group. |
UTILIZATION_LIMIT |
Specifies the maximum CPU utilization percentage permitted for the consumer group. This value overrides any level allocations for CPU (MGMT_P1 through MGMT_P8 ), and also imposes a limit on total CPU utilization when unused allocations are redistributed. You can specify this attribute and leave MGMT_P1 through MGMT_P8 NULL . |
SWITCH_IO_LOGICAL |
Number of logical I/O requests that will trigger the action specified by SWITCH_GROUP . As with other switch directives, if SWITCH_FOR_CALL is TRUE , then the number of logical I/O requests is accumulated from the start of a call. Otherwise, the number of logical I/O requests is accumulated for the length of the session. |
SWITCH_ELAPSED_TIME |
Elapsed time, in seconds, that will trigger the action specified by SWITCH_GROUP . As with other switch directives, if SWITCH_FOR_CALL is TRUE , then the elapsed time is accumulated from the start of a call. Otherwise, the elapsed time is accumulated for the length of the session. |
SHARES |
Allocates resources among pluggable databases (PDBs) in a multitenant container database (CDB). Also allocates resources among consumer groups in a non-CDB or in a PDB.See "CDB Resource Plans". |
PARALLEL_STMT_CRITICAL |
Specifies whether parallel statements from the consumer group are critical.When BYPASS_QUEUE is specified, parallel statements from the consumer group are critical. These statements bypass the parallel queue and are executed immediately.When FALSE or NULL (the default) is specified, parallel statements from the consumer group are not critical. These statements are added to the parallel queue when necessary. |
SESSION_PGA_LIMIT |
Specifies the maximum amount of PGA memory, in megabytes, that can be allocated to each session in a particular consumer group. If a session exceeds the limit, then its process is terminated with an ORA-10260 error. |
- 示例1
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (
PLAN => 'DAYTIME',
GROUP_OR_SUBPLAN => 'OLTP',
COMMENT => 'OLTP group',
MGMT_P1 => 75);
END;
/
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (
PLAN => 'DAYTIME',
GROUP_OR_SUBPLAN => 'REPORTING',
COMMENT => 'Reporting group',
MGMT_P1 => 15,
PARALLEL_DEGREE_LIMIT_P1 => 8,
ACTIVE_SESS_POOL_P1 => 4,
SESSION_PGA_LIMIT => 20);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE (
PLAN => 'DAYTIME',
GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
COMMENT => 'This one is required',
MGMT_P1 => 10);
END;
/
- 示例2
使用RATIO方法分配CPU,該方法使用比率而不是百分比。假設應用程式提供了三種服務級別:Gold, Silver 和 Bronze。這樣,建立三個名為GOLD_CG,SILVER_CG和BRONZE_CG的使用者組,並建立以下資源計劃:
GOLD_CG,SILVER_CG,BRONZE_CG和OTHER_GROUPS消費組的CPU分配比例分別為10:5:2:1
BEGIN
DBMS_RESOURCE_MANAGER.CREATE_PLAN
(PLAN => 'SERVICE_LEVEL_PLAN',
MGMT_MTH => 'RATIO',
COMMENT => 'Plan that supports three service levels');
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE
(PLAN => 'SERVICE_LEVEL_PLAN',
GROUP_OR_SUBPLAN => 'GOLD_CG',
COMMENT => 'Gold service level customers',
MGMT_P1 => 10);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE
(PLAN => 'SERVICE_LEVEL_PLAN',
GROUP_OR_SUBPLAN => 'SILVER_CG',
COMMENT => 'Silver service level customers',
MGMT_P1 => 5);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE
(PLAN => 'SERVICE_LEVEL_PLAN',
GROUP_OR_SUBPLAN => 'BRONZE_CG',
COMMENT => 'Bronze service level customers',
MGMT_P1 => 2);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE
(PLAN => 'SERVICE_LEVEL_PLAN',
GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
COMMENT => 'Lowest priority sessions',
MGMT_P1 => 1);
END;
/
驗證暫存區域
-
遵守的規則及檢查項
- 計劃不能包含迴圈,例如子計劃不能引用上層計劃
- 計劃指令引用的所有計劃和資源使用者組必須存在
- 所有計劃都必須具有指向計劃或資源使用者組的計劃指令
- 任何給定級別的所有百分比之和不得超過100
- 無法刪除被活動例項使用的當前頂級計劃
- 以下引數只能出現在引用資源使用者組的計劃指令中,而不能出現在其他資源計劃中:
ACTIVE_SESS_POOL_P1
MAX_EST_EXEC_TIME
MAX_IDLE_BLOCKER_TIME
MAX_IDLE_TIME
PARALLEL_DEGREE_LIMIT_P1
QUEUEING_P1
SESSION_PGA_LIMIT
SWITCH_ESTIMATE
SWITCH_FOR_CALL
SWITCH_GROUP
SWITCH_IO_MEGABYTES
SWITCH_IO_REQS
SWITCH_TIME
UNDO_POOL
UTILIZATION_LIMIT
- 任何活動計劃中最多隻能有28個資源使用者組,且一個計劃最多可以有28個子計劃
- 資源計劃和資源使用者組不能使用相同的名稱
- 任何有效計劃中的都必須有針對OTHER_GROUPS的計劃指令。這樣可以確保為不屬於當前活動計劃中所包含的任何使用者組的會話分配資源(由OTHER_GROUPS指令指定)。
-
示例
BEGIN
DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
END;
/
提交暫存區域
提交過程包含驗證,可以不需要單獨呼叫VALIDATE_PENDING_AREA過程。在執行驗證之前,不會提交任何更改。
BEGIN
DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
/
清理暫存區域
BEGIN
DBMS_RESOURCE_MANAGER.CLEAR_PENDING_AREA();
END;
/
啟用資源管理器並切換計劃
啟用資源管理器
初始化引數方式
配置初始化引數RESOURCE_MANAGER_PLAN啟用資源管理器。預設未啟用資源管理器
ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = 'mydb_plan';
--
ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = 'FORCE:mydb_plan';
Oracle Scheduler Windows方式
-- 建立維護視窗
BEGIN
DBMS_SCHEDULER.CREATE_WINDOW(
window_name => 'EARLY_MORNING_WINDOW',
duration => NUMTODSINTERVAL(1, 'hour'),
resource_plan => 'DEFAULT_MAINTENANCE_PLAN',
repeat_interval => 'FREQ=DAILY;BYHOUR=5;BYMINUTE=0;BYSECOND=0');
DBMS_SCHEDULER.ADD_GROUP_MEMBER(
group_name => 'MAINTENANCE_WINDOW_GROUP',
member => 'EARLY_MORNING_WINDOW');
END;
/
-- 啟用
BEGIN
dbms_auto_task_admin.enable(
client_name => 'RESOURCE_PLAN',
operation => NULL,
window_name => 'EARLY_MORNING_WINDOW');
END;
/
檢視
SELECT client_name, status, consumer_group, window_group
FROM dba_autotask_client;
select window_name, resource_plan from dba_scheduler_windows where resource_plan is not null;
關閉資源管理器
- 配置初始化引數
ALTER SYSTEM SET RESOURCE_MANAGER_PLAN = '';
- 關閉資源管理器相關的維護視窗
-- 檢查
select * from DBA_SCHEDULER_WINDOWS;
-- 執行過程將resource_plan屬性值設為空, execute dbms_scheduler.set_attribute('<window name>','RESOURCE_PLAN','');
execute dbms_scheduler.set_attribute('WEEKNIGHT_WINDOW','RESOURCE_PLAN','');
execute dbms_scheduler.set_attribute('WEEKEND_WINDOW','RESOURCE_PLAN','');
select 'execute dbms_scheduler.set_attribute('''||WINDOW_NAME||''',''RESOURCE_PLAN'','''');' cmd_sql from dba_scheduler_windows;
Oracle資料庫資源管理器案例
多級資源計劃案例
結構圖
配置SQL
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', MGMT_P1 => 80, MGMT_P2=> 0);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'Batch_group',
COMMENT => 'batch bug users sessions at level 1', MGMT_P1 => 20, MGMT_P2 => 0,
PARALLEL_DEGREE_LIMIT_P1 => 8);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'Bug_Maint_group',
COMMENT => 'bug maintenance users sessions at level 2', MGMT_P1 => 0, MGMT_P2 => 100);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan',
GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
COMMENT => 'all other users sessions at level 3', MGMT_P1 => 0, MGMT_P2 => 0,
MGMT_P3 => 100);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'Postman_group',
COMMENT => 'mail postman at level 1', MGMT_P1 => 40, MGMT_P2 => 0);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'Users_group',
COMMENT => 'mail users sessions at level 2', MGMT_P1 => 0, MGMT_P2 => 80);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'Mail_Maint_group',
COMMENT => 'mail maintenance users sessions at level 2', MGMT_P1 => 0, MGMT_P2 => 20);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan',
GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
COMMENT => 'all other users sessions at level 3', MGMT_P1 => 0, MGMT_P2 => 0,
MGMT_P3 => 100);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'mydb_plan',
GROUP_OR_SUBPLAN => 'maildb_plan',
COMMENT=> 'all mail users sessions at level 1', MGMT_P1 => 30);
DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'mydb_plan',
GROUP_OR_SUBPLAN => 'bugdb_plan',
COMMENT => 'all bug users sessions at level 1', MGMT_P1 => 70);
DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
/
說明
In this plan schema, CPU resources are allocated as follows:
- Under
mydb_plan
, 30% of CPU is allocated to themaildb_plan
subplan, and 70% is allocated to thebugdb_plan
subplan. Both subplans are at level 1. Becausemydb_plan
itself has no levels below level 1, any resource allocations that are unused by either subplan at level 1 can be used by its sibling subplan. Thus, ifmaildb_plan
uses only 20% of CPU, then 80% of CPU is available tobugdb_plan
. maildb_plan
andbugdb_plan
define allocations at levels 1, 2, and 3. The levels in these subplans are independent of levels in their parent plan,mydb_plan
. That is, all plans and subplans in a plan schema have their own level 1, level 2, level 3, and so on.- Of the 30% of CPU allocated to
maildb_plan
, 40% of that amount (effectively 12% of total CPU) is allocated toPostman_group
at level 1. BecausePostman_group
has no siblings at level 1, there is an implied 60% remaining at level 1. This 60% is then shared byUsers_group
andMail_Maint_group
at level 2, at 80% and 20%, respectively. In addition to this 60%,Users_group
andMail_Maint_group
can also use any of the 40% not used byPostman_group
at level 1. - CPU resources not used by either
Users_group
orMail_Maint_group
at level 2 are allocated toOTHER_GROUPS
, because in multilevel plans, unused resources are reallocated to consumer groups or subplans at the next lower level, not to siblings at the same level. Thus, ifUsers_group
uses only 70% instead of 80%, the remaining 10% cannot be used byMail_Maint_group
. That 10% is available only toOTHER_GROUPS
at level 3. - The 70% of CPU allocated to the
bugdb_plan
subplan is allocated to its consumer groups in a similar fashion. If eitherOnline_group
orBatch_group
does not use its full allocation, the remainder may be used byBug_Maint_group
. IfBug_Maint_group
does not use all of that allocation, the remainder goes toOTHER_GROUPS
.
維護使用者組、資源計劃和計劃指令
更新使用者組
呼叫過程UPDATE_CONSUMER_GROUP更新使用者組
PROCEDURE UPDATE_CONSUMER_GROUP
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
CONSUMER_GROUP VARCHAR2 IN
NEW_COMMENT VARCHAR2 IN DEFAULT
NEW_CPU_MTH VARCHAR2 IN DEFAULT
NEW_MGMT_MTH VARCHAR2 IN DEFAULT
NEW_CATEGORY VARCHAR2 IN DEFAULT
-
建立暫存區域
-
執行UPDATE_CONSUMER_GROUP過程
-
BEGIN DBMS_RESOURCE_MANAGER.UPDATE_CONSUMER_GROUP ( CONSUMER_GROUP => 'OLTP', NEW_COMMENT => 'OLTP applications', NEW_MGMT_MTH => 'ROUND-ROBIN'); END; /
-
-
提交暫存區域
刪除使用者組
呼叫過程DELETE_CONSUMER_GROUP 刪除使用者組
PROCEDURE DELETE_CONSUMER_GROUP
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
CONSUMER_GROUP VARCHAR2 IN
-
建立暫存區域
-
執行DELETE_CONSUMER_GROUP過程
-
BEGIN DBMS_RESOURCE_MANAGER.DELETE_CONSUMER_GROUP (CONSUMER_GROUP => 'OLTP'); END; /
-
-
提交暫存區域
更新資源計劃
PROCEDURE UPDATE_PLAN
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
PLAN VARCHAR2 IN
NEW_COMMENT VARCHAR2 IN DEFAULT
NEW_CPU_MTH VARCHAR2 IN DEFAULT
NEW_ACTIVE_SESS_POOL_MTH VARCHAR2 IN DEFAULT
NEW_PARALLEL_DEGREE_LIMIT_MTH VARCHAR2 IN DEFAULT
NEW_QUEUEING_MTH VARCHAR2 IN DEFAULT
NEW_MGMT_MTH VARCHAR2 IN DEFAULT
NEW_SUB_PLAN BOOLEAN IN DEFAULT
NEW_MAX_IOPS NUMBER IN DEFAULT
NEW_MAX_MBPS NUMBER IN DEFAULT
-
建立暫存區域
-
執行UPDATE_PLAN過程
BEGIN
DBMS_RESOURCE_MANAGER.UPDATE_PLAN (
PLAN => 'DAYTIME',
NEW_COMMENT => '50% more resources for OLTP applications');
END;
/
- 提交暫存區域
刪除資源計劃
-
建立暫存區域
-
執行DELETE_PLAN過程
BEGIN
DBMS_RESOURCE_MANAGER.DELETE_PLAN(PLAN => 'great_bread');
END;
/
- 提交暫存區域
更新計劃指令
PROCEDURE UPDATE_PLAN_DIRECTIVE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
PLAN VARCHAR2 IN
GROUP_OR_SUBPLAN VARCHAR2 IN
NEW_COMMENT VARCHAR2 IN DEFAULT
NEW_CPU_P1 NUMBER IN DEFAULT
NEW_CPU_P2 NUMBER IN DEFAULT
NEW_CPU_P3 NUMBER IN DEFAULT
NEW_CPU_P4 NUMBER IN DEFAULT
NEW_CPU_P5 NUMBER IN DEFAULT
NEW_CPU_P6 NUMBER IN DEFAULT
NEW_CPU_P7 NUMBER IN DEFAULT
NEW_CPU_P8 NUMBER IN DEFAULT
NEW_ACTIVE_SESS_POOL_P1 NUMBER IN DEFAULT
NEW_QUEUEING_P1 NUMBER IN DEFAULT
NEW_PARALLEL_DEGREE_LIMIT_P1 NUMBER IN DEFAULT
NEW_SWITCH_GROUP VARCHAR2 IN DEFAULT
NEW_SWITCH_TIME NUMBER IN DEFAULT
NEW_SWITCH_ESTIMATE BOOLEAN IN DEFAULT
NEW_MAX_EST_EXEC_TIME NUMBER IN DEFAULT
NEW_UNDO_POOL NUMBER IN DEFAULT
NEW_MAX_IDLE_TIME NUMBER IN DEFAULT
NEW_MAX_IDLE_BLOCKER_TIME NUMBER IN DEFAULT
NEW_SWITCH_TIME_IN_CALL NUMBER IN DEFAULT
NEW_MGMT_P1 NUMBER IN DEFAULT
NEW_MGMT_P2 NUMBER IN DEFAULT
NEW_MGMT_P3 NUMBER IN DEFAULT
NEW_MGMT_P4 NUMBER IN DEFAULT
NEW_MGMT_P5 NUMBER IN DEFAULT
NEW_MGMT_P6 NUMBER IN DEFAULT
NEW_MGMT_P7 NUMBER IN DEFAULT
NEW_MGMT_P8 NUMBER IN DEFAULT
NEW_SWITCH_IO_MEGABYTES NUMBER IN DEFAULT
NEW_SWITCH_IO_REQS NUMBER IN DEFAULT
NEW_SWITCH_FOR_CALL BOOLEAN IN DEFAULT
NEW_MAX_UTILIZATION_LIMIT NUMBER IN DEFAULT
NEW_PARALLEL_TARGET_PERCENTAGE NUMBER IN DEFAULT
NEW_PARALLEL_QUEUE_TIMEOUT NUMBER IN DEFAULT
NEW_PARALLEL_SERVER_LIMIT NUMBER IN DEFAULT
NEW_UTILIZATION_LIMIT NUMBER IN DEFAULT
NEW_SWITCH_IO_LOGICAL NUMBER IN DEFAULT
NEW_SWITCH_ELAPSED_TIME NUMBER IN DEFAULT
NEW_SHARES NUMBER IN DEFAULT
NEW_PARALLEL_STMT_CRITICAL VARCHAR2 IN DEFAULT
NEW_SESSION_PGA_LIMIT NUMBER IN DEFAULT
NEW_PQ_TIMEOUT_ACTION VARCHAR2 IN DEFAULT
-
建立暫存區域
-
執行UPDATE_PLAN_DIRECTIVE過程
BEGIN
DBMS_RESOURCE_MANAGER.CLEAR_PENDING_AREA();
DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA();
DBMS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTIVE(
PLAN => 'SIMPLE_PLAN1',
GROUP_OR_SUBPLAN => 'MYGROUP1',
NEW_COMMENT => 'Higher priority'
);
DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
/
- 提交暫存區域
刪除計劃指令
PROCEDURE DELETE_PLAN_DIRECTIVE
Argument Name Type In/Out Default?
------------------------------ ----------------------- ------ --------
PLAN VARCHAR2 IN
GROUP_OR_SUBPLAN VARCHAR2 IN
-
建立暫存區域
-
執行DELETE_PLAN_DIRECTIVE過程
BEGIN
DBMS_RESOURCE_MANAGER.DELETE_PLAN_DIRECTIVE(PLAN => 'great_bread');
END;
/
- 提交暫存區域
檢視資源管理器配置和狀態
檢視使用者組
使用檢視DBA_RSRC_CONSUMER_GROUP_PRIVS 顯示授予使用者或角色的使用者組。
col grantee for a12
col granted_group for a32
col grant_option for a16
col initial_group for a16
SELECT GRANTEE, GRANTED_GROUP, GRANT_OPTION, INITIAL_GROUP FROM dba_rsrc_consumer_group_privs;
檢視資源計劃資訊
使用DBA_RSRC_PLANS檢視顯示資料庫中定義的所有資源計劃。
SELECT plan,status,comments FROM dba_rsrc_plans;
檢視會話的當前使用者組
col username for a16
col RESOURCE_CONSUMER_GROUP for a32
SELECT sid,serial#,username,resource_consumer_group FROM v$session;
檢視當前活動的計劃
col name for a24
col is_top_plan for a16
SELECT name, is_top_plan FROM v$rsrc_plan;
監視資源管理器
下面的檢視監視資源管理器的配置
動態檢視名稱 | 說明 |
---|---|
V$RSRC_PLAN |
顯示當前活動的資源計劃及其子計劃 |
V$RSRC_PLAN_HISTORY |
顯示何時在例項上啟用或禁用資源計劃 |
DBA_HIST_RSRC_PLAN | 基於AWR快照儲存資料 |
V$RSRC_CONSUMER_GROUP |
監視消耗的資源,包括CPU,I/O 和並行 |
V$RSRC_CONS_GROUP_HISTORY |
|
DBA_HIST_RSRC_CONSUMER_GROUP | 基於AWR快照儲存資料 |
V$RSRC_SESSION_INFO |
監視連線會話的狀態 |
V$RSRCMGRMETRIC |
跟蹤過去一分鐘內以毫秒為單位的CPU指標,會話數或利用率 |
V$RSRCMGRMETRIC_HISTORY |
跟蹤過去60分鐘內以毫秒為單位的CPU指標,會話數或利用率 |
DBA_HIST_RSRC_METRIC | 基於AWR快照儲存資料 |
SELECT name, is_top_plan FROM v$rsrc_plan;
-- 監視消耗的資源,包括CPU,I/O 和並行
SELECT name, active_sessions, queue_length,
consumed_cpu_time, cpu_waits, cpu_wait_time
FROM v$rsrc_consumer_group;
-- 監視連線會話的狀態
SELECT se.sid sess_id, co.name consumer_group,
se.state, se.consumed_cpu_time cpu_time, se.cpu_wait_time, se.queued_time
FROM v$rsrc_session_info se, v$rsrc_consumer_group co
WHERE se.current_consumer_group_id = co.id
AND co.name <> '_ORACLE_BACKGROUND_GROUP_';
--
col window_name for a32
SELECT sequence# seq, name plan_name,
to_char(start_time, 'YYYY-MM-DD HH24:MM') start_time,
to_char(end_time, 'YYYY-MM-DD HH24:MM') end_time, window_name
FROM v$rsrc_plan_history;
--
SELECT sequence# seq, name, cpu_wait_time, cpu_waits,
consumed_cpu_time FROM v$rsrc_cons_group_history;
-- 跟蹤以毫秒為單位的CPU指標,會話數或過去一分鐘的利用率
SELECT sequence#, consumer_group_name, avg_active_parallel_stmts, avg_queued_parallel_stmts,
avg_active_parallel_servers, avg_queued_parallel_servers, parallel_servers_limit
FROM v$rsrcmgrmetric;
資源管理器資料字典檢視
View | Description |
---|---|
DBA_RSRC_CONSUMER_GROUP_PRIVS |
列出所有資源使用者組以及被授予它們的使用者和角色 |
DBA_RSRC_CONSUMER_GROUPS |
列出所有資源使用者組 |
DBA_RSRC_MANAGER_SYSTEM_PRIVS |
列出了已被授予Resource Manager系統特權的所有使用者和角色 |
DBA_RSRC_PLAN_DIRECTIVES |
列出所有的資源計劃指令 |
DBA_RSRC_PLANS |
列出資料庫中存在的所有資源計劃 |
DBA_RSRC_GROUP_MAPPINGS |
列出所有會話屬性的所有各種對映鍵值對 |
DBA_RSRC_MAPPING_PRIORITY |
列出每個屬性的當前對映優先順序 |
DBA_HIST_RSRC_PLAN |
列出基於AWR快照的啟用的資源計劃的歷史資訊 |
DBA_HIST_RSRC_CONSUMER_GROUP |
顯示基於AWR快照的資源使用者組的歷史統計資訊 |
V$RSRC_CONS_GROUP_HISTORY |
顯示資源使用者組的累積統計資訊 |
V$RSRC_CONSUMER_GROUP |
顯示當前活動的資源使用者組資訊 |
V$RSRCMGRMETRIC |
顯示過去一分鐘內每個消費者組消耗的資源的歷史記錄和累積的CPU等待時間 |
V$RSRCMGRMETRIC_HISTORY |
以分鐘為單位顯示過去一小時每個消費者組的資源消耗歷史記錄和累積的CPU等待時間。如果啟用了新的資源計劃,則將清除歷史記錄 |
V$RSRC_PLAN |
顯示當前啟用的資源計劃 |
V$RSRC_PLAN_HISTORY |
顯示何時在例項上啟用或禁用資源管理計劃。瞭解隨著時間的推移如何在消費者組之間共享資源 |
V$RSRC_SESSION_INFO |
顯示每個會話的資源管理器統計資訊。顯示會話如何受到資源管理器的影響 |