?
Solved

oracle session or table lock

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
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 shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to recover a database from a user managed backup
Suggested Courses

765 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