// // How To Automatic Kill Inactive Sessions using Resource Manager

A technical troubleshooting blog about Oracle with other Databases & Cloud Technologies.

How To Automatic Kill Inactive Sessions using Resource Manager

2 min read
Database server crashed after memory on server used by inactive sessions

The Following Example used to illustrate the scenario for User XX, 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
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;
/

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 => 'XX',
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 XX 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 => 'XX',
consumer_group => 'SHORT_RUNNING');
end;
/


begin
dbms_resource_manager.validate_pending_area();
end;
/


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='XX';

  SID     MODULE       STATUS
---------------------------------
  365     SQL*Plus         KILLED