-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathresmgr.sql
More file actions
87 lines (74 loc) · 2.11 KB
/
resmgr.sql
File metadata and controls
87 lines (74 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
REM
REM Standard disclaimer - anything in here can be used at your own risk.
REM
REM It is possible you'll need to edit the script for correct usernames/passwords, missing information etc.
REM
REM No warranty or liability etc etc etc. See the license file in the git repo root
REM
REM *** USE AT YOUR OWN RISK ***
REM
conn /@MYDB as sysdba
begin
dbms_resource_manager.create_pending_area();
-- create a consumer group that users will sit in
--
dbms_resource_manager.create_consumer_group(
consumer_group=>'CANCEL_ON_LONG_EXECUTION',
comment=>'Consumer group that will keep an eye on statement execution'
);
-- and we need a resource plan
--
dbms_resource_manager.create_plan(
PLAN=> 'EXECUTION_TIME_LIMIT',
comment=>'Kill statements after exceeding total execution time'
);
-- create a plan directive for that consumer group
-- the plan will cancel the current SQL if it runs for more than '10' sec
--
dbms_resource_manager.create_plan_directive(
plan=> 'EXECUTION_TIME_LIMIT',
group_or_subplan=>'CANCEL_ON_LONG_EXECUTION',
comment=>'Kill statement after exceeding total execution time',
switch_group=>'CANCEL_SQL',
switch_time=>10,
switch_estimate=>false,
switch_for_call=>true
);
-- fallback bucket for non-impacted users
--
dbms_resource_manager.create_plan_directive(
plan=> 'EXECUTION_TIME_LIMIT',
group_or_subplan=>'OTHER_GROUPS',
comment=>'leave others alone'
);
dbms_resource_manager.validate_pending_area;
dbms_resource_manager.submit_pending_area();
end;
/
clear screen
-- allow SCOTT to be put into this group
--
begin
dbms_resource_manager_privs.grant_switch_consumer_group(
'SCOTT',
'CANCEL_ON_LONG_EXECUTION',
false);
end;
/
-- activate our plan
--
alter system set
resource_manager_plan ='EXECUTION_TIME_LIMIT';
clear screen
conn scott/tiger@MYDB
-- switch SCOTT into the time limit group
--
declare
l_cg varchar2(100);
begin
dbms_session.switch_current_consumer_group('CANCEL_ON_LONG_EXECUTION',l_cg,true);
end;
/
set timing on
select count(*) from all_source;
select count(*) from all_source,all_source;