Oracle DB 使用资源管理

 • 创建资源使用者组
• 为使用者组指定CPU 资源分配指令
• 将用户与资源使用者组关联起来
• 激活资源计划
• 在SQL*Plus 中测试
• 停用资源计划

创建一个 APPUSER 使用者组,并将其分配给默认的DEFAULT_PLAN 资源计划。然后,将多个Oracle 用户和主要的操作系统用户映射到资源组。激活该资源计划并测试所进行的分配。
以 SYS 用户身份登录(使用 oracle 口令以 SYSDBA 身份连接),然后通过Oracle Enterprise Manager Database Control 或通过SQL*Plus 执行必要的任务。

1) 使用Oracle Enterprise Manager Database Control,创建一个名为 APPUSER 的资源组。此时,请不要向该组添加用户。
a)  在Oracle Enterprise Manager 中,选择“Server > Consumer Groups(服务器> 使用者组)”(在“Resource Manager(资源管理器)”部分中)。
b) 在“Consumer Groups(使用者组)”页中,单击“Create(创建)”按钮。
c)  输入 APPUSER 作为“Consumer Group(使用者组)”,并确保“Scheduling Policy(调度策略)”已设置为“Round Robin(循环)”。
问题1:ROUND-ROBIN 参数值意味着什么?
可能的答案:ROUND-ROBIN 表示根据活动的资源计划指令,向 APPUSER 使用者组平均分配CPU 资源。

d) 此外,也可单击“Show SQL(显示SQL)”,复查语句,然后单击“Return(返回)”。绑定变量因安全原因而未显示。
 
 
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.create_consumer_group(consumer_group => ?,comment => ? , cpu_mth => ?);
dbms_resource_manager.submit_pending_area();
END;

e)  在“Create Resource Consumer Group(创建资源使用者组)”页上,单击“OK(确定)”创建使用者组。
f)  此时会出现一条确认消息,并显示新的使用者组。确认创建后,单击“数据库实例:test0924”链接。
2) 将 APPUSER 和 LOW_GROUP 使用者组添加到 DEFAULT_PLAN 资源计划。更改级别3 的CPU 资源分配百分比:APPUSER 使用者组改为60%,LOW_GROUP
使用者组改为40%。
a)  在Oracle Enterprise Manager 中,选择“Server > Plans(服务器> 计划)”。
b) 在“Resource Plans(资源计划)”页上,选择 DEFAULT_PLAN 并单击“Edit(编辑)”按钮。
c)  单击“Modify(修改)”。
 
d) 在“Select Groups/Subplans(选择组/子计划)”页上,将 APPUSER 和LOW_GROUP 移至“Resource Allocations(资源分配)”。
e)  单击“OK(确定)”。

f)  在“Level 3(级别3)”下,为 APPUSER 输入 60,为 LOW_GROUP 输入 40。
g) 单击“Show SQL(显示SQL)”。
DECLARE
spfileValue VARCHAR2(1000);
scopeValue VARCHAR2(10) := 'MEMORY';
planName VARCHAR2(100) :=?;
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.create_plan_directive(
plan => ?,
group_or_subplan => ?,
comment => ?,
max_utilization_limit => ?,
mgmt_p1 => ?, mgmt_p2 => ?, mgmt_p3 => ?, mgmt_p4 => ?,
mgmt_p5 => ?, mgmt_p6 => ?, mgmt_p7 => ?, mgmt_p8 => ? ,
parallel_degree_limit_p1 => ? ,
parallel_target_percentage => ? ,
parallel_queue_timeout => ? ,
switch_io_reqs => ? ,
switch_io_megabytes => ? 
,
active_sess_pool_p1 => ?,
queueing_p1 => ?,
switch_group => ?,
switch_time => ?,
switch_estimate => case ? when 'false' then false when 'true' then true else false end,
undo_pool => ? ,
max_idle_time => ?,
max_idle_blocker_time => ?,
switch_for_call => case ? when 'false' then false when 'true' then true else false end

);
dbms_resource_manager.create_plan_directive(
plan => ?,
group_or_subplan => ?,
comment => ?,
max_utilization_limit => ?,
mgmt_p1 => ?, mgmt_p2 => ?, mgmt_p3 => ?, mgmt_p4 => ?,
mgmt_p5 => ?, mgmt_p6 => ?, mgmt_p7 => ?, mgmt_p8 => ? ,
parallel_degree_limit_p1 => ? ,
parallel_target_percentage => ? ,
parallel_queue_timeout => ? ,
switch_io_reqs => ? ,
switch_io_megabytes => ? 
,
active_sess_pool_p1 => ?,
queueing_p1 => ?,
switch_group => ?,
switch_time => ?,
switch_estimate => case ? when 'false' then false when 'true' then true else false end,
undo_pool => ? ,
max_idle_time => ?,
max_idle_blocker_time => ?,
switch_for_call => case ? when 'false' then false when 'true' then true else false end

);
dbms_resource_manager.submit_pending_area();
select value into spfileValue from v$parameter where name = 'spfile';
IF spfileValue IS NOT NULL then
EXECUTE IMMEDIATE 'alter system set resource_manager_plan = '||planName||' scope=BOTH';
END IF;
dbms_resource_manager.switch_plan( plan_name => ? , sid => ? , allow_scheduler_plan_switches => FALSE );
END;
h) 复查代码,然后单击“Return(返回)”。

i)  在“Edit Resource Plan: DEAFULT_PLAN(编辑资源计划: DEAFULT_PLAN)”页上,单击“Apply(应用)”将 APPUSER 和LOW_GROUP 使用者组分配到 DEFAULT_PLAN 资源计划。(稍后激活此计划。)
j)  会收到一条消息,告知更新已成功。
3) 配置“Consumer Group Mappings(使用者组映射)”,使 HR Oracle 用户属于APPUSER 使用者组,并且使 SCOTT 用户属于 LOW_GROUP 使用者组。对于
SCOTT 用户,请确认其 ORACLE_USER 属性的优先级比 CLIENT_OS_USER属性高。
a)  在Oracle Enterprise Manager 中,选择“Server > Consumer Group Mappings(服务器> 使用者组映射)”。
b) 选择“Oracle User(Oracle 用户)”,并单击“Add Rule for Selected Type(为所选类型添加规则)”按钮。
c)  在“Consumer Group Mappings(使用者组映射)”页上,确保 APPUSER 已选为“Selected Consumer Groups(所选使用者组)”。
d) 将 HR 用户移至“Selected Oracle User(所选Oracle 用户)”区域中,然后单击“OK(确定)”。

e)  会收到成功消息。在“Consumer Group Mappings General(使用者组映射一般信息)”页上,单击“Show SQL(显示SQL)”。
f)  复查语句并单击“Return(返回)”。
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.set_consumer_group_mapping(
dbms_resource_manager.oracle_user,
'HR',
'APPUSER'
);
dbms_resource_manager.submit_pending_area();
END;

 
g) 单击“Apply(应用)”,将 HR 用户分配给 APPUSER 使用者组。
h) 再次选择“Oracle User(Oracle 用户)”,并单击“Add Rule for Selected Type(为所选类型添加规则)”按钮。
i)  从“Selected Consumer Groups(所选使用者组)”下拉列表中选择LOW_GROUP,并将 SCOTT 移至“Selected Oracle User(所选Oracle 用户)”区域中,然后单击“OK(确定)”。
j)  会收到成功消息(但此时请勿应用所做的更改)。在“Consumer Group Mappings(使用者组映射)”页上,单击“Priorities(优先级)”选项卡。
k) 确认“Oracle User(Oracle 用户)”的优先级比“Client OS User(客户机操作系统用户)”高。
l)  单击“Apply(应用)”,将 SCOTT 用户分配给 LOW_GROUP 使用者组。会收到成功消息。

4) 配置使用者组映射,以便使 oracle 操作系统用户属于 SYS_GROUP 使用者组。
a)  返回“Consumer Group Mappings - General(使用者组映射- 一般信息)”页。
b) 选择“Client OS User(客户机操作系统用户)”,并单击“Add Rule for Selected Type(为所选类型添加规则)”按钮。
c)  从“Selected Consumer Groups(所选使用者组)”下拉列表中选择SYS_GROUP,将 oracle 移至“Selected Client OS User(所选客户机操作系统用户)”区域中,然后单击“OK(确定)”。会收到成功消息。


d) 可以选择单击“Show SQL(显示SQL)”,复查语句,然后单击“Return(返回)”。
e)  单击“Apply(应用)”,将 oracle 操作系统用户分配给 SYS_GROUP 使用者组。会收到成功消息。
5) 将 PM Oracle 用户分配给以下使用者组:APPUSER、LOW_GROUP 和SYS_GROUP。
a)  在Oracle Enterprise Manager 中,选择“Server > Users(服务器> 用户)”(在“Security(安全)”部分中)。

b) 选择 PM 用户,然后单击“Edit(编辑)”按钮。
c)  单击“Consumer Groups Privileges(使用者组权限)”选项卡。如果出现有关 PM 用户口令的错误,请在两个口令字段中均输入 pm。
d) 单击“Edit List(编辑列表)”按钮。
e)  将 APPUSER、LOW_GROUP 和 SYS_GROUP 使用者组移至“Selected Consumer Groups(所选使用者组)”,然后单击“OK(确定)”。
f)  单击“Show SQL(显示SQL)”。
g) 复查语句并单击“Return(返回)”。
h) 单击“Apply(应用)”,将 PM 用户分配给这些使用者组。会收到成功消息。
6) 激活 DEFAULT_PLAN 资源计划。
a)  在Oracle Enterprise Manager 中,选择“Server > Plans(服务器> 计划)”。
b) 在“Resource Plans(资源计划)”页中选择 DEFAULT_PLAN,从“Actions(操作)”下拉列表中选择“Activate(激活)”,然后单击“Go(执行)”。
c)  单击“Yes(是)”以确认激活。
会看到成功消息。

7) 检测使用者组映射。启动两个SQL*Plus 会话,第一个使用system/oracle连接字符串,第二个使用scott/tiger连接字符串。
sys@TEST0924> conn system/oracle
Connected.

sys@TEST0924> conn scott/tiger
Connected.
a) 确定ORACLE_SID
b) 要使用 system/oracle连接字符串启动SQL*Plus 会话并将SQL 提示设置为“FIRST”,请输入:
sys@TEST0924> conn system/oracle
Connected.
system@TEST0924> set sqlprompt "FIRST>"
FIRST>
c)  确定ORACLE_SID
d) 要使用 scott/tiger 连接字符串启动SQL*Plus 会话并将SQL 提示设置为“SECOND”,请输入:
sys@TEST0924> conn scott/tiger
Connected.
scott@TEST0924>  set sqlprompt "SECOND>"
SECOND>
首先查看query_rsc_groups.sql
[oracle@rtest labs]$ cat /home/oracle/labs/query_rsc_groups.sql
-- Oracle Database 10g: Administration Workshop II
-- Oracle Server Technologies - Curriculum Development
-- 
-- ***Training purposes only***
-- ***Not appropriate for production use***
-- 
-- Start a SQL*Plus session as system/oracle@orcl
-- Start a second SQL*Plus session to view information about

SELECT schemaname, resource_consumer_group
FROM V$SESSION
WHERE schemaname not like 'SYS%'
/
e)  在 FIRSTSQL*Plus 会话中,输入:
FIRST>@/home/oracle/labs/query_rsc_groups.sql

SCHEMANAME                     RESOURCE_CONSUMER_GROUP
------------------------------ --------------------------------
DBSNMP                         OTHER_GROUPS
DBSNMP                         OTHER_GROUPS
SCOTT                          LOW_GROUP
DBSNMP                         OTHER_GROUPS
DBSNMP                         _ORACLE_BACKGROUND_GROUP_

f)  问题:SCOTT 用户属于哪一个使用者组?
答案:SCOTT 属于 LOW_GROUP 使用者组。
注:在执行本步骤(和后续步骤)后得到的输出结果可能与此处显示的输出结果不同。此处的相关信息只针对提到的特定用户。
g) 在 SECOND 终端窗口中,以 PM 用户身份进行连接(使用 pm 作为口令):
SECOND>conn pm/pm
Connected.
pm@TEST0924> set sqlprompt "SECOND>"
SECOND>
h) 在 FIRSTSQL*Plus 会话中,输入“/”再次执行之前的SQL 语句。
FIRST>/

SCHEMANAME                     RESOURCE_CONSUMER_GROUP
------------------------------ --------------------------------
DBSNMP                         OTHER_GROUPS
DBSNMP                         OTHER_GROUPS
PM                             SYS_GROUP
DBSNMP                         OTHER_GROUPS
DBSNMP                         _ORACLE_BACKGROUND_GROUP_
i)  问题:PM 用户属于哪一个使用者组?
答案:PM 属于 SYS_GROUP 使用者组。
j)  在 SECOND 终端窗口中,以 OE 用户身份进行连接(使用 oe 作为口令):
SECOND>conn oe/oe
Connected.
oe@TEST0924> set sqlprompt "SECOND>"
SECOND>
k) 在 FIRSTSQL*Plus 会话中,输入“/”再次执行之前的SQL 语句。
FIRST>/

SCHEMANAME                     RESOURCE_CONSUMER_GROUP
------------------------------ --------------------------------
DBSNMP                         OTHER_GROUPS
DBSNMP                         OTHER_GROUPS
OE                             OTHER_GROUPS
DBSNMP                         OTHER_GROUPS
DBSNMP                         _ORACLE_BACKGROUND_GROUP_

l)  退出这两个SQL*Plus 会话。
m) 问题:测试 OEOracle 用户时,您会发现 OE 属于 OTHER_GROUPS 使用者组。
为什么会这样?
可能的答案:未明确将 OE 用户分配给另一个使用者资源组。
8) 还原为原始配置的方法是停用 DEFAULT_PLAN 资源组,锁定帐户,撤消所有使用者组映射,最后删除 APPUSER 资源组。
a)  要在Oracle Enterprise Manager 中停用 DEFAULT_PLAN 资源计划,请选择“Server > Plans(服务器> 计划)”。
b) 在“Resource Plans(资源计划)”页中选择 DEFAULT_PLAN,从“Actions
(操作)”下拉列表中选择“Deactivate(停用)”,然后单击“Go(执行)”。
c)  单击“Yes(是)”以确认停用。
会收到成功消息。

d) 要重新配置或撤消所有使用者组映射,请复查并执行工作目录中的
rsc_cleanup.sh 脚本:
[oracle@rtest labs]$ cat rsc_cleanup.sh 
# Oracle Database 11g: Administration Workshop II
# Oracle Server Technologies - Curriculum Development
#
# ***Training purposes only***
# ***Not appropriate for production use***
#
# This script supports the Resource Manager practice session.
#   Start this script connected as OS user: oracle.

sqlplus "/ as sysdba" << EOF


PROMPT undo lab step 5

BEGIN
    dbms_resource_manager_privs.revoke_switch_consumer_group(
        revokee_name => 'PM',
        consumer_group => 'APPUSER'
    );
END;
/
BEGIN
    dbms_resource_manager_privs.revoke_switch_consumer_group(
        revokee_name => 'PM',
        consumer_group => 'LOW_GROUP'
    );
END;
/
BEGIN
    dbms_resource_manager_privs.revoke_switch_consumer_group(
        revokee_name => 'PM',
        consumer_group => 'SYS_GROUP'
    );
END;
/
PROMPT undo lab step 4

BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.set_consumer_group_mapping(
    dbms_resource_manager.client_os_user,
    'ORACLE',
    NULL
);
dbms_resource_manager.submit_pending_area();
END;
/
PROMPT  undo lab step 3

BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.set_consumer_group_mapping(
    dbms_resource_manager.oracle_user,
    'HR',
    NULL
);
dbms_resource_manager.set_consumer_group_mapping(
    dbms_resource_manager.oracle_user,
    'SCOTT',
    NULL
);
dbms_resource_manager.set_consumer_group_mapping(
    dbms_resource_manager.oracle_user,
    'SYS',
    NULL
);
dbms_resource_manager.set_consumer_group_mapping(
    dbms_resource_manager.oracle_user,
    'SYSTEM',
    NULL
);
dbms_resource_manager.submit_pending_area();
END;
/
PROMPT  undo lab step 2

BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.delete_plan_directive('DEFAULT_PLAN', 'APPUSER');
dbms_resource_manager.delete_plan_directive('DEFAULT_PLAN', 'LOW_GROUP');
dbms_resource_manager.submit_pending_area();
dbms_resource_manager.switch_plan( plan_name => '', sid => 'orcl', allow_scheduler_plan_switches => FALSE );
END;
/
exit
EOF

[oracle@rtest labs]$ ./rsc_cleanup.sh 

SQL*Plus: Release 11.2.0.3.0 Production on Sat Oct 26 12:53:30 2013

Copyright (c) 1982, 2011, Oracle.  All rights reserved.


Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options

SQL> SQL> SQL> undo lab step 5
SQL> SQL>   2    3    4    5    6    7  
PL/SQL procedure successfully completed.

SQL>   2    3    4    5    6    7  
PL/SQL procedure successfully completed.

SQL>   2    3    4    5    6    7  
PL/SQL procedure successfully completed.

SQL> undo lab step 4
SQL> SQL>   2    3    4    5    6    7    8    9   10   11  
PL/SQL procedure successfully completed.

SQL> undo lab step 3
SQL> SQL>   2    3    4    5    6    7    8    9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26  
PL/SQL procedure successfully completed.

SQL> undo lab step 2
SQL> SQL>   2    3    4    5    6    7    8    9  
PL/SQL procedure successfully completed.

SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Automatic Storage Management, OLAP, Data Mining
and Real Application Testing options
e)  要删除 APPUSER 资源组,请在Oracle Enterprise Manager 中选择“Server > Consumer Groups(服务器> 使用者组)”。
f)  在“Consumer Groups(使用者组)”页中,选择 APPUSER 并单击“Delete(删除)”按钮。
g) 单击“Yes(是)”以确认删除。会收到成功消息。
h) 退出Oracle Enterprise Manager 并关闭所有终端窗口
原文地址:https://www.cnblogs.com/hzcya1995/p/13316754.html