What are the different techniques for Unlocking an oracle table?
What I Tried.
Get the object ID of the locked table:
SELECT object_id FROM dba_objects WHERE object_name='YOUR TABLE NAME';
Get the SID values for this ID:
SELECT sid FROM v$lock WHERE id1=OBJECT ID FROM STEP1
Get the session values for these SIDs:
SELECT sid, serial# from v$session where sid in (COMMA SEPARATED LIST OF SIDs FROM STEP2.)
Kill the sessions causing the lock:
ALTER SYSTEM KILL SESSION (SID,SERIAL#)
pair values from step 3
e.g. ALTER SYSTEM KILL SESSION '231,23454'
But The Problem is I have lot of tables which has been locked is there any other technique for unlocking the tables.
I am using SQLDeveloper Is there any direct option for unlocking it.
Answer: The only way to release a lock on an Oracle table is to kill the session that is holding the lock, or wait for the transaction to complete.
Use sys. dm_exec_requests and/or sys_dm_tran_locks. The way to 'unlock' a table is to kill the connection holding the lock, or wait for that connection to finish what it's doing and let SQL release the locks.
A locked table remains locked until you either commit your transaction or roll it back, either entirely or to a savepoint before you locked the table. A lock never prevents other users from querying the table. A query never places a lock on a table.
Option 1:
Well, one of the options is to rollback the locked SQL statement. For an instance,
lock table table1 in exclusive mode; -- is what you should've used to lock the table.
To unlock: rollback;
Option 2:
To find username and sid:
select * from v$locked_object;
To find serial# using sid:
select * from v$session where sid= put the sid you found on v$locked_object;
To kill session:
alter system kill session 'sid, serial#'; -- Execute this command as sysdba as normal user won't have privilege.
You can also try to execute just
COMMIT;
or
ROLLBACK;
in this session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With