Sometimes our session or a few DB objects get locked. Use the below queries to deal with it:
BEGIN
FOR r IN (select sid,serial# from v$session where username = 'USER')
LOOP
EXECUTE IMMEDIATE 'alter system kill session ''' || r.sid
|| ',' || r.serial# || '''';
END LOOP;
END;
select * from v$session where osuser='<Operating System User>';
select * from DBA_LOCKS ;
select * from dba_ddl_locks where name like 'DB Object Name';
select * from DBA_LOCKS where session_id in (select session_id from dba_ddl_locks where name like 'DB Object Name')
select * from v$session where sid in (select session_id from dba_ddl_locks where name like 'DB Object Name');
alter system kill session '876,55576'; --Give SID and Serial#
select * from DBA_LOCKS where session_id in (select sid from v$session where status='INACTIVE')
How to Check the Locked Object Details
Lock related queries :
SELECT XIDUSN,OBJECT_ID,SESSION_ID,OR
SELECT d.OBJECT_ID, substr(OBJECT_NAME,1,20), l.SESSION_ID, l.ORACLE_USERNAME, l.LOCKED_MODE
from v$locked_object l, dba_objects d
where d.OBJECT_ID=l.OBJECT_ID;
SELECT ADDR, KADDR, SID, TYPE, ID1, ID2, LMODE, BLOCK from v$lock;
SELECT a.sid, a.saddr, b.ses_addr, a.username, b.xidusn, b.used_urec, b.used_ublk
FROM v$session a, v$transaction b
WHERE a.saddr = b.ses_addr;
SELECT s.sid, l.lmode, l.block, substr(s.username, 1, 10), substr(s.schemaname, 1, 10),
substr(s.osuser, 1, 10), substr(s.program, 1, 30), s.command
FROM v$session s, v$lock l
WHERE s.sid=l.sid;
SELECT p.spid, s.sid, p.addr,s.paddr,substr(s.userna
s.command,substr(s.osuser, 1, 10), substr(s.machine, 1, 10)
FROM v$session s, v$process p
WHERE s.paddr=p.addr
SELECT sid, serial#, command,substr(username, 1, 10), osuser, sql_address,LOCKWAIT,
to_char(logon_time, 'DD-MM-YYYY;HH24:MI'), substr(program, 1, 30)
FROM v$session;
SELECT sid, serial#, username, LOCKWAIT from v$session;
SELECT v.SID, v.BLOCK_GETS, v.BLOCK_CHANGES, w.USERNAME, w.OSUSER, w.TERMINAL
FROM v$sess_io v, V$session w
WHERE v.SID=w.SID ORDER BY v.SID;
SELECT * from dba_waiters;
SELECT waiting_session, holding_session, lock_type, mode_held
FROM dba_waiters;
SELECT
p.spid unix_spid,
s.sid sid,
p.addr,
s.paddr,
substr(s.username, 1, 10) username,
substr(s.schemaname, 1, 10) schemaname,
s.command command,
substr(s.osuser, 1, 10) osuser,
substr(s.machine, 1, 25) machine
FROM v$session s, v$process p
WHERE s.paddr=p.addr
ORDER BY p.spid;
Comments
Post a Comment