Slides from Openworl 2019. A look at how to safely (and unsafely) kill sessions in the Oracle database, and how to perhaps avoid killing them altogether.
5. 17/09/2019
5
The following is intended to outline our general product direction. It is intended for information purposes only,
and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or
functionality, and should not be relied upon in making purchasing decisions. The development, release,
timing, and pricing of any features or functionality described for Oracle’s products may change and remains at
the sole discretion of Oracle Corporation.
Statements in this presentation relating to Oracle’s future plans, expectations, beliefs, intentions and prospects
are “forward-looking statements” and are subject to material risks and uncertainties. A detailed discussion of
these factors and other risks that affect our business is contained in Oracle’s Securities and Exchange
Commission (SEC) filings, including our most recent reports on Form 10-K and Form 10-Q under the heading
“Risk Factors.” These filings are available on the SEC’s website or on Oracle’s website
at http://www.oracle.com/investor. All information in this presentation is current as of September 2019 and
Oracle undertakes no duty to update any statement in light of new information or future events.
Safe Harbor
10
if it's not in the documentation
- contact Support
- clarify usage before proceeding
9
10
11. 17/09/2019
11
SQL> select sid, last_call_et, status,
3 from v$session s;
SID LAST_CALL_ET STATUS
---------- ------------ ----------
39 7376 ACTIVE
40 412 INACTIVE
44 421 INACTIVE
...
...
22
what most of us do
21
22
37. 17/09/2019
37
SQL> set feedback on sql_id
SQL> set timing on
SQL> select count(*) from scott.emp, scott.emp, scott.emp,
2 ( select 1 from dual connect by level <= 100000 );
COUNT(*)
----------
274400000
1 row selected.
SQL_ID: dcrqdagwxagth
Elapsed: 00:00:15.72
SQL> declare
2 q varchar2(30);
3 begin
4 q := dbms_sqlq.create_quarantine_by_sql_id(sql_id => 'dcrqdagwxagth');
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> select count(*) from scott.emp, scott.emp, scott.emp,
2 ( select 1 from dual connect by level <= 100000 );
*
ERROR at line 1:
ORA-56955: quarantined plan used
87
88
38. 17/09/2019
38
89
automatic via resource manager
SQL> begin
2 dbms_resource_manager.create_pending_area();
3
4 -- switch into this group before running a possibly
5 -- long running SQL statement
6
7 dbms_resource_manager.create_consumer_group(
8 CONSUMER_GROUP=>'CG_EXEC_TIME_LIMIT_CANCEL',
9 COMMENT=>'Limited execution time per statement'
10 );
11
12 -- and we need a resource plan
13
14 dbms_resource_manager.create_plan(
15 PLAN=> 'EXEC_TIME_LIMIT',
16 COMMENT=>'Kill statement after exceeding total execution time'
17 );
18
[cont]
89
90
39. 17/09/2019
39
19 -- now create a plan directive for that special user group
20 -- to cancel current SQL if it runs for more than 'n' sec
21
22 dbms_resource_manager.create_plan_directive(
23 PLAN=> 'EXEC_TIME_LIMIT',
24 GROUP_OR_SUBPLAN=>'CG_EXEC_TIME_LIMIT_CANCEL',
25 COMMENT=>'Kill statement after exceeding total execution time',
36 SWITCH_GROUP=>'CANCEL_SQL',
37 SWITCH_TIME=>10,
38 SWITCH_ESTIMATE=>false,
39 SWITCH_FOR_CALL=> TRUE
40 );
41
42 DBMS_RESOURCE_MANAGER.VALIDATE_PENDING_AREA;
43
44 DBMS_RESOURCE_MANAGER.SUBMIT_PENDING_AREA();
45
46 end;
47 /
PL/SQL procedure successfully completed.
SQL> select count(*) from emp, emp, emp,
2 ( select 1 from dual connect by level <= 50000 );
COUNT(*)
----------
27440000
Elapsed: 00:00:04.11
SQL> select count(*) from emp, emp, emp,
2 ( select 1 from dual connect by level <= 1000000 );
ERROR at line 1:
ORA-00040: active time limit exceeded - call aborted
Elapsed: 00:00:12.00
91
92
40. 17/09/2019
40
SQL> select count(*) from scott.emp, scott.emp, scott.emp,
2 ( select 1 from dual connect by level <= 100000 );
*
ERROR at line 1:
ORA-56955: quarantined plan used
94
wrap up
93
94
42. 17/09/2019
42
97
... be gentle :-)
98
Ten Amazing SQL Features
Monday, September 16, 02:30 PM - 03:15 PM, Moscone South - Room 203
Proven Ways to Make Applications Slower and Less Secure [THT4796]
Tuesday, September 17, 04:30 PM - 04:50 PM, The Exchange - Theater 3
The Best Oracle Database Feature Ever Invented [THT4798]
Wednesday, September 18, 10:15 AM - 10:35 AM, The Exchange - Theater 3
Flashback - Not Just for DBAs
Wednesday, September 18, 04:00 PM - 04:45 PM, Moscone South - Room 306
PL/SQL: Still the Best Data Access Language
Thursday, September 19, 12:15 PM - 01:00 PM, Moscone South - Room 155A
97
98
43. 17/09/2019
43
99
Have a great OpenWorld !
youtube youtube.com/c/ConnorMcDonaldOracle
blog connor-mcdonald.com
twitter @connor_mc_d
99