Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unlock An Oracle Table

What are the different techniques for Unlocking an oracle table?

What I Tried.

  1. Get the object ID of the locked table:

    SELECT object_id FROM dba_objects WHERE object_name='YOUR TABLE NAME';

  2. Get the SID values for this ID:

    SELECT sid FROM v$lock WHERE id1=OBJECT ID FROM STEP1

  3. Get the session values for these SIDs:

    SELECT sid, serial# from v$session where sid in (COMMA SEPARATED LIST OF SIDs FROM STEP2.)

  4. 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.

like image 976
smali Avatar asked Feb 23 '15 06:02

smali


People also ask

How do you break a table lock in Oracle?

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.

How do you unlock a table in SQL?

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.

Why are tables locked in Oracle?

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.


2 Answers

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. 
like image 93
Vinoth Kumar Avatar answered Nov 05 '22 23:11

Vinoth Kumar


You can also try to execute just

COMMIT;

or

ROLLBACK;

in this session.

like image 24
Viacheslav Plekhanov Avatar answered Nov 05 '22 22:11

Viacheslav Plekhanov