The document provides a solution to automatically kill inactive sessions using the Resource Manager after a period of idle time. It outlines the steps to create a resource plan called "TEST_PLAN" with consumer groups "LONG_RUNNING" and "SHORT_RUNNING" that limit idle time to 5 and 1 minute respectively. The plan is validated, submitted and made the active plan. Testing confirms a session locked on a table is killed after being idle for over 1 minute, releasing the lock.
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
How To Automatically Kill Inactive Sessions using Resource Manager
1. How To Automatic Kill Inactive Sessions using
Resource Manager (Doc ID 1935739.1)
To
Bottom
In this Document
Goal
Solution
References
APPLIES TO:
Oracle Database - Enterprise Edition - Version 11.2.0.1 to 12.1.0.2 [Release 11.2 to
12.1]
Information in this document applies to any platform.
***Checked for relevance on 23-May-2016***
GOAL
Database server crashed after memory on server used by inactive sessions
SOLUTION
The Following Example used to illustrate the scenario for User SH , please Review and
modify whatever needed
to confirm Automatic Kill of the Huge number of Inactive Sessions after a period of Idle
Time .
1.CREATE THE PLAN
begin
dbms_resource_manager.create_pending_area();
end;
/
begin
2. dbms_resource_manager.create_plan( plan => 'TEST_PLAN', comment =>
'Resource plan/method for Idle
time kill sessions');
end;
/
2.CREATE THE CONSUMER GROUPS
begin
dbms_resource_manager.create_consumer_group( consumer_group =>
'LONG_RUNNING',
comment =>'Privileged Users');
dbms_resource_manager.create_consumer_group( consumer_group =>
'SHORT_RUNNING',
comment => 'Under Privileged Users');
end;
/
3.CREATE DIRECTIVES FOR THE PLAN
begin
dbms_resource_manager.create_plan_directive( plan => 'TEST_PLAN',
group_or_subplan =>
'LONG_RUNNING', comment => 'Limit idle time to 5 minutes',
max_idle_time => 300);
dbms_resource_manager.create_plan_directive( plan => 'TEST_PLAN',
group_or_subplan =>
'SHORT_RUNNING', comment => 'Limit idle time to 1 minute',
max_idle_time => 60);
dbms_resource_manager.create_plan_directive( plan => 'TEST_PLAN',
group_or_subplan =>
'OTHER_GROUPS', comment => 'Limit idle time to 1 Hour', max_idle_time
=> 3600);
end;
/
4.VALIDATE AND SUBMIT THE PLAN
begin
dbms_resource_manager.validate_pending_area();
end;
3. /
begin
dbms_resource_manager.submit_pending_area();
end;
/
5.ALLOW CONSUMER GROUP SWITCHING
begin
dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name
=> 'SYSTEM',
consumer_group => 'LONG_RUNNING', grant_option => FALSE);
dbms_resource_manager_privs.grant_switch_consumer_group(grantee_name
=> 'SH',
consumer_group => 'SHORT_RUNNING', grant_option => FALSE);
end;
/
6.ASSIGN DATABASE USERS A DEFAULT INITIAL CONSUMER GROUP AT CONNECTION
TIME
For Example :
A)User SYSTEM is made member of the group LONG_RUNNING
B)User SH is made member of the group SHORT_RUNNING
begin
dbms_resource_manager.create_pending_area();
end;
/
begin
dbms_resource_manager.set_initial_consumer_group( user => 'SYSTEM',
consumer_group => 'LONG_RUNNING');
dbms_resource_manager.set_initial_consumer_group( user => 'SH',
consumer_group => 'SHORT_RUNNING');
end;
/
begin
dbms_resource_manager.validate_pending_area();
end;
4. /
begin
dbms_resource_manager.submit_pending_area();
end;
/
7.MAKE THE NEW PLAN THE ACTIVE ONE FOR THE DATABASE
SQL> alter system set resource_manager_plan=’TEST_PLAN’;
This query will show the sessions that are killed when the idle time thresholds set for
the plan are crossed.
SQL> select NAME, ACTIVE_SESSIONS_KILLED, IDLE_SESSIONS_KILLED
FROM V$RSRC_CONSUMER_GROUP WHERE NAME='SHORT_RUNNING';
SQL>select SID,MODULE,STATUS
from V$session where USERNAME='SH';
SID MODULE
---------- ----------------------------------------------------------------
STATUS
--------
365 SQL*Plus
KILLED
Testing for the release of resources :
From Session 1:
SQL>conn sh/sh ;
Connected.
5. SQL>create table con_tab ( a varchar2(34));
Table created.
15:11:40 SQL>lock table con_tab in exclusive mode ;
Table(s) Locked.
From Session 2
SQL>select SID,MODULE,STATUS
from V$session where USERNAME='SH'
15:12:04 SYS@Farag11203>/
SID MODULE
---------- -----------------------------------------------------------
-----
STATUS
--------
5 SQL*Plus
INACTIVE
15:12:28 SYS@Farag11203>/
SID MODULE
---------- -----------------------------------------------------------
-----
STATUS
--------
5 SQL*Plus
KILLED
15:18:26 SQL>conn sh/sh
Connected.
15:18:35 SQL>alter table con_tab add c number;
Table altered.
6. From the above Test for sh session that was locking table con_tab in exclusive mode on
session 1.
the session have a status of inactive for more than 60 seconds (idle)
after the seconds it changed to a status of KILLED and afterwards a conenction
using session 2 to sh/sh would be able to acquire exclusive reourse on the same table ,
which confirmed that the lock table resources has been released .
To delete the plan .
Deleting a Plan
The DELETE_PLAN procedure deletes the specified plan as well as all the plan directives
associated with it. The pending area must be created first, and then submitted after the plan is
deleted.
The following PL/SQL block deletes the great_bread plan and its directives.
BEGIN
DBMS_RESOURCE_MANAGER.DELETE_PLAN(PLAN => 'great_bread');
END;
/
+
To delete consumer group
DBMS_RESOURCE_MANAGER.DELETE_CONSUMER_GROUP (
consumer_group IN VARCHAR2);
please refer the below
http://docs-uat1.us.oracle.com/cd/E11882_01/server.112/e25494/dbrm.htm#ADMIN11898
https://docs.oracle.com/cd/A91202_01/901_doc/appdev.901/a89852/dbms_r9a.htm
Thanks & Regards,
Shekar Tuduru,
Shift time: 7 AM to 3:30 PM (IST),
7. Desk Phone: +91 80 41072313,
Oracle Customer Support.
If you need assistance during my off-shift hours, please call the Oracle HUB and request for
reassignment of this SR.
Contact number of HUB : http://www.oracle.com/support/contact.html (1.800.223.1711)