`

Oracle DBMS_RESOURCE_MANAGER 用法例子

阅读更多

General

Note: Resource Manager requires a massive over-demand on CPU before the expected behavior starts to show: Generally speaking a 300% or 400% CPU load to see that the actual split gets closer to expectation, with the lower-privileged processes losing time in a wait state whose name includes 'resmgr: ....{something}..'

Source

{ORACLE_HOME}/rdbms/admin/dbmsrmad.sql

First Available

8.1.5


Consumer Group Mapping Constants

Name

Data Type

Value

client_machine

VARCHAR2(30)

'CLIENT_MACHINE'

client_os_user

VARCHAR2(30)

'CLIENT_OS_USER'

client_program

VARCHAR2(30)

'CLIENT_PROGRAM'

module_name

VARCHAR2(30)

'MODULE_NAME'

module_name_action

VARCHAR2(30)

'MODULE_NAME_ACTION'

oracle_user

VARCHAR2(30)

'ORACLE_USER'

performance_class

VARCHAR2(30)

'PERFORMANCE_CLASS'

service_module

VARCHAR2(30)

'SERVICE_MODULE'

service_module_action

VARCHAR2(30)

'SERVICE_MODULE_ACTION'

service_name

VARCHAR2(30)

'SERVICE_NAME'

 


Consumer Group Mapping Constants

Name

Data Type

Value

client_machine

VARCHAR2(30)

'CLIENT_MACHINE'

client_os_user

VARCHAR2(30)

'CLIENT_OS_USER'

client_program

VARCHAR2(30)

'CLIENT_PROGRAM'

module_name

VARCHAR2(30)

'MODULE_NAME'

module_name_action

VARCHAR2(30)

'MODULE_NAME_ACTION'

oracle_user

VARCHAR2(30)

'ORACLE_USER'

service_module

VARCHAR2(30)

'SERVICE_MODULE'

service_module_action

VARCHAR2(30)

'SERVICE_MODULE_ACTION'

service_name

VARCHAR2(30)

'SERVICE_NAME'

 

CLEAR_PENDING_AREA

Clears the work area for the resource manager

dbms_resource_manager.clear_pending_area;

exec dbms_resource_manager.clear_pending_area ;

CREATE_PENDING_AREA

Creates a work area for changes to resource manager objects

dbms_resource_manager.create_pending_area;

See Demo

DELETE_CONSUMER_GROUP

Delete entries that define resource consumer groups

dbms_resource_manager.delete_consumer_group(consumer_group IN VARCHAR2);

See Demo

 

DELETE_PLAN

Deletes the specified plan as well as all the plan directives to which it refers

dbms_resource_manager.delete_plan(plan IN VARCHAR2);

exec dbms_resource_manager.delete_plan ('UW_PLAN');

 

DELETE_PLAN_CASCADE

Deletes the specified plan as well as well as its descendants (plan directives, subplans, consumer groups)

dbms_resource_manager.delete_plan_cascade(plan IN VARCHAR2);

See Demo

 

DELETE_PLAN_DIRECTIVE

Delete resource plan directives

dbms_resource_manager.delete_plan_directive(
plan             IN VARCHAR2,
group_or_subplan IN VARCHAR2);

See Demo

 

SET_CONSUMER_GROUP_MAPPING

Adds, deletes, or modifies entries that map sessions to consumer groups, based on the session's login and runtime attributes

dbms_resource_manager.set_consumer_group_mapping(
attribute      IN VARCHAR2,
value          IN VARCHAR2,
consumer_group IN VARCHAR2 DEFAULT NULL);

TBD

 

SET_CONSUMER_GROUP_MAPPING_PRI


Creates the session attribute mapping priority list

The highest priority is 1, the lowest 10 (the docs are incorrect)

dbms_resource_manager.set_consumer_group_mapping_pri(
explicit              IN NUMBER,
oracle_user           IN NUMBER,
service_name          IN NUMBER,
client_os_user        IN NUMBER,
client_program        IN NUMBER,
client_machine        IN NUMBER,
module_name           IN NUMBER,
module_name_action    IN NUMBER,
service_module        IN NUMBER,
service_module_action IN NUMBER);

desc dba_rsrc_mapping_priority

SELECT *
FROM dba_rsrc_mapping_priority;

exec dbms_resource_manager.create_pending_area ;

exec dbms_resource_manager.set_consumer_group_mapping_pri(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

exec dbms_resource_manager.validate_pending_area ;

exec dbms_resource_manager.submit_pending_area ;

SELECT *
FROM dba_rsrc_mapping_priority;

exec dbms_resource_manager.create_pending_area ;

exec dbms_resource_manager.set_consumer_group_mapping_pri(1, 7, 6, 9, 8, 10, 5, 4, 3, 2);

exec dbms_resource_manager.validate_pending_area ;

exec dbms_resource_manager.submit_pending_area ;

 

SET_INITIAL_CONSUMER_GROUP

Assigns the initial resource consumer group for a user: Obsolete

dbms_resource_manager.set_initial_consumer_group(
user           IN VARCHAR2,
consumer_group IN VARCHAR2);

Deprecated

 

SUBMIT_PENDING_AREA

Submits pending changes for the resource manager

dbms_resource_manager.submit_pending_area;

See Demo

 

SWITCH_CONSUMER_GROUP_FOR_SESS


Changes the resource consumer group of a specific session

dbms_resource_manager.switch_consumer_group_for_sess(
session_id     IN NUMBER,
session_serial IN NUMBER,
consumer_group IN VARCHAR2);

SELECT username, initial_rsrc_consumer_group
FROM dba_users
ORDER BY 1;

col schemaname format a15
col program format a20

SELECT sid, serial#, schemaname, osuser, program
FROM gv$session
WHERE service_name NOT LIKE '%BACK%';

exec dbms_resource_manager.switch_consumer_group_for_sess (147, 1883, 'SYS_GROUP');

SELECT username, initial_rsrc_consumer_group
FROM dba_users
ORDER BY 1;

exec dbms_resource_manager.switch_consumer_group_for_sess (147, 1883, 'DEFAULT_CONSUMER_GROUP');

 

SWITCH_CONSUMER_GROUP_FOR_USER

Changes the resource consumer group for all sessions with a given user name

dbms_resource_manager.switch_consumer_group_for_user(
user           IN VARCHAR2,
consumer_group IN VARCHAR2);

exec dbms_resource_manager.switch_consumer_group_for_user (
'UWCLASS', 'rpt_writers_grp');

 

SWITCH_PLAN

Sets the current resource manager plan

dbms_resource_manager.switch_plan(
plan_name                     IN VARCHAR2,
sid                           IN VARCHAR2 DEFAULT '*',
allow_scheduler_plan_switches IN BOOLEAN DEFAULT TRUE);

TBD

VALIDATE_PENDING_AREA

Validates pending changes for the resource manager

dbms_resource_manager.validate_pending_area;

See Demo

 

Demos


Create Plan 1 Demonstration

conn / as sysdba

desc dba_users

SELECT username, initial_rsrc_consumer_group
FROM dba_users
ORDER BY 1;

GRANT select ON dba_rsrc_consumer_groups TO uwclass;

-- create pointy-haired boss user
CREATE USER phb
IDENTIFIED BY phb
DEFAULT TABLESPACE uwdata
TEMPORARY TABLESPACE temp
QUOTA 1M ON uwdata;

GRANT create session TO phb;

SELECT username, initial_rsrc_consumer_group
FROM dba_users
ORDER BY 1;

desc dba_rsrc_consumer_group_privs

SELECT *
FROM dba_rsrc_consumer_group_privs;

set linesize 121
col plan format a30
col cpu_method format a10
col comments format a60

desc dba_rsrc_plans

SELECT plan, cpu_method, comments, mandatory
FROM dba_rsrc_plans;

col cpu_method format a15
col consumer_group format a25
col comments format a45

desc dba_rsrc_consumer_groups

SELECT *
FROM dba_rsrc_consumer_groups;

col value format a20

desc dba_rsrc_group_mappings

SELECT *
FROM dba_rsrc_group_mappings;

exec dbms_resource_manager_privs.grant_system_privilege ('UWCLASS', 'ADMINISTER_RESOURCE_MANAGER', FALSE);

conn uwclass/uwclass

-- create a pending area
exec dbms_resource_manager.create_pending_area ;

-- create two consumer groups: Workers and Managers
exec dbms_resource_manager.create_consumer_group ('Workers', 'Those that do actual work');

exec dbms_resource_manager.create_consumer_group ('Managers', 'Those that don''t but take all the credit');

SELECT *
FROM dba_rsrc_consumer_groups;

exec dbms_resource_manager.update_consumer_group ('Managers', 'The Cartesian products of the IT world');

SELECT *
FROM dba_rsrc_consumer_groups;

-- create resource management plan
exec dbms_resource_manager.create_plan ('UW_PLAN','Demo Resource Plan', 'RATIO');

-- create plan directives
exec dbms_resource_manager.create_plan_directive (plan=>'UW_PLAN', group_or_subplan=>'Workers', comment=>'Can Grab All The CPU', cpu_p1=>100);

exec dbms_resource_manager.create_plan_directive (plan=>'UW_PLAN', group_or_subplan=>'Managers', comment=>'Give Managers Little Weight', cpu_p1=>1);

-- validate the pending area
exec dbms_resource_manager.validate_pending_area ;

exec dbms_resource_manager.create_plan_directive (plan=>'UW_PLAN', group_or_subplan=>'OTHER_GROUPS', comment=>'Testing', cpu_p2=>0);

-- validate the pending area
exec dbms_resource_manager.validate_pending_area ;

-- oops ... go back and redo correctly
-- delete plan directives
exec dbms_resource_manager.delete_plan_directive ('UW_PLAN', 'Managers');

-- recreate plan directives
exec dbms_resource_manager.create_plan_directive (plan=>'UW_PLAN', group_or_subplan=>'Managers', comment=>'Infinite Weight', cpu_p1=>0);

-- revalidate the pending area
exec dbms_resource_manager.validate_pending_area ;

-- submit the pending area
exec dbms_resource_manager.submit_pending_area ;

SELECT plan, cpu_method, comments, status, mandatory
FROM dba_rsrc_plans;

SELECT *
FROM dba_rsrc_consumer_groups;

exec dbms_resource_manager_privs.grant_switch_consumer_group ( grantee_name=>'PHB', consumer_group=>'Managers', grant_option=>FALSE);

exec dbms_resource_manager.set_initial_consumer_group (user => 'SCHEDULE', consumer_group=>'Managers');

alter system set resource_manager_plan = 'UW_PLAN';

conn schedule/schedule

/* So PHB is in a group that should have no CPU. Does this
mean PHB can't do anything?
*/


SELECT COUNT(*) FROM all_tables;

/* PHB is fine. There's plenty of free CPU so even though the group
that PHB group belongs to "looks" like it should have no CPU, that doesn't have any effect in this case.
*/


Create Plan 2 Demonstration

/*
Resource Manager is only effective (from a CPU point of view)
once CPU utilization starts to max out. Oracle takes the attitude
that if there is spare CPU capacity, there is no need to limit
usage. Only when the resource becomes scarce does Oracle restrict
access.
*/


BEGIN
-- create pending area
dbms_resource_manager.create_pending_area ;

dbms_resource_manager.create_plan (plan=>'TEST2',
comment=>'Use 10g Feature');

dbms_resource_manager.create_plan_directive (plan=>'TEST2',
group_or_subplan=>'HAVES', comment=>'Testing', cpu_p1=>100);

dbms_resource_manager.create_plan_directive (plan=>'TEST2',
group_or_subplan=>'NOTS', comment=>'Testing', cpu_p1=>0,
max_est_exec_time=>0);

/*
Prevent the have Managers from running any operation that has
an estimated execution time > 0.
*/


dbms_resource_manager.create_plan_directive (plan=>'TEST2',
group_or_subplan=>'OTHER_GROUPS', comment=>'Testing', cpu_p2=>100);

dbms_resource_manager.validate_pending_area ;

dbms_resource_manager.submit_pending_area ;

dbms_resource_manager_privs.grant_switch_consumer_group (
grantee_name=>'PHB', consumer_group=>'Managers',
grant_option=>FALSE);

dbms_resource_manager.set_initial_consumer_group
(user =>
'SCHEDULE', consumer_group=>'Managers');
END;
/

ALTER SYSTEM SET resource_manager_plan = test2;

conn schedule/schedule

SELECT COUNT(*) FROM huge_table;

ERROR at line 1:
ORA-07455: estimated execution time (56 secs), exceeds limit (0 secs)

/*
However, the problem here is that Oracle kinda rounds *down* the
estimate execution time so providing I'm not being too greedy with my resources, Oracle can be a little lenient ...
*/

SELECT COUNT(*) FROM small_table;


Drop Plan Demonstration

conn / as sysdba

-- create pending area

exec dbms_resource_manager.create_pending_area ;

-- remove admin privilege from uwclass
exec dbms_resource_manager_privs.revoke_system_privilege ( 'UWCLASS', 'ADMINISTER_RESOURCE_MANAGER');

-- delete resource plan
exec dbms_resource_manager.delete_plan_cascade ('UW_PLAN');

-- validate pending area
exec dbms_resource_manager.validate_pending_area ;

SELECT username, initial_rsrc_consumer_group
FROM dba_users
ORDER BY 1;

-- switch consumer group for user SCHEDULES
exec dbms_resource_manager.switch_consumer_group_for_user ( 'SCHEDULE', 'DEFAULT_CONSUMER_GROUP');

BEGIN
dbms_resource_manager.create_pending_area ;
dbms_resource_manager.delete_plan_cascade ('UW_PLAN');
dbms_resource_manager.validate_pending_area ;
END;
/

-- submit pending area
exec dbms_resource_manager.submit_pending_area ;

-- revoke system privilege from user
exec dbms_resource_manager_privs.revoke_system_privilege ('UWCLASS');

 

参考至:http://hi.baidu.com/edeed/blog/item/33c6b901c36b3a07728da521.html

如有错误,欢迎指正

邮箱:czmcj@163.com

 

分享到:
评论

相关推荐

    使用resource Manager对数据库资源再分配.doc

    【使用Resource Manager对数据库资源再分配】 在Oracle数据库管理中,Resource Manager是一个强大的工具,用于控制和优化数据库资源的分配,以确保不同类型的数据库工作负载得到适当的服务水平。Resource Manager...

    oracle系统内置包

    此外,Oracle还提供了DBMS_RESOURCE_MANAGER_PRIVS包来进行权限维护,确保只有授权用户才能执行特定的操作。 总之,Oracle的系统内置包提供了丰富的功能,涵盖数据库管理的各个方面。掌握这些包的使用,可以帮助...

    Oracle运维最佳实践-下.pdf 带书签

    - 使用`DBMS_RESOURCE_MANAGER`来管理会话资源。 - 设置`OPEN_CURSORS`和`SESSIONS`参数来控制会话数量。 - **2.1.14 DBMS_ADVANCED_REWRITE** - `DBMS_ADVANCED_REWRITE`是Oracle提供的一个用于优化查询重写的...

    Oracle_DBA_Automation_Quick_Reference.rar

    使用Oracle Enterprise Manager或脚本,可以自动化用户管理、权限分配、审计策略设置等安全任务,以增强数据库安全。 综上所述,《Oracle DBA Automation Quick Reference》可能包含了这些关键领域的实用技巧和...

    Oracle rac功能测试方案

    - 使用`dbms_resource_manager`包中的`CALIBRATE_IO`函数来测试I/O性能。 - 执行以下SQL语句: ```sql SQL> set timing on SQL> set serveroutput on SQL> declare v_max_iops BINARY_INTEGER; v_max_mbps ...

    oracle 10g administration workshop ii labs

    10. **数据库性能监控与资源管理**:通过PGA(Program Global Area)和SGA(System Global Area)管理,以及数据库资源调度器(DBMS_RESOURCE_MANAGER)来优化系统资源的分配。 通过Oracle 10g Administration ...

    sql面试题\oracle面试题目

    - **Database Resource Manager**:资源管理。 - **Database Replay**:性能诊断工具。 - **Real Application Clusters (RAC)**:高可用性。 #### 64. 查询表中一个FID对应多个不同的FNO的记录 - 使用`GROUP BY FID...

    Expert.Oracle.Database.11g.Administration

    10. **数据库性能调优**:探讨pga_aggregate_target、sga_target等内存参数的调整,以及DBMS_XPLAN、DBMS_RESOURCE_MANAGER包的使用来优化系统性能。 11. **数据库升级与迁移**:了解从早期版本升级到Oracle 11g的...

    Oracle性能优化方法(SQL篇)

    10. **资源管理**:通过DBMS_RESOURCE_MANAGER,可以对系统资源进行分配,设置不同用户的CPU和I/O配额,确保关键任务得到优先处理。 以上这些方法是Oracle SQL性能优化的核心内容,实践中需要根据具体情况灵活应用...

    oracle学习整理

    5. **资源管理**:通过DBMS_RESOURCE_MANAGER分配CPU和I/O资源,实现多用户环境下的公平调度。 通过深入学习Oracle函数、解决常见问题和进行性能调优,开发者和DBA能够更好地管理和利用Oracle数据库,提升系统的...

    oracle ocp 11g 题库中文版

    Oracle数据库的资源管理器(Resource Manager)是用于控制数据库资源使用的组件,它通过定义资源计划来控制用户会话可以使用的系统资源,例如CPU、并行查询服务器、I/O等。 在设置作业参数时,特别是那些不能隐式...

    Oracle数据库实验报告

    - **使用方法**:`SET @varname = value;` 或 `&varname`。 #### 五、扩展UPDATE(RETURNING) - **用途**:更新操作后立即返回受影响行的新值。 - **SQL语句**示例: ```sql UPDATE table_name SET column_name ...

    Oracle性能优化技术内幕.rar

    例如,使用DBMS_RESOURCE_MANAGER进行CPU和I/O的分配。 6. 并发控制:Oracle的多版本并发控制(MVCC)机制,如读已提交和串行化隔离级别,以及锁管理,都需要合理设置以平衡并发性和一致性。 7. 日志和归档策略:...

    oracle系统自带角色说明

    在Oracle数据库中,为了方便用户管理和使用权限,系统预定义了一系列的角色,这些角色包含了特定的权限组合,可以帮助管理员快速地为不同的用户分配合适的访问权限。本文将详细介绍Oracle系统中自带的一些关键角色...

    OCP 11G 题库053补充题库

    - **资源管理**:掌握如何使用Oracle Resource Manager来限制用户会话和应用程序的资源消耗。 - **使用调度程序**:学习如何使用Oracle Scheduler来自动化任务执行,包括作业、窗口和程序的概念。 - **全球化支持**...

    oracle 优化

    10. **资源管理**:在Oracle 10.2版本中,可以使用资源计划(DBMS_RESOURCE_MANAGER)来分配不同用户或工作负载的系统资源,确保关键业务的优先级。 优化过程需要持续监控和调整,通过`EXPLAIN PLAN`、`DBMS_XPLAN`...

    Oracle 11g OCP 051/052 题库

    5. **数据库资源管理**:理解DBMS_RESOURCE_MANAGER的使用,实施数据库资源调度和限制。 6. **数据泵导入导出**:学习如何使用Data Pump进行大规模数据迁移和复制。 通过Oracle.Lead2Pass.1Z0-052.v2012-09-03.by....

    oracle日常维护

    使用Resource Manager来控制不同用户的资源使用。 以上内容涵盖了Oracle数据库日常维护的基本要点,但实际操作中,DBA还需要根据具体的业务环境和需求,灵活应用和调整这些策略。Oracle日常维护手册中将详细阐述...

    Oracle 10G的使用教程

    2. **资源管理**:通过ASM(Automatic Storage Management)进行存储管理,通过DBMS_RESOURCE_MANAGER调整资源分配。 3. **安全性**:用户权限管理、角色、审计、加密等,确保数据安全。 4. **数据库优化**:索引...

Global site tag (gtag.js) - Google Analytics