用資源管理器限制大資料量查詢

2022-05-04 19:48:34 字數 4886 閱讀 7074

最近生產庫上經常因為一些查詢賬號登陸資料倉儲,做了大資料量查詢,sql語句甚至不帶條件,嚴重拖累了資料庫效能,

因此我增加了resource manager限制這些查詢賬號的最大執行時間,以及cpu使用率,目的是降低這些賬號查詢對資料庫正常業務的影響。

1.資源管理器建立的步驟:

step 1: create a pending area.

step 2: create, modify, or delete consumer groups.

step 3: create the resource plan.

step 4: create resource plan directives.

step 5: validate the pending area.

step 6: submit the pending area.

2.我的建立指令碼

begin

dbms_resource_manager.create_pending_area();

/* create consumer groups.

* by default, users start in other_groups, which is automatically

* created for every database.

*/dbms_resource_manager.create_consumer_group(

'main_group',

'rptdw main users group');

dbms_resource_manager.create_consumer_group(

'query_group',

'using for query users ,limit parallel threads and cpu consume percentage');

/* create a plan to manage these consumer groups */

dbms_resource_manager.create_plan(

'rptdw_plan',

'plan for limit long-running queries and too many parallel querys');

dbms_resource_manager.create_plan_directive(

'rptdw_plan', 'other_groups', 'directive for rptdw system users activity',

mgmt_p1 => 100);

dbms_resource_manager.create_plan_directive(

'rptdw_plan', 'query_group', 'directive for query users activity',

mgmt_p2 => 80,

parallel_degree_limit_p1 => 2,

max_est_exec_time => 120);

dbms_resource_manager.validate_pending_area();

dbms_resource_manager.submit_pending_area();

end;

/3.如果中間報錯,需要清空懸掛區。

begin

dbms_resource_manager.clear_pending_area();

end;

/4,到所有rac的節點用sys使用者執行,讓資源管理器計畫生效。

alter system set resource_manager_plan = rptdw_plan ;

5.我想把以下資料庫賬號加入新建的資源計畫的query_group消費組

support

frombi

main1

main4

main_dba

mread_q

ops$mon

boco4a

report1

執行成功

pl/sql procedure successfully completed

我想把其他資料庫賬號加入消費組other_groups

det6.給賬號分配許可權,然後修改這些賬號的初始化的消費者組

begin

dbms_resource_manager_privs.grant_system_privilege(grantee_name=>'main2',admin_option=>true);

end;

/begin

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name =>'support',consumer_group =>'query_group',grant_option => false);

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name =>'frombi',consumer_group =>'query_group',grant_option => false);

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name =>'main1',consumer_group =>'query_group',grant_option => false);

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name =>'main4',consumer_group =>'query_group',grant_option => false);

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name =>'main_dba',consumer_group =>'query_group',grant_option => false);

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name =>'mread_q',consumer_group =>'query_group',grant_option => false);

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name =>'ops$mon',consumer_group =>'query_group',grant_option => false);

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name =>'boco4a',consumer_group =>'query_group',grant_option => false);

dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name =>'main2',consumer_group =>'query_group',grant_option => false);

end;

/begin

dbms_resource_manager.set_initial_consumer_group('support','query_group');

dbms_resource_manager.set_initial_consumer_group('frombi','query_group');

dbms_resource_manager.set_initial_consumer_group('main1','query_group');

dbms_resource_manager.set_initial_consumer_group('main4','query_group');

dbms_resource_manager.set_initial_consumer_group('main_dba','query_group');

dbms_resource_manager.set_initial_consumer_group('mread_q','query_group');

dbms_resource_manager.set_initial_consumer_group('ops$mon','query_group');

dbms_resource_manager.set_initial_consumer_group('boco4a','query_group');

dbms_resource_manager.set_initial_consumer_group('main2','query_group');

end;

/7.回頭看了最大執行時間2分鐘,感覺太少了,修改消費組query_group的計畫指導

begin

dbms_resource_manager.clear_pending_area();

dbms_resource_manager.create_pending_area();

dbms_resource_manager.update_plan_directive(

plan                  => 'rptdw_plan',

group_or_subplan      => 'query_group',

new_max_est_exec_time => 1800

);dbms_resource_manager.submit_pending_area();

end;

/8.測試一下

用限制賬號main2登陸,執行

select count(*) from report1.t_f_uservisit_plt

報錯:ora-07455: 估計執行時間(119039秒)超出了限制(1800秒)

資源管理器生效。

資源管理器

using system using system.collections.generic using system.linq using system.text using system.threading.tasks namespace day 09 小型資源管理器 檔案長度 public st...

簡單資源管理器

下面共享乙個我自己的資源管理器,很簡單的,看起來也明白,主要是我是新手,不想寫的太複雜,自己專案使用的好用,便是最好的。using unityengine using system.collections using system.collections.generic using system p...

Windows資源管理器

在資源管理器中,選定多個非連續檔案的操作為 a 按住shift鍵,單擊每乙個要選定的檔案圖示 b 按住ctrl鍵,單擊每乙個要選定的檔案圖示 c 先選中第乙個檔案,按住shift鍵,再單擊最後乙個要選定的檔案圖示 d 先選中第乙個檔案,按住ctrl鍵,再單擊最後乙個要選定的檔案圖示 檔案abc.bm...