Solved

oracle session or table lock

Posted on 2008-06-20
3
892 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
3 Comments
 
LVL 16

Expert Comment

by:rolutola
Comment Utility
Check the alert log which would point you to a trace file with all the details you require.

R.
0
 
LVL 47

Accepted Solution

by:
schwertner earned 500 total points
Comment Utility
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
Comment Utility
wow !!! thanks schwertner
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now