Wednesday, November 9, 2011

Oracle session time out when it trying to drop or create and replace object

If something is locked it can not be dropped or create or replace. The error message make it seem as if it is timed out.

One solution is to wait and eventually the lock might be resolved.
In the past I have resolved this my restarting the instance. I did not know what the real problem was.


A more elegant solution is to provided here

Killing an oracle session to remove a lock

 I will copy the queries in case the post is lost:

Identifying the locks:

  1. SELECT  l.inst_id,  
  2. SUBSTR(L.ORACLE_USERNAME,1,8) ORA_USER,   
  3. SUBSTR(L.SESSION_ID,1,3) SID,  
  4. S.serial#,  
  5. SUBSTR(O.OWNER||'.'||O.OBJECT_NAME,1,40) OBJECT, P.SPID OS_PID,  
  6. DECODE(L.LOCKED_MODE,   0,'NONE',  
  7. 1,'NULL',  
  8. 2,'ROW SHARE',  
  9. 3,'ROW EXCLUSIVE',  
  10. 4,'SHARE',  
  11. 5,'SHARE ROW EXCLUSIVE',  
  12. 6,'EXCLUSIVE',  
  13. NULL) LOCK_MODE  
  14. FROM    sys.GV_$LOCKED_OBJECT L  
  15. , DBA_OBJECTS O  
  16. , sys.GV_$SESSION S  
  17. , sys.GV_$PROCESS P  
  18. WHERE     L.OBJECT_ID = O.OBJECT_ID  
  19.   and     l.inst_id = s.inst_id  
  20.   AND     L.SESSION_ID = S.SID  
  21.   and     s.inst_id = p.inst_id  
  22.   AND     S.PADDR = P.ADDR(+)  
  23. order by l.inst_id
Kill the session:

ALTER SYSTEM KILL SESSION 'sid,serial#' IMMEDIATE; 

The hard part here is to realize to check whether there is a lock.

No comments:

Post a Comment