DBMS_RESOURCE_MANAGER

参考文档:

Database Administrator's Guide

27 Managing Resources with Oracle Database Resource Manager

27.5.5 Creating a Resource Plan

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;
/

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',
                                              UTILIZATION_LIMIT => 90);

  DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
  DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;

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',
                                              MGMT_P2           => 100,
                                              UTILIZATION_LIMIT => 20);

  DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
  DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
/

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',
                                              UTILIZATION_LIMIT => 30);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN              => 'apps_plan',
                                              GROUP_OR_SUBPLAN  => 'APP2_GROUP',
                                              COMMENT           => 'Apps group 2',
                                              UTILIZATION_LIMIT => 30);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN              => 'apps_plan',
                                              GROUP_OR_SUBPLAN  => 'APP3_GROUP',
                                              COMMENT           => 'Apps group 3',
                                              UTILIZATION_LIMIT => 30);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN              => 'apps_plan',
                                              GROUP_OR_SUBPLAN  => 'APP4_GROUP',
                                              COMMENT           => 'Apps group 4',
                                              UTILIZATION_LIMIT => 30);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN              => 'apps_plan',
                                              GROUP_OR_SUBPLAN  => 'OTHER_GROUPS',
                                              COMMENT           => 'Mandatory',
                                              UTILIZATION_LIMIT => 20);

  DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
  DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
/

BEGIN
  DBMS_RESOURCE_MANAGER.CREATE_PENDING_AREA();
  DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'APP1_GROUP',
                                              COMMENT        => 'Group for application #1');
  DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'APP2_OLTP_GROUP',
                                              COMMENT        => 'Group for OLTP activity in application #2');
  DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'APP2_ADHOC_GROUP',
                                              COMMENT        => 'Group for ad-hoc queries in application #2');
  DBMS_RESOURCE_MANAGER.CREATE_CONSUMER_GROUP(CONSUMER_GROUP => 'APP2_REPORT_GROUP',
                                              COMMENT        => 'Group for reports in application #2');
  DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN    => 'APPS_PLAN',
                                    COMMENT => 'Plan for managing 3 applications');
  DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN     => 'APP2_SUBPLAN',
                                    COMMENT  => 'Subplan for managing application #2',
                                    SUB_PLAN => TRUE);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN(PLAN     => 'APP2_REPORTS_SUBPLAN',
                                    COMMENT  => 'Subplan for managing reports in application #2',
                                    SUB_PLAN => TRUE);

  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN              => 'APPS_PLAN',
                                              GROUP_OR_SUBPLAN  => 'APP1_GROUP',
                                              COMMENT           => 'Limit CPU for application #1 to 40%',
                                              UTILIZATION_LIMIT => 40);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN              => 'APPS_PLAN',
                                              GROUP_OR_SUBPLAN  => 'APP2_SUBPLAN',
                                              COMMENT           => 'Limit CPU for application #2 to 40%',
                                              UTILIZATION_LIMIT => 40);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN              => 'APP2_SUBPLAN',
                                              GROUP_OR_SUBPLAN  => 'APP2_OLTP_GROUP',
                                              COMMENT           => 'Limit CPU for OLTP to 90% of application #2',
                                              UTILIZATION_LIMIT => 90);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN             => 'APP2_SUBPLAN',
                                              GROUP_OR_SUBPLAN => 'APP2_REPORTS_SUBPLAN',
                                              COMMENT          => 'Subplan for ad-hoc and normal reports for application #2');
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN              => 'APP2_REPORTS_SUBPLAN',
                                              GROUP_OR_SUBPLAN  => 'APP2_ADHOC_GROUP',
                                              COMMENT           => 'Limit CPU for ad-hoc queries to 50% of application #2 reports',
                                              UTILIZATION_LIMIT => 50);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN              => 'APP2_REPORTS_SUBPLAN',
                                              GROUP_OR_SUBPLAN  => 'APP2_REPORT_GROUP',
                                              COMMENT           => 'Limit CPU for reports to 50% of application #2 reports',
                                              UTILIZATION_LIMIT => 50);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN             => 'APPS_PLAN',
                                              GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
                                              COMMENT          => 'No directives for default users');
  DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
  DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
/

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           => 60,
                                              SWITCH_GROUP      => 'batch',
                                              SWITCH_TIME       => 3,
                                              UNDO_POOL         => 200,
                                              SWITCH_FOR_CALL   => TRUE,
                                              SESSION_PGA_LIMIT => 20);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN                   => 'erp_plan',
                                              GROUP_OR_SUBPLAN       => 'batch',
                                              COMMENT                => 'BATCH sessions',
                                              MGMT_P1                => 30,
                                              PARALLEL_SERVER_LIMIT  => 8,
                                              PARALLEL_QUEUE_TIMEOUT => 600,
                                              MAX_EST_EXEC_TIME      => 3600);
  DBMS_RESOURCE_MANAGER.CREATE_PLAN_DIRECTIVE(PLAN             => 'erp_plan',
                                              GROUP_OR_SUBPLAN => 'OTHER_GROUPS',
                                              COMMENT          => 'mandatory',
                                              MGMT_P1          => 10);
  DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA();
  DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
END;
/

END

相关推荐
Viktor_Ye16 分钟前
高效集成易快报与金蝶应付单的方案
java·前端·数据库
努力算法的小明1 小时前
SQL 复杂查询
数据库·sql
斗-匕1 小时前
MySQL 三大日志详解
数据库·mysql·oracle
代码中の快捷键1 小时前
MySQL数据库存储引擎
数据库·mysql
只因在人海中多看了你一眼1 小时前
数据库体系
数据库
尘浮生1 小时前
Java项目实战II基于微信小程序的电影院买票选座系统(开发文档+数据库+源码)
java·开发语言·数据库·微信小程序·小程序·maven·intellij-idea
六月闻君2 小时前
MySQL 报错:1137 - Can‘t reopen table
数据库·mysql
SelectDB技术团队2 小时前
兼顾高性能与低成本,浅析 Apache Doris 异步物化视图原理及典型场景
大数据·数据库·数据仓库·数据分析·doris
inventecsh2 小时前
mongodb基础操作
数据库·mongodb
白云如幻2 小时前
SQL99版链接查询语法
数据库·sql·mysql