Oracle® Database Administrator's Guide 11g Release 2 (11.2) Part Number E10595-06 |
|
|
View PDF |
This section provides some examples of resource plans. The following examples are presented:
The following PL/SQL block creates a multilevel plan as illustrated in Figure 26-3. Default resource allocation method settings are used for all plans and resource consumer groups.
BEGIN DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'bugdb_plan', COMMENT => 'Resource plan/method for bug users sessions'); DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'maildb_plan', COMMENT => 'Resource plan/method for mail users sessions'); DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'mydb_plan', COMMENT => 'Resource plan/method for bug and mail users sessions'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Online_group', COMMENT => 'Resource consumer group/method for online bug users sessions'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Batch_group', COMMENT => 'Resource consumer group/method for batch job bug users sessions'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Bug_Maint_group', COMMENT => 'Resource consumer group/method for users sessions for bug db maint'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Users_group', COMMENT => 'Resource consumer group/method for mail users sessions'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Postman_group', COMMENT => 'Resource consumer group/method for mail postman'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'Mail_Maint_group', COMMENT => 'Resource consumer group/method for users sessions for mail db maint'); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan', GROUP_OR_SUBPLAN => 'Online_group', COMMENT => 'online bug users sessions at level 1', MGMT_P1 => 80, MGMT_P2=> 0); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan', GROUP_OR_SUBPLAN => 'Batch_group', COMMENT => 'batch bug users sessions at level 1', MGMT_P1 => 20, MGMT_P2 => 0, PARALLEL_DEGREE_LIMIT_P1 => 8); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan', GROUP_OR_SUBPLAN => 'Bug_Maint_group', COMMENT => 'bug maintenance users sessions at level 2', MGMT_P1 => 0, MGMT_P2 => 100); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'bugdb_plan', GROUP_OR_SUBPLAN => 'OTHER_GROUPS', COMMENT => 'all other users sessions at level 3', MGMT_P1 => 0, MGMT_P2 => 0, MGMT_P3 => 100); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan', GROUP_OR_SUBPLAN => 'Postman_group', COMMENT => 'mail postman at level 1', MGMT_P1 => 40, MGMT_P2 => 0); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan', GROUP_OR_SUBPLAN => 'Users_group', COMMENT => 'mail users sessions at level 2', MGMT_P1 => 0, MGMT_P2 => 80); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan', GROUP_OR_SUBPLAN => 'Mail_Maint_group', COMMENT => 'mail maintenance users sessions at level 2', MGMT_P1 => 0, MGMT_P2 => 20); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'maildb_plan', GROUP_OR_SUBPLAN => 'OTHER_GROUPS', COMMENT => 'all other users sessions at level 3', MGMT_P1 => 0, MGMT_P2 => 0, MGMT_P3 => 100); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'mydb_plan', GROUP_OR_SUBPLAN => 'maildb_plan', COMMENT=> 'all mail users sessions at level 1', MGMT_P1 => 30); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'mydb_plan', GROUP_OR_SUBPLAN => 'bugdb_plan', COMMENT => 'all bug users sessions at level 1', MGMT_P1 => 70); DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA(); END; /
The preceding call to VALIDATE_PENDING_AREA
is optional because the validation is implicitly performed in SUBMIT_PENDING_AREA
.
In this plan schema, CPU resources are allocated as follows:
Under mydb_plan
, 30% of CPU is allocated to the maildb_plan
subplan, and 70% is allocated to the bugdb_plan
subplan. Both subplans are at level 1. Because mydb_plan
itself has no levels below level 1, any resource allocations that are unused by either subplan at level 1 can be used by its sibling subplan. Thus, if maildb_plan
uses only 20% of CPU, then 80% of CPU is available to bugdb_plan
.
maildb_plan
and bugdb_plan
define allocations at levels 1, 2, and 3. The levels in these subplans are independent of levels in their parent plan, mydb_plan
. That is, all plans and subplans in a plan schema have their own level 1, level 2, level 3, and so on.
Of the 30% of CPU allocated to maildb_plan
, 40% of that amount (effectively 12% of total CPU) is allocated to Postman_group
at level 1. Because Postman_group
has no siblings at level 1, there is an implied 60% remaining at level 1. This 60% is then shared by Users_group
and Mail_Maint_group
at level 2, at 80% and 20%, respectively. In addition to this 60%, Users_group
and Mail_Maint_group
can also use any of the 40% not used by Postman_group
at level 1.
CPU resources not used by either Users_group
or Mail_Maint_group
at level 2 are allocated to OTHER_GROUPS
, because in multilevel plans, unused resources are reallocated to consumer groups or subplans at the next lower level, not to siblings at the same level. Thus, if Users_group
uses only 70% instead of 80%, the remaining 10% cannot be used by Mail_Maint_group
. That 10% is available only to OTHER_GROUPS
at level 3.
The 70% of CPU allocated to the bugdb_plan
subplan is allocated to its consumer groups in a similar fashion. If either Online_group
or Batch_group
does not use its full allocation, the remainder may be used by Bug_Maint_group
. If Bug_Maint_group
does not use all of that allocation, the remainder goes to OTHER_GROUPS
.
The following examples demonstrate how to use the MAX_UTILIZATION_LIMIT
resource plan directive attribute to:
Restrict total database CPU utilization
Quarantine runaway queries
Limit CPU usage for applications
Limit CPU utilization during maintenance windows
Example 1 - Restricting Overall Database CPU Utilization
In this example, regardless of database load, system workload from Oracle Database never exceeds 90% of CPU, leaving 10% of CPU for other applications sharing the server.
BEGIN DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.CREATE_PLAN( PLAN => 'MAXCAP_PLAN', COMMENT => 'Limit overall database CPU'); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE( PLAN => 'MAXCAP_PLAN', GROUP_OR_SUBPLAN => 'OTHER_GROUPS', COMMENT => 'This group is mandatory', MAX_UTILIZATION_LIMIT => 90); DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA(); END; /
Because there is no plan directive other than the one for OTHER_GROUPS
, all sessions are mapped to OTHER_GROUPS
.
Example 2 - Quarantining Runaway Queries
In this example, runaway queries are switched to a consumer group with a maximum utilization limit of 20%, limiting the amount of resources that they can consume until you can intervene. A runaway query is characterized here as one that takes more than 10 minutes of CPU time. Assume that session mapping rules start all sessions in START_GROUP
.
BEGIN DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP ( CONSUMER_GROUP => 'START_GROUP', COMMENT => 'Sessions start here'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP ( CONSUMER_GROUP => 'QUARANTINE_GROUP', COMMENT => 'Sessions switched here to quarantine them'); DBMS_RESOURCE_MANAGER.CREATE_PLAN( PLAN => 'Quarantine_plan', COMMENT => 'Quarantine runaway queries'); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE( PLAN => 'Quarantine_plan', GROUP_OR_SUBPLAN => 'START_GROUP', COMMENT => 'Max CPU 10 minutes before switch', MGMT_P1 => 75, switch_group => 'QUARANTINE_GROUP', switch_time => 600); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE( PLAN => 'Quarantine_plan', GROUP_OR_SUBPLAN => 'OTHER_GROUPS', COMMENT => 'Mandatory', MGMT_P1 => 25); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE( PLAN => 'Quarantine_plan', GROUP_OR_SUBPLAN => 'QUARANTINE_GROUP', COMMENT => 'Limited CPU', MAX_UTILIZATION_LIMIT => 20); DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA(); END; /
Caution:
Although you could set the maximum utilization limit to zero forQUARANTINE_GROUP
, thus completely quarantining runaway queries, you must do this with caution. If the runaway query is holding any resources—PGA memory, locks, and so on—required by any other session, a zero allocation setting could lead to a deadlock.Example 3 - LImiting CPU for Applications
In this example, assume that mapping rules map application sessions into one of four application groups. Each application group is allocated a maximum utilization limit of 30%. This limits CPU utilization of any one application to 30%. The sum of the MAX_UTILIZATION_LIMIT
values exceeds 100%, which is permissible and acceptable in a situation where all applications are not active simultaneously.
BEGIN DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP ( CONSUMER_GROUP => 'APP1_GROUP', COMMENT => 'Apps group 1'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP ( CONSUMER_GROUP => 'APP2_GROUP', COMMENT => 'Apps group 2'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP ( CONSUMER_GROUP => 'APP3_GROUP', COMMENT => 'Apps group 3'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP ( CONSUMER_GROUP => 'APP4_GROUP', COMMENT => 'Apps group 4'); DBMS_RESOURCE_MANAGER.CREATE_PLAN( PLAN => 'apps_plan', COMMENT => 'Application consolidation'); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE ( PLAN => 'apps_plan', GROUP_OR_SUBPLAN => 'APP1_GROUP', COMMENT => 'Apps group 1', MAX_UTILIZATION_LIMIT => 30); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE ( PLAN => 'apps_plan', GROUP_OR_SUBPLAN => 'APP2_GROUP', COMMENT => 'Apps group 2', MAX_UTILIZATION_LIMIT => 30); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE ( PLAN => 'apps_plan', GROUP_OR_SUBPLAN => 'APP3_GROUP', COMMENT => 'Apps group 3', MAX_UTILIZATION_LIMIT => 30); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE ( PLAN => 'apps_plan', GROUP_OR_SUBPLAN => 'APP4_GROUP', COMMENT => 'Apps group 4', MAX_UTILIZATION_LIMIT => 30); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE ( PLAN => 'apps_plan', GROUP_OR_SUBPLAN => 'OTHER_GROUPS', COMMENT => 'Mandatory', MAX_UTILIZATION_LIMIT => 20); DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA(); END; /
Example 4 - Limiting CPU During Maintenance Windows
The following PL/SQL block adds maximum CPU utilization limits to the predefined plan DEFAULT_MAINTENANCE_PLAN
, which is activated during maintenance windows.
BEGIN DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTIVE('DEFAULT_MAINTENANCE_PLAN', 'ORA$DIAGNOSTICS', NEW_MAX_UTILIZATION_LIMIT => 5); DBMS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTIVE('ORA$AUTOTASK_HIGH_SUB_PLAN', 'ORA$AUTOTASK_HEALTH_GROUP', NEW_MAX_UTILIZATION_LIMIT => 25); DBMS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTIVE('ORA$AUTOTASK_HIGH_SUB_PLAN', 'ORA$AUTOTASK_STATS_GROUP', NEW_MAX_UTILIZATION_LIMIT => 25); DBMS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTIVE('ORA$AUTOTASK_HIGH_SUB_PLAN', 'ORA$AUTOTASK_SPACE_GROUP', NEW_MAX_UTILIZATION_LIMIT => 25); DBMS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTIVE('ORA$AUTOTASK_HIGH_SUB_PLAN', 'ORA$AUTOTASK_SQL_GROUP', NEW_MAX_UTILIZATION_LIMIT => 25); DBMS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTIVE('ORA$AUTOTASK_SUB_PLAN', 'ORA$AUTOTASK_URGENT_GROUP', NEW_MAX_UTILIZATION_LIMIT => 25); DBMS_RESOURCE_MANAGER.UPDATE_PLAN_DIRECTIVE('ORA$AUTOTASK_SUB_PLAN', 'ORA$AUTOTASK_MEDIUM_GROUP', NEW_MAX_UTILIZATION_LIMIT => 25); DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA(); END; /
The example presented here could represent a plan for a database supporting a packaged ERP (Enterprise Resource Planning) or CRM (Customer Relationship Management) application. The work in such an environment can be highly varied. There may be a mix of short transactions and quick queries, in combination with longer running batch jobs that include large parallel queries. The goal is to give good response time to OLTP (Online Transaction Processing), while allowing batch jobs to run in parallel.
The plan is summarized in the following table.
Group | CPU Resource Allocation % | Active Session Pool Parameters | Automatic Consumer Group Switching | Maximum Estimated Execution Time | Undo Pool |
---|---|---|---|---|---|
oltp |
Level 1: 80% | Switch to group: batch
Switch time: 3 secs |
200K | ||
batch |
Level 2: 100% | Pool size: 5
Timeout: 600 secs |
-- | 3600 secs | -- |
OTHER_GROUPS |
Level 3: 100% | -- | -- | -- |
By assigning only 80% of the CPU to oltp
at level 1, batch
is guaranteed to get at least 20%, plus any of oltp
's unused CPU resources. OTHER_GROUPS
, however, is not guaranteed any CPU resources. It gets CPU resources only if batch
is unable to consume all of its allocation. A similar-looking plan would give oltp
80% and batch
20%, both at level 1, and OTHER_GROUPS
100% at level 2. With this plan, oltp
's unused CPU allocation would be given to OTHER_GROUPS
, not batch
.
The following statements create the preceding plan, which is named erp_plan
:
BEGIN DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN => 'erp_plan', COMMENT => 'Resource plan/method for ERP Database'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'oltp', COMMENT => 'Resource consumer group/method for OLTP jobs'); DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'batch', COMMENT => 'Resource consumer group/method for BATCH jobs'); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'erp_plan', GROUP_OR_SUBPLAN => 'oltp', COMMENT => 'OLTP sessions', MGMT_P1 => 80, SWITCH_GROUP => 'batch', SWITCH_TIME => 3, UNDO_POOL => 200); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'erp_plan', GROUP_OR_SUBPLAN => 'batch', COMMENT => 'BATCH sessions', MGMT_P2 => 100, ACTIVE_SESS_POOL_P1 => 5, QUEUEING_P1 => 600, MAX_EST_EXEC_TIME => 3600); DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN => 'erp_plan', GROUP_OR_SUBPLAN => 'OTHER_GROUPS', COMMENT => 'mandatory', MGMT_P3 => 100); DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA(); DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA(); END; /
Oracle Database includes a predefined resource plan, MIXED_WORKLOAD_PLAN
, that prioritizes interactive operations over batch operations, and includes the required subplans and consumer groups recommended by Oracle. MIXED_WORKLOAD_PLAN
is defined as follows:
In this plan, because INTERACTIVE_GROUP
is intended for short transactions, any call that consumes more than 60 seconds of CPU time is automatically switched to BATCH_GROUP
, which is intended for longer batch operations.
You can use this predefined plan if it is appropriate for your environment. (You can modify the plan, or delete it if you do not intend to use it.) Note that there is nothing special about the names BATCH_GROUP
and INTERACTIVE_GROUP
. The names reflect only the intended purposes of the groups, and it is up to you to map application sessions to these groups and adjust CPU resource allocation percentages accordingly so that you achieve proper resource management for your interactive and batch applications. For example, to ensure that your interactive applications run under the INTERACTIVE_GROUP
consumer group, you must map your interactive applications' user sessions to this consumer group based on user name, service name, program name, module name, or action, as described in "Specifying Session-to–Consumer Group Mapping Rules". You must map your batch applications to the BATCH_GROUP
in the same way. Finally, you must enable this plan as described in "Enabling Oracle Database Resource Manager and Switching Plans".
See Table 26-3 and Table 26-4 for explanations of the other resource consumer groups and subplans in this plan.