Tuesday, July 21, 2015

Oracle: Check User Locks

sqlplus system/******** <<ENDSQL> /dev/null
clear buffer
set feedback off
set pause off
column USERID FORMAT A9;
column SID FORMAT 6;
column USER_B FORMAT A9;
column SID_B FORMAT 6;
spool $HOME/userlocks
SELECT rtrim(DECODE(request,0,'Holder: ','Waiter: ')|| v1.sid ||' - ' ||V2.USERNAME) "Session",
       lmode,
       v1.request,
       v2.STATUS,
       v2.COMMAND,
       v2.PROCESS "OS PROCESS",
       v1.type
  FROM V\$LOCK V1,
       V\$SESSION V2
 WHERE (V1.id1, V1.id2, V1.type) IN (SELECT id1, id2, type
                                       FROM V\$LOCK
                                      WHERE request>0)
   AND V1.SID = V2.SID
 ORDER BY v1.id1, v1.request;
/

spool off
ENDSQL

No comments:

Post a Comment