ACE Director Alum Daniel Morgan, founder of Morgan's Library, is scheduling
complimentary technical Workshops on Database Security for the first 30
Oracle Database customers located anywhere in North America, EMEA, LATAM, or
APAC that send an email to
asra_us@oracle.com. Request a Workshop for
your organization today.
Purpose
Maintains plans, consumer groups, and plan directives that control and limit CPU and I/O resource allocation between PDBs and User Consumer Groups.
It also provides semantics so that you may group together changes to the plan schema.
You may note in the Oracle docs the phrase "It can only be called when consolidation is enabled." This is jargon that translates into English as "you have a CDB."
Note: Depending on database size or available disk this may take a very long time
dbms_resource_manager.calibrate_io(
num_physical_disks IN PLS_INTEGER DEFAULT 1,
max_latency IN PLS_INTEGER DEFAULT 20,
max_iops OUT PLS_INTEGER,
max_mbps OUT PLS_INTEGER,
actual_latency OUT PLS_INTEGER);
conn / as sysdba
SELECT pname, pval1
FROM aux_stats$
WHERE sname = 'SYSSTATS_MAIN';
col name format a50
SELECT name, asynch_io
FROM gv$datafile f, gv$iostat_file i
WHERE f.file# = i.file_no
AND filetype_name = 'Data File';
-- asynch io must be configured
SELECT name, value
FROM gv$parameter
WHERE name = 'filesystemio_options';
ALTER SYSTEM SET filesystemio_options = 'SETALL' SCOPE=SPFILE;
ALTER SYSTEM SET filesystemio_options = 'NONE' SCOPE=SPFILE;
shutdown immediate;
start;
SELECT name, value
FROM gv$parameter
WHERE name = 'filesystemio_options';
dbms_resource_manager.create_cdb_plan_directive(
plan IN VARCHAR2,
pluggable_database IN VARCHAR2,
comment IN VARCHAR2 DEFAULT '',
shares IN NUMBER DEFAULT NULL,
utilization_limit IN NUMBER DEFAULT NULL,
parallel_server_limit IN NUMBER DEFAULT NULL,
memory_min IN NUMBER DEFAULT NULL,
memory_limit IN NUMBER DEFAULT NULL);
Create a consolidation resource plan profile directive
dbms_resource_manager.create_cdb_profile_directive(
plan IN VARCHAR2,
profile IN VARCHAR2,
comment IN VARCHAR2 DEFAULT '',
shares IN NUMBER DEFAULT NULL,
utilization_limit IN NUMBER DEFAULT NULL,
parallel_server_limit IN NUMBER DEFAULT NULL,
memory_min IN NUMBER DEFAULT NULL,
memory_limit IN NUMBER DEFAULT NULL
Create entries that define resource consumer groups
dbms_resource_manager.create_consumer_group(
consumer_group IN VARCHAR2,
comment IN VARCHAR2,
cpu_mth IN VARCHAR2 DEFAULT,
mgmt_mth IN VARCHAR2 DEFAULT 'ROUND-ROBIN',
category IN VARCHAR2 DEFAULT 'OTHER');
dbms_resource_manager.create_plan(
plan IN VARCHAR2,
comment IN VARCHAR2,
cpu_mth IN VARCHAR2 DEFAULT NULL,
active_sess_pool_mth IN VARCHAR2 DEFAULT 'ACTIVE_SESS_POOL_ABSOLUTE',
parallel_degree_limit_mth IN VARCHAR2 DEFAULT 'PARALLEL_DEGREE_LIMIT_ABSOLUTE',
queueing_mth IN VARCHAR2 DEFAULT 'FIFO_TIMEOUT',
mgmt_mth IN VARCHAR2 DEFAULT 'EMPHASIS',
sub_plan IN BOOLEAN DEFAULT FALSE,
max_iops IN NUMBER DEFAULT NULL,
max_mbps IN NUMBER DEFAULT NULL);
cpu_mth: Use 'EMPHASIS' for multi-level plans and 'RATIO' for single level plans
dbms_resource_mananger.create_plan_directive(
plan IN VARCHAR2,
group_or_subplan IN VARCHAR2,
comment IN VARCHAR2,
cpu_p1 IN NUMBER DEFAULT NULL,
cpu_p2 IN NUMBER DEFAULT NULL,
cpu_p3 IN NUMBER DEFAULT NULL,
cpu_p4 IN NUMBER DEFAULT NULL,
cpu_p5 IN NUMBER DEFAULT NULL,
cpu_p6 IN NUMBER DEFAULT NULL,
cpu_p7 IN NUMBER DEFAULT NULL,
cpu_p8 IN NUMBER DEFAULT NULL,
active_sess_pool_p1 IN NUMBER DEFAULT NULL,
queueing_p1 IN NUMBER DEFAULT NULL,
parallel_degree_limit_p1 IN NUMBER DEFAULT NULL,
switch_group IN VARCHAR2 DEFAULT NULL,
switch_time IN NUMBER DEFAULT NULL,
switch_estimate IN BOOLEAN DEFAULT FALSE,
max_est_exec_time IN NUMBER DEFAULT NULL,
undo_pool IN NUMBER DEFAULT NULL,
max_idle_time IN NUMBER DEFAULT NULL,
max_idle_blocker_time IN NUMBER DEFAULT NULL,
switch_time_in_call IN NUMBER DEFAULT NULL,
mgmt_p1 IN NUMBER DEFAULT NULL,
mgmt_p2 IN NUMBER DEFAULT NULL,
mgmt_p3 IN NUMBER DEFAULT NULL,
mgmt_p4 IN NUMBER DEFAULT NULL,
mgmt_p5 IN NUMBER DEFAULT NULL,
mgmt_p6 IN NUMBER DEFAULT NULL,
mgmt_p7 IN NUMBER DEFAULT NULL,
mgmt_p8 IN NUMBER DEFAULT NULL,
switch_io_megabytes IN NUMBER DEFAULT NULL,
switch_io_reqs IN NUMBER DEFAULT NULL,
switch_for_call IN BOOLEAN DEFAULT NULL,
max_utilization_limit IN NUMBER DEFAULT NULL, -- max resource alloc. as a % cap
parallel_target_percentage IN NUMBER DEFAULT NULL,
parallel_queue_timeout IN NUMBER DEFAULT NULL,
parallel_server_limit IN NUMBER DEFAULT NULL,
utilization_limit IN NUMBER DEFAULT NULL,
switch_io_logical IN NUMBER DEFAULT NULL,
switch_elapsed_time IN NUMBER DEFAULT NULL,
shares IN NUMBER DEFAULT NULL,
parallel_stmt_critical IN VARCHAR2 DEFAULT NULL);
Create a single-level resource plan containing up to eight consumer groups in one step
dbms_resource_manager.create_simple_plan(
simple_plan IN VARCHAR2 DEFAULT NULL,
consumer_group1 IN VARCHAR2 DEFAULT NULL,
group1_cpu IN NUMBER DEFAULT NULL, -- deprecated parameter
consumer_group2 IN VARCHAR2 DEFAULT NULL,
group2_cpu IN NUMBER DEFAULT NULL, -- deprecated parameter
consumer_group3 IN VARCHAR2 DEFAULT NULL,
group3_cpu IN NUMBER DEFAULT NULL, -- deprecated parameter
consumer_group4 IN VARCHAR2 DEFAULT NULL,
group4_cpu IN NUMBER DEFAULT NULL, -- deprecated parameter
consumer_group5 IN VARCHAR2 DEFAULT NULL,
group5_cpu IN NUMBER DEFAULT NULL, -- deprecated parameter
consumer_group6 IN VARCHAR2 DEFAULT NULL,
group6_cpu IN NUMBER DEFAULT NULL, -- deprecated parameter
consumer_group7 IN VARCHAR2 DEFAULT NULL,
group7_cpu IN NUMBER DEFAULT NULL, -- deprecated parameter
consumer_group8 IN VARCHAR2 DEFAULT NULL,
group8_CPU IN NUMBER DEFAULT NULL, -- deprecated parameter
group1_percent IN NUMBER DEFAULT NULL,
group2_percent IN NUMBER DEFAULT NULL,
group3_percent IN NUMBER DEFAULT NULL,
group4_percent IN NUMBER DEFAULT NULL,
group5_percent IN NUMBER DEFAULT NULL,
group6_percent IN NUMBER DEFAULT NULL,
group7_percent IN NUMBER DEFAULT NULL,
group8_percent IN NUMBER DEFAULT NULL);
dbms_resource_manager.dequeue_parallel_statement(
session_id IN PLS_INTEGER,
session_serial IN PLS_INTEGER,
inst_id IN PLS_INTEGER DEFAULT NULL,
sql_id IN VARCHAR2 DEFAULT NULL);
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);
-- extracted from $ORACLE_HOME/rdbms/adminexecrm.sql. Do not run this demo code BEGIN
dbms_rmin.install;
-- set initial consumer group for SYS and SYSTEM to be SYS_GROUP
dbms_resource_manager.create_pending_area;
dbms_resource_manager.set_consumer_group_mapping(dbms_resource_manager.oracle_user, 'SYSTEM', 'SYS_GROUP');
dbms_resource_manager.set_consumer_group_mapping(dbms_resource_manager.oracle_user, 'SYS', 'SYS_GROUP');
END;
/
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,
client_id IN NUMBER DEFAULT 11);
Update a consolidation resource plan's autotask directive which applies to the autotask jobs that run in the root PDB
dbms_resource_manager.update_cdb_autotask_directive(
plan IN VARCHAR2,
new_comment IN VARCHAR2 DEFAULT NULL,
new_shares IN NUMBER DEFAULT NULL,
new_utilization_limit IN NUMBER DEFAULT NULL,
new_parallel_server_limit IN NUMBER DEFAULT NULL,
new_memory_min IN NUMBER DEFAULT NULL,
new_memory_limit IN NUMBER DEFAULT NULL);
Update a consolidation resource plan's default directive which applies to each PDB that does not have a specific directive in the CDB plan
dbms_resource_manager.update_cdb_default_directive(
plan IN VARCHAR2,
new_comment IN VARCHAR2 DEFAULT NULL,
new_shares IN NUMBER DEFAULT NULL,
new_utilization_limit IN NUMBER DEFAULT NULL,
new_parallel_server_limit IN NUMBER DEFAULT NULL,
new_memory_min IN NUMBER DEFAULT NULL,
new_memory_limit IN NUMBER DEFAULT NULL);
dbms_resource_manager.update_cdb_plan_directive(
plan IN VARCHAR2,
pluggable_database IN VARCHAR2,
new_comment IN VARCHAR2 DEFAULT NULL,
new_shares IN NUMBER DEFAULT NULL,
new_utilization_limit IN NUMBER DEFAULT NULL,
new_parallel_server_limit IN NUMBER DEFAULT NULL,
new_memory_min IN NUMBER DEFAULT NULL,
new_memory_limit IN NUMBER DEFAULT NULL);
Update a consolidation resource plan profile directive
dbms_resource_manager.update_cdb_profile_directive(
plan IN VARCHAR2,
profile IN VARCHAR2,
new_comment IN VARCHAR2 DEFAULT NULL,
new_shares IN NUMBER DEFAULT NULL,
new_utilization_limit IN NUMBER DEFAULT NULL,
new_parallel_server_limit IN NUMBER DEFAULT NULL,
new_memory_min IN NUMBER DEFAULT NULL,
new_memory_limit IN NUMBER DEFAULT NULL);
Update entries that define resource consumer groups
dbms_resource_manager.update_consumer_group(
consumer_group IN VARCHAR2,
new_comment IN VARCHAR2 DEFAULT NULL,
new_cpu_mth IN VARCHAR2 DEFAULT NULL,
new_mgmt_mth IN VARCHAR2 DEFAULT NULL,
new_category IN VARCHAR2 DEFAULT NULL);
dbms_resource_manager.update_plan(
plan IN VARCHAR2,
new_comment IN VARCHAR2 DEFAULT NULL,
new_cpu_mth IN VARCHAR2 DEFAULT NULL,
new_active_sess_pool_mth IN VARCHAR2 DEFAULT NULL,
new_parallel_degree_limit_mth IN VARCHAR2 DEFAULT NULL,
new_queueing_mth IN VARCHAR2 DEFAULT NULL,
new_mgmt_mth IN VARCHAR2 DEFAULT NULL,
new_sub_plan IN BOOLEAN DEFAULT FALSE,
new_max_iops IN NUMBER DEFAULT NULL,
new_max_mbps IN NUMBER DEFAULT NULL);
dbms_resource_manager.update_plan_directive(
plan IN VARCHAR2,
group_or_subplan IN VARCHAR2,
new_comment IN VARCHAR2 DEFAULT NULL,
new_cpu_p1 IN NUMBER DEFAULT NULL,
new_cpu_p2 IN NUMBER DEFAULT NULL,
new_cpu_p3 IN NUMBER DEFAULT NULL,
new_cpu_p4 IN NUMBER DEFAULT NULL,
new_cpu_p5 IN NUMBER DEFAULT NULL,
new_cpu_p6 IN NUMBER DEFAULT NULL,
new_cpu_p7 IN NUMBER DEFAULT NULL,
new_cpu_p8 IN NUMBER DEFAULT NULL,
new_active_sess_pool_p1 IN NUMBER DEFAULT NULL,
new_queueing_p1 IN NUMBER DEFAULT NULL,
new_parallel_degree_limit_p1 IN NUMBER DEFAULT NULL,
new_switch_group IN VARCHAR2 DEFAULT NULL,
new_switch_time IN NUMBER DEFAULT NULL,
new_switch_estimate IN BOOLEAN DEFAULT FALSE,
new_max_est_exec_time IN NUMBER DEFAULT NULL,
new_undo_pool IN NUMBER DEFAULT NULL,
new_max_idle_time IN NUMBER DEFAULT NULL,
new_max_idle_blocker_time IN NUMBER DEFAULT NULL,
new_switch_time_in_call IN NUMBER DEFAULT NULL,
new_mgmt_p1 IN NUMBER DEFAULT NULL,
new_mgmt_p2 IN NUMBER DEFAULT NULL,
new_mgmt_p3 IN NUMBER DEFAULT NULL,
new_mgmt_p4 IN NUMBER DEFAULT NULL,
new_mgmt_p5 IN NUMBER DEFAULT NULL,
new_mgmt_p6 IN NUMBER DEFAULT NULL,
new_mgmt_p7 IN NUMBER DEFAULT NULL,
new_mgmt_p8 IN NUMBER DEFAULT NULL,
new_switch_io_megabytes IN NUMBER DEFAULT NULL,
new_switch_io_reqs IN NUMBER DEFAULT NULL,
new_switch_for_call IN BOOLEAN DEFAULT NULL,
new_max_utilization_limit IN NUMBER DEFAULT NULL,
new_parallel_target_percentage IN NUMBER DEFAULT NULL,
new_parallel_queue_timeout IN NUMBER DEFAULT NULL,
new_parallel_server_limit IN NUMBER DEFAULT NULL,
new_utilization_limit IN NUMBER DEFAULT NULL,
new_switch_io_logical IN NUMBER DEFAULT NULL,
new_switch_elapsed_time IN NUMBER DEFAULT NULL,
new_shares IN NUMBER DEFAULT NULL,
new_parallel_stmt_critical IN VARCHAR2 DEFAULT NULL);
-- 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;
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;
-- Prevent the Managers from running an operation
with an estimated execution time > 0
dbms_resource_manager.create_plan_directive(plan => 'TEST2',
group_or_subplan => 'OTHER_GROUPS', comment => 'Testing', cpu_p2 => 100);
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 sys@pdbdev 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');
Creating services and resource management groups for a RAC cluster
-- server control portion srvctl add service -d OPM01P -s node1primary -r OPM01P1 -a OPM01P3
srvctl add service -d OPM01P -s node2primary -r OPM01P2 -a OPM01P3
srvctl add service -d OPM01P -s node3primary -r OPM01P3 -a OPM01P1, OPM01P2
srvctl start service -d OPM01P -s node1primary
srvctl start service -d OPM01P -s node2primary
srvctl start service -d OPM01P -s node3primary
-- database portion: add mappings and mapping priority
BEGIN
dbms_resource_manager.clear_pending_area();
dbms_resource_manager.create_pending_area();
dbms_resource_manager.set_consumer_group_mapping(
attribute => 'CLIENT_PROGRAM',
value => 'EtlEngine.exe',
consumer_group => 'data_collection');
dbms_resource_manager.set_consumer_group_mapping(
attribute => 'CLIENT_PROGRAM',
value => 'ReadData.exe',
consumer_group => 'data_collection');
SELECT dbms_utility.current_instance, TO_CHAR(begin_time, 'HH:MI') time,
60 * (SELECT value FROM v$osstat WHERE stat_name = 'NUM_CPUS') total,
60 * (SELECT value FROM v$parameter WHERE name = 'cpu_count') db_total,
SUM(cpu_consumed_time) / 1000 consumed, SUM(cpu_wait_time) / 1000 throttled
FROM v$rsrcmgrmetric_history
GROUP BY begin_time
ORDER BY 1;
SELECT TO_CHAR(begin_time, 'HH:MI') time,
ROUND(SUM(cpu_consumed_time) / 60000,2) avg_running,
ROUND(SUM(cpu_wait_time) / 60000,2) avg_throttled
FROM gv$rsrcmgrmetric_history
GROUP BY TO_CHAR(begin_time, 'HH:MI')
ORDER BY 1;