ORACLE RESOURCE MANAGER(资源管理器)

ORACLE RESOURCE MANAGER资源管理器

本文演示简单资源计划的使用,普通资源计划的使用请参考oracle官方文档
1、简单资源计划以SYS_GROUP组作为level 1,OTHER_GROUPS组作为level 3, 不需要单独创建组(CREATE_CONSUMER_GROUP)和计划指令( CREATE_RESOURCE_PLAN_DIRECTIVES )
Consumer Group Level 1 Level 2 Level 3
SYS_GROUP 100% - -
mailgrp - 80% -
mgrgrp - 20% -
OTHER_GROUPS - - 100%

2、如果要指定用户的默认组(DBA_USERS.INITIAL_RSRC_CONSUMER_GROUP),dba用户必须调用DBMS_RESOURCE_MANAGER_PRIVS.GRANT_SWITCH_CONSUMER_GROUP为指定用户赋于切换到指定组的权限。

 
  
演示示例

 

SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE    10.2.0.1.0      Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SQL> --1.创建简单资源计划
SQL> BEGIN
2  DBMS_RESOURCE_MANAGER.CREATE_SIMPLE_PLAN(SIMPLE_PLAN => 'simple_plan1',
3     CONSUMER_GROUP1 => 'mailgrp', GROUP1_CPU => 80,
4     CONSUMER_GROUP2 => 'mgrgrp', GROUP2_CPU => 20);
5  END;
6  /
PL/SQL 过程已成功完成。
SQL> --2.为组和用户指定映射规则
SQL> BEGIN
2  DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA();
3  DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING
4       (DBMS_RESOURCE_MANAGER.ORACLE_USER, 'mail', 'mailgrp');
5  DBMS_RESOURCE_MANAGER.SET_CONSUMER_GROUP_MAPPING
6       (DBMS_RESOURCE_MANAGER.ORACLE_USER, 'mgr', 'mgrgrp');
7  END;
8  /
PL/SQL 过程已成功完成。
SQL> --3.提交变更
SQL> BEGIN
2  DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
3  END;
4  /
PL/SQL 过程已成功完成。
SQL> set linesize 200
SQL> COL PLAN FOR A20;
SQL> COL CPU_METHOD FOR A20;
SQL> COL STATUS FOR A10;
SQL> COL MANDATORY FOR A10;
SQL> COL COMMENTS FOR A50;
SQL> SELECT  T.PLAN,T.CPU_METHOD,T.STATUS,T.MANDATORY,T.COMMENTS  FROM DBA_RSRC_PLANS T;
PLAN                 CPU_METHOD           STATUS     MANDATORY  COMMENTS
-------------------- -------------------- ---------- ---------- --------------------------------------------------
SIMPLE_PLAN1         EMPHASIS                        NO         Simple plan
INTERNAL_PLAN        EMPHASIS                        YES        Default Plan
INTERNAL_QUIESCE     EMPHASIS                        YES        Plan to internally quiesce system
SYSTEM_PLAN          EMPHASIS                        NO         Plan to give system sessions priority
SQL> COL PLAN FOR A20;
SQL> COL GROUP_OR_SUBPLAN FOR A20;
SQL> COL TYPE FOR A20;
SQL> COL CPU_P1 FOR 99999
SQL> COL CPU_P2 FOR 99999
SQL> COL CPU_P3 FOR 99999
SQL> COL MANDATORY FOR A10;
SQL> COL COMMENTS FOR A50;
SQL> SELECT T.PLAN,T.GROUP_OR_SUBPLAN,T.TYPE,T.CPU_P1,T.CPU_P2,T.CPU_P3 ,T.MANDATORY,T.COMMENTS
2  FROM DBA_RSRC_PLAN_DIRECTIVES  T WHERE T.PLAN='SIMPLE_PLAN1';
PLAN                 GROUP_OR_SUBPLAN     TYPE                 CPU_P1 CPU_P2 CPU_P3 MANDATORY  COMMENTS
-------------------- -------------------- -------------------- ------ ------ ------ ---------- --------------------------
SIMPLE_PLAN1         MAILGRP              CONSUMER_GROUP            0     80      0 NO         Level 2 Group 1
SIMPLE_PLAN1         SYS_GROUP            CONSUMER_GROUP          100      0      0 NO         SYS Level 1
SIMPLE_PLAN1         OTHER_GROUPS         CONSUMER_GROUP            0      0    100 NO         OTHER_GROUPS Level 3
SIMPLE_PLAN1         MGRGRP               CONSUMER_GROUP            0     20      0 NO         Level 2 Group 2
SQL> COL ATTRIBUTE FOR A20
SQL> COL VALUE FOR A20
SQL> COL CONSUMER_GROUP FOR A20
SQL> COL STATUS FOR A20
SQL> SELECT * FROM DBA_RSRC_GROUP_MAPPINGS;
ATTRIBUTE            VALUE                CONSUMER_GROUP       STATUS
-------------------- -------------------- -------------------- --------------------
ORACLE_USER          MAIL                 MAILGRP
ORACLE_USER          MGR                  MGRGRP
ORACLE_USER          SYS                  SYS_GROUP
ORACLE_USER          SYSTEM               SYS_GROUP
SQL> COL CONSUMER_GROUP FOR A25
SQL> COL CPU_METHOD FOR A20
SQL> COL STATUS FOR A10
SQL> COL MANDATORY FOR A10
SQL> COL COMMENTS FOR A50
SQL> SELECT * FROM DBA_RSRC_CONSUMER_GROUPS;
CONSUMER_GROUP            CPU_METHOD           COMMENTS                                           STATUS     MANDATORY
------------------------- -------------------- -------------------------------------------------- ---------- ----------
MAILGRP                   ROUND-ROBIN          Level 2 Group 1                                            NO
MGRGRP                    ROUND-ROBIN          Level 2 Group 2                                            NO
OTHER_GROUPS              ROUND-ROBIN          consumer group for users not included in any group         YES
in the active top-plan
DEFAULT_CONSUMER_GROUP    ROUND-ROBIN          consumer group for users not assigned to any group         YES
SYS_GROUP                 ROUND-ROBIN          Group of system sessions                                   YES
LOW_GROUP                 ROUND-ROBIN          Group of low priority sessions                             NO
AUTO_TASK_CONSUMER_GROUP  ROUND-ROBIN          System maintenance task consumer group                     NO
已选择7行。
SQL> --4.开启simple_plan1资源计划
SQL> ALTER SYSTEM SET RESOURCE_MANAGER_PLAN='SIMPLE_PLAN1';
系统已更改。
SQL> --访问该视图查看活动的资源计划
SQL> SELECT * FROM V$RSRC_PLAN;
ID NAME                             IS_TO
---------- -------------------------------- -----
66146 SIMPLE_PLAN1                     TRUE
SQL> --这个时候INITIAL_RSRC_CONSUMER_GROUP显示了初始的组,但实际上并不会被应用,必须赋权才行
SQL> SELECT T.USERNAME,T.INITIAL_RSRC_CONSUMER_GROUP  FROM DBA_USERS T
2  WHERE T.USERNAME IN('MAIL','MGR');
USERNAME                       INITIAL_RSRC_CONSUMER_GROUP
------------------------------ ------------------------------
MGR                            MGRGRP
MAIL                           MAILGRP
SQL> SELECT T.SID,T.SERIAL#,T.USERNAME,T.RESOURCE_CONSUMER_GROUP FROM V$SESSION T
2  WHERE T.USERNAME  IN('MAIL','MGR');
SID    SERIAL# USERNAME                       RESOURCE_CONSUMER_GROUP
---------- ---------- ------------------------------ --------------------------------
133          5 MGR                            OTHER_GROUPS
135         32 MGR                            OTHER_GROUPS
SQL> --5.为指定用户赋于切换到指定组的权限,使该用户可以使用组
SQL> BEGIN
2   DBMS_RESOURCE_MANAGER_PRIVS.GRANT_SWITCH_CONSUMER_GROUP ('mail', 'mailgrp', TRUE);
3   DBMS_RESOURCE_MANAGER_PRIVS.GRANT_SWITCH_CONSUMER_GROUP ('mgr', 'mgrgrp', TRUE);
4  END;
5  /
PL/SQL 过程已成功完成。
SQL> --6.在其它会话中,以MAIL用户登录,由以下输出可知,MAILGRP组已被应用。
SQL> SELECT T.SID,T.SERIAL#,T.USERNAME,T.RESOURCE_CONSUMER_GROUP FROM V$SESSION T
2  WHERE T.USERNAME  IN('MAIL','MGR');
SID    SERIAL# USERNAME                       RESOURCE_CONSUMER_GROUP
---------- ---------- ------------------------------ --------------------------------
133          5 MGR                            OTHER_GROUPS
135         32 MGR                            OTHER_GROUPS
137          3 MAIL                           MAILGRP
SQL> SELECT T.SID,T.SERIAL#,T.USERNAME,T.RESOURCE_CONSUMER_GROUP FROM V$SESSION T
2  WHERE T.USERNAME  IN('MAIL','MGR');
SID    SERIAL# USERNAME                       RESOURCE_CONSUMER_GROUP
---------- ---------- ------------------------------ --------------------------------
133          5 MGR                            OTHER_GROUPS
135         32 MGR                            OTHER_GROUPS
137          3 MAIL                           MAILGRP
140         56 MGR                            MGRGRP

 

 

相关视图
DBA_RSRC_CONSUMER_GROUP_PRIVS

USER_RSRC_CONSUMER_GROUP_PRIVS

DBAview lists all resource consumer groups and the users and roles to 

which they have been granted.USERview 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

DBAview lists all users and roles that have been granted Database 

Resource Manager system privileges.USERview lists all the users that are

 granted system privileges for theDBMS_RESOURCE_MANAGERpackage.

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

DBAview contains information about all users of the database. 

Specifically, for the Database Resource Manager, it contains the initial 

resource consumer group for the user.USERview 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 theSYS_GROUPconsumer

 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 viewV$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.


参考:
Using the Database Resource Manager 
http://docs.oracle.com/cd/B19306_01/server.102/b14231/dbrm.htm#i1010776

 

你可能感兴趣的:(oracle,manager,database,resource)