Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

oracle session or table lock

Posted on 2008-06-20
3
Medium Priority
?
916 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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 Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

609 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