Solved

oracle session or table lock

Posted on 2008-06-20
3
910 Views
Last Modified: 2012-06-27
I am using Oracle 10g. Sometimes application got stuck due to deadlock. I want to find out from where it is got locked and other details of it. Is there any query for that to find it out?
0
Comment
Question by:siva_gk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 16

Expert Comment

by:Richard Olutola
ID: 21836858
Check the alert log which would point you to a trace file with all the details you require.

R.
0
 
LVL 48

Accepted Solution

by:
schwertner earned 500 total points
ID: 21836880
REM PURPOSE:
REM    The report generated by this script gives information on sessions
REM    which are holding locks and gives the information needed to kill
REM    using the ALTER SYSTEM KILL SESSION command.
REM ------------------------------------------------------------------------
REM Main text of script follows:
 
set linesize 180 pagesize 66
break on Kill on username on terminal
column Kill heading 'Kill String' format a13
column res heading 'Resource Type' format 999
column id1 format 9999990
column id2 format 9999990
column lmode heading 'Lock Held' format a20
column request heading 'Lock Requested' format a20
column serial# format 99999
column username  format a10  heading "Username"
column terminal heading Term format a10
column OSuser heading OSuser format a15
column machine heading Machine format a10
column tab format a35 heading "Table Name"
column owner format a9
column Address format a18
select      nvl(S.USERNAME,'Internal') username,
      nvl(S.TERMINAL,'None') terminal,
        nvl(S.MACHINE,'None') machine,
        nvl(S.OSUSER,'None') OSuser,    
      L.SID||','||S.SERIAL# Kill,
      U1.NAME||'.'||substr(T1.NAME,1,20) tab,
      decode(L.LMODE,1,'No Lock',
            2,'Row Share',
            3,'Row Exclusive',
            4,'Share',
            5,'Share Row Exclusive',
            6,'Exclusive',null) lmode,
      decode(L.REQUEST,1,'No Lock',
            2,'Row Share',
            3,'Row Exclusive',
            4,'Share',
            5,'Share Row Exclusive',
            6,'Exclusive',null) request
from      V$LOCK L,  
      V$SESSION S,
      SYS.USER$ U1,
      SYS.OBJ$ T1
where      L.SID = S.SID  
and      T1.OBJ# = decode(L.ID2,0,L.ID1,L.ID2)  
and      U1.USER# = T1.OWNER#
and      S.TYPE != 'BACKGROUND'
order by   username, terminal, machine, lmode
--order by 1,2,6
/



SHOWING ALSO THE SQL :


SET ECHO off
REM NAME:   TFSLKILL.SQL
REM USAGE:"@path/tfslkill"
REM ------------------------------------------------------------------------
REM REQUIREMENTS:
REM    SELECT on V$LOCK, V$SESSION, SYS.USER$, SYS.OBJ$
REM ------------------------------------------------------------------------
REM PURPOSE:
REM    The report generated by this script gives information on sessions
REM    which are holding locks and gives the information needed to kill
REM    using the ALTER SYSTEM KILL SESSION command.
REM ------------------------------------------------------------------------
REM Main text of script follows:
 
set linesize 300 pagesize 66
break on Kill on username on terminal
column Kill heading 'Kill String' format a13
column res heading 'Resource Type' format 999
column id1 format 9999990
column id2 format 9999990
column lmode heading 'Lock Held' format a20
column request heading 'Lock Requested' format a20
column serial# format 99999
column username  format a10  heading "Username"
column terminal heading Term format a10
column OSuser heading OSuser format a15
column machine heading Machine format a10
column tab format a35 heading "Table Name"
column owner format a9
column Address format a18
column sql format a135 heading "S  Q  L"
select      nvl(S.USERNAME,'Internal') username,
      nvl(S.TERMINAL,'None') terminal,
        nvl(S.MACHINE,'None') machine,
        nvl(S.OSUSER,'None') OSuser,    
      L.SID||','||S.SERIAL# Kill,
      U1.NAME||'.'||substr(T1.NAME,1,20) tab,
      decode(L.LMODE,1,'No Lock',
            2,'Row Share',
            3,'Row Exclusive',
            4,'Share',
            5,'Share Row Exclusive',
            6,'Exclusive',null) lmode,
      decode(L.REQUEST,1,'No Lock',
            2,'Row Share',
            3,'Row Exclusive',
            4,'Share',
            5,'Share Row Exclusive',
            6,'Exclusive',null) request,
        sql. sql_text SQL  
from      V$LOCK L,  
      V$SESSION S,
      SYS.USER$ U1,
      SYS.OBJ$ T1,
        v$sqltext sql
where      L.SID = S.SID  
and      T1.OBJ# = decode(L.ID2,0,L.ID1,L.ID2)  
and      U1.USER# = T1.OWNER#
and      S.TYPE != 'BACKGROUND'
and     sql.hash_value=s.sql_hash_value  
order by   username, terminal, machine
--order by 1,2,6
/

0
 

Author Comment

by:siva_gk
ID: 21843678
wow !!! thanks schwertner
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question