Skip to content

Commit 73a8d9a

Browse files
Merge pull request #955 from oracle-devrel/uschwinn-resource
Uschwinn resource
2 parents 3d27d1e + dbf2fec commit 73a8d9a

19 files changed

+443
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Database Resource Manager
2+
3+
4+
Computing resources in either a Cloud environment or a traditional data center environment represent a significant cost to any organization. Proper management of those computing issues in one business application from impacting another. Oracle’s resource management tools include the ability to manage system resources so that each database (and therefore each business application) receives the desired minimum amount of system resources, and each database does not exceed the amount of allocated resources. With Database Resource Manager the database has more control over how hardware resources are allocated. When database resource allocation decisions are left to the operating system, you may encounter problems with workload management.
5+
6+
Database Resource Manager helps to overcome these problems like inappropriate allocation of resources, and excessive overhead by allowing the database more control over how hardware resources are allocated. In an environment with multiple concurrent user sessions that run jobs with differing priorities, all sessions should not be treated equally. Database Resource Manager enables you to classify sessions into groups based on session attributes and then allocate resources to those groups in a way that optimizes hardware utilization for your application environment.
7+
8+
Reviewed: 16.04.2024
9+
10+
# Useful Links
11+
12+
## Documentation
13+
14+
- [Database Administrator’s Guide](https://docs.oracle.com/en/database/oracle/oracle-database/19/admin/managing-resources-with-oracle-database-resource-manager.html#GUID-2BEF5482-CF97-4A85-BD90-9195E41E74EF)
15+
- [PL/SQL Packages and Types Reference: DBMS_RESOURCE_MANAGER](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_RESOURCE_MANAGER.html#GUID-F3B685CB-5F15-4DFB-90FD-6FBBA9B6F6DB)
16+
- [PL/SQL Packages and Types Reference: DBMS_RESOURCE_MANAGER_PRIVS](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_RESOURCE_MANAGER_PRIVS.html#GUID-B8B082C6-DF53-466B-9B11-1CAFCC3F0509)
17+
18+
19+
## Videos
20+
21+
- [How to Use Resource Manager in Oracle with CDB and PDB - Oracle database resource manager](https://www.youtube.com/watch?v=rXSWGo2pWE4)
22+
23+
## Blogs and technical briefs
24+
25+
- [High Performance Database Deployment with Resource Manager](https://blogs.oracle.com/exadata/post/high-performance-database-deployment-with-resource-manager)
26+
- [Multitenant: Dynamic CPU Scaling - Resource Manager Control of CPU using CPU_COUNT and CPU_MIN_COUNT](https://oracle-base.com/articles/19c/multitenant-dynamic-cpu-scaling-19c)
27+
- [Best Practices for Database Consolidation](https://www.oracle.com/docs/tech/database/maa-consolidation.pdf)
28+
29+
# Team Publications
30+
31+
- [Scripts to create a simple resource plan](https://github.com/oracle-devrel/technology-engineering/tree/main/data-platform/core-converged-db/resource-manager/scripts)
32+
33+
34+
# License
35+
36+
Copyright (c) 2024 Oracle and/or its affiliates.
37+
38+
Licensed under the Universal Permissive License (UPL), Version 1.0.
39+
40+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Database Resource Manager scripts
2+
3+
Use these Database Resource Manager scripts to set up a simple resource plan and consumer groups in a database (PDB) to limit CPU for certain tasks such as redefinition tasks. All scripts must be run as sysdba. Please change the scripts according to your needs. For a detailed description please read the documentation.
4+
5+
Reviewed: 16.04.2024
6+
7+
# When to use this asset?
8+
9+
To learn about database resource manager.
10+
11+
# How to use this asset?
12+
13+
Run the scripts.
14+
15+
The following scripts help to monitor the setup:
16+
- monitorplan.sql: to monitor the resource plan
17+
- monitorgroup.sql: to monitor the resource group for a user (e.g. after a switch)
18+
- cpu_sess.sql: to monitor resource manager statistics per session
19+
- cpu_user.sql: to display CPU related data for currently active resource consumer groups
20+
- cpu_dop_sess.sql: to display CPU and DOP related data for currently active resource consumer groups
21+
- activeplan.sql: to display active plan and the history of active plans
22+
- throttlingperconsumer.sql: to display information about resources consumed and wait times per consumer group.
23+
Interesting fact: When STATISTICS_LEVEL is set to TYPICAL or ALL, this view contains information about CPU utilization and wait times even when no Resource Manager plan is set or when the Resource Manager plan does not monitor CPU or session resources. Metrics are collected and stored every minute when CPU utilization is not being monitored.
24+
25+
The following scripts helps to setup an environment:
26+
- consumer.sql: to set up the consumer groups
27+
- plan.sql: to set up the resource plan
28+
- planon.sql: switch plan on
29+
- planoff.sql: switch plan off
30+
- removeplan.sql: to remove a resource plan
31+
32+
The foloowing scripts switch a plan or a group to another plan or group:
33+
- switch_sess.sql: to switch a current session to raise or lower resources
34+
- switch_user.sql: to switch a user
35+
- switchplan.sql: to switch a plan
36+
37+
Scripts to test a plan:
38+
- burn.sql: to create REDEF_USER and a program to burn CPU
39+
- burns.sql: to run the script to burn CPU
40+
41+
# Useful Links
42+
43+
## Documentation
44+
45+
- [Database Administrator’s Guide](https://docs.oracle.com/en/database/oracle/oracle-database/19/admin/managing-resources-with-oracle-database-resource-manager.html#GUID-2BEF5482-CF97-4A85-BD90-9195E41E74EF)
46+
- [PL/SQL Packages and Types Reference: DBMS_RESOURCE_MANAGER](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_RESOURCE_MANAGER.html#GUID-F3B685CB-5F15-4DFB-90FD-6FBBA9B6F6DB)
47+
- [PL/SQL Packages and Types Reference: DBMS_RESOURCE_MANAGER_PRIVS](https://docs.oracle.com/en/database/oracle/oracle-database/19/arpls/DBMS_RESOURCE_MANAGER_PRIVS.html#GUID-B8B082C6-DF53-466B-9B11-1CAFCC3F0509)
48+
49+
# License
50+
51+
Copyright (c) 2024 Oracle and/or its affiliates.
52+
53+
Licensed under the Universal Permissive License (UPL), Version 1.0.
54+
55+
See [LICENSE](https://github.com/oracle-devrel/technology-engineering/blob/main/LICENSE) for more details.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- to monitor active plans and the history of active plans
2+
3+
set linesize window
4+
select * from v$rsrc_plan;
5+
6+
select sequence# seq, name plan_name,
7+
to_char(start_time, 'DD-mon HH24:mi') start_time,
8+
to_char(end_time, 'dd-mon hh24:mi') end_time
9+
from v$rsrc_plan_history;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- Test the resource plan
2+
-- Create a user REDEF_USER and a script to burn CPU
3+
4+
drop user redef_user cascade;
5+
create user redef_user identified by test;
6+
grant connect, resource to redef_user;
7+
alter user redef_user quota 100M on users;
8+
9+
-- script for CPU burn
10+
11+
CREATE OR REPLACE FUNCTION redef_user.burn_cpu (p_mins IN NUMBER)
12+
RETURN NUMBER
13+
AS
14+
l_start_time DATE;
15+
l_number NUMBER := 1;
16+
BEGIN
17+
l_start_time := SYSDATE;
18+
LOOP
19+
EXIT WHEN SYSDATE - l_start_time > (p_mins/24/60);
20+
l_number := l_number + 1;
21+
END LOOP;
22+
RETURN 0;
23+
END;
24+
/
25+
grant execute on burn_cpu to public;
26+
27+
-- Use burns.sql to run the script
28+
-- SELECT burn_cpu (5) FROM dual;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Run the script to burn CPU
2+
-- First execute burn.sql
3+
4+
SELECT redef_user.burn_cpu (5) FROM dual;
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
-- Create the consumer groups in a first step
2+
-- A resource consumer group (consumer group) is a collection of user sessions that are grouped together based on their processing needs.
3+
-- There are special consumer groups SYS_GROUP and OTHER_GROUPS that are always present in the data dictionary. They cannot be modified or deleted. SYS_GROUP
4+
-- There can be no more than 28 resource consumer groups in any active plan.
5+
6+
7+
-- delete existing groups if required
8+
BEGIN
9+
dbms_resource_manager.clear_pending_area();
10+
dbms_resource_manager.create_pending_area();
11+
12+
dbms_resource_manager.delete_consumer_group(consumer_group => 'REDEF_GROUP');
13+
14+
dbms_resource_manager.validate_pending_area();
15+
dbms_resource_manager.submit_pending_area();
16+
END;
17+
/
18+
BEGIN
19+
dbms_resource_manager.clear_pending_area();
20+
dbms_resource_manager.create_pending_area();
21+
22+
dbms_resource_manager.delete_consumer_group(consumer_group =>'LOWER_GROUP');
23+
24+
dbms_resource_manager.validate_pending_area();
25+
dbms_resource_manager.submit_pending_area();
26+
END;
27+
/
28+
29+
-- change priority of consumer groups if required
30+
begin
31+
dbms_resource_manager.set_consumer_group_mapping_pri(
32+
explicit => 1,
33+
service_module_action => 2,
34+
service_module => 3,
35+
module_name_action => 4,
36+
module_name => 5,
37+
service_name => 6,
38+
oracle_user => 7,
39+
client_program => 8,
40+
client_os_user => 9,
41+
client_machine => 10,
42+
client_id => 11);
43+
end;
44+
/
45+
46+
-- Create consumer group REDEF_GROUP and LOWER_GROUP
47+
BEGIN
48+
dbms_resource_manager.clear_pending_area();
49+
dbms_resource_manager.create_pending_area();
50+
dbms_resource_manager.create_consumer_group(consumer_group => 'REDEF_GROUP', comment => 'Consumer group for redefinition');
51+
dbms_resource_manager.validate_pending_area();
52+
dbms_resource_manager.submit_pending_area();
53+
END;
54+
/
55+
56+
-- Consumer group for lower usage
57+
BEGIN
58+
dbms_resource_manager.clear_pending_area();
59+
dbms_resource_manager.create_pending_area();
60+
dbms_resource_manager.create_consumer_group(consumer_group => 'LOWER_GROUP', comment => 'Consumer group for lower usage');
61+
dbms_resource_manager.validate_pending_area();
62+
dbms_resource_manager.submit_pending_area();
63+
END;
64+
/
65+
66+
-- Grant user REDEF_USER the privilege to switch to group REDEF_GROUP and map user REDEF_USER to the REDEF_GROUP consumer group every time he logs in:
67+
BEGIN
68+
dbms_resource_manager.clear_pending_area();
69+
dbms_resource_manager.create_pending_area();
70+
71+
DBMS_RESOURCE_MANAGER_PRIVS.GRANT_SWITCH_CONSUMER_GROUP(GRANTEE_NAME => 'REDEF_USER', CONSUMER_GROUP => 'REDEF_GROUP', GRANT_OPTION => TRUE);
72+
DBMS_RESOURCE_MANAGER.set_consumer_group_mapping(attribute => dbms_resource_manager.oracle_user, value => 'REDEF_USER',consumer_group => 'REDEF_GROUP');
73+
74+
dbms_resource_manager.validate_pending_area();
75+
dbms_resource_manager.submit_pending_area();
76+
END;
77+
/
78+
79+
-- Grant user REDEF_USER the privilege to switch to group LOWER_GROUP
80+
BEGIN
81+
dbms_resource_manager.clear_pending_area();
82+
dbms_resource_manager.create_pending_area();
83+
84+
DBMS_RESOURCE_MANAGER_PRIVS.GRANT_SWITCH_CONSUMER_GROUP(GRANTEE_NAME => 'REDEF_USER', CONSUMER_GROUP => 'LOWER_GROUP', GRANT_OPTION => TRUE);
85+
86+
dbms_resource_manager.validate_pending_area();
87+
dbms_resource_manager.submit_pending_area();
88+
END;
89+
/
90+
91+
92+
-- Monitor consumer groups and the mappings
93+
set linesize window
94+
col value format a20
95+
col consumer_group format a25
96+
col attribute format a15
97+
select attribute, value, consumer_group from DBA_RSRC_GROUP_MAPPINGS;
98+
99+
col comments format a60
100+
col status format a10
101+
select CONSUMER_GROUP, COMMENTS from DBA_RSRC_CONSUMER_GROUPS;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-- V$RSRC_SESSION_INFO displays Resource Manager statistics per session.
2+
3+
set linesize window
4+
col username format a20
5+
col osuser format a15
6+
col gruppe format a15
7+
8+
select s.username username,s.osuser osuser, co.name gruppe,
9+
se.state, se.consumed_cpu_time cpu_time, se.cpu_wait_time
10+
from v$rsrc_session_info se, v$rsrc_consumer_group co , v$session s
11+
where se.current_consumer_group_id = co.id and s.sid=se.sid and se.state!='NOT MANAGED';
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- V$RSRC_SESSION_INFO displays Resource Manager statistics per session.
2+
3+
set linesize window
4+
col username format a10
5+
col osuser format a10
6+
col group_name format a20
7+
col service format a8
8+
col state format a15
9+
10+
select s.inst_id inst,
11+
s.username username,
12+
s.osuser osuser,
13+
co.name group_name,
14+
s.service_name service,
15+
se.state,
16+
se.consumed_cpu_time cpu_time,
17+
se.cpu_wait_time,
18+
se.dop/2 degree_of_parallelism
19+
from gv$rsrc_session_info se, gv$rsrc_consumer_group co, gv$session s
20+
where se.current_consumer_group_id = co.id
21+
and s.sid = se.sid
22+
and s.inst_id = se.inst_id
23+
and co.name not in ('_ORACLE_BACKGROUND_GROUP_')
24+
order by s.inst_id, s.username;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- V$RSRC_CONSUMER_GROUP displays data related to currently active resource consumer groups.
2+
3+
set linesize window
4+
5+
select inst_id,
6+
name,
7+
active_sessions,
8+
consumed_cpu_time,
9+
cpu_waits,
10+
cpu_wait_time
11+
from gv$rsrc_consumer_group
12+
order by inst_id, name;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Monitor user REDEF_USER and his consumer groups
2+
3+
select sid, serial#, username, resource_consumer_group, status
4+
from v$session where username='REDEF_USER';

0 commit comments

Comments
 (0)