Monday, 19 January 2015

How to kill the session in Oracle

As we know, while  performing any DDL and DML operations on oracle table, oracle database puts the lock on corresponding table, after successful query execution it will automatically release the lock on that table.

If we interrupt the query execution, the lock still remains on the table. So we can't perform any DML and DDL operation on the same table.

So before we are going to perform any DML or DDL operations, we should kill the session to unlock the table. Below is the procedure to kill session/unlock table.

first identify the object id for your table by using following query.   
SELECT * FROM dba_objects WHERE object_name='EMP';

in my case OBJECT_ID is 83603.

Now check the lock, if exist.

SELECT sid FROM v$lock WHERE id1=83603;

in my case sid value is 3341

if the above query didn't return any value means, there is no lock on that table.

SELECT sid, serial# FROM v$session WHERE sid=3341;

here sid=3341 and serial#=226371


Now we need to kill the session by using above values.

ALTER SYSTEM KILL SESSION '3341,226371' ;

once the session was killed, we can perform any type of valid operation on oracle table.




No comments:

Post a Comment