Locking SqlText

Hi,
I want to know the Sql Statement (DML) which needs to be commit / rollback and may cause the other sessions locking the record. In V$Session view's Sql_Id, I unable to find out the Id of this specific query (here I found Null Id for this query). Hope you guys will understand what I want.
Regards,
Danish

I think I already answered that, pretty definitively.
No, it's not possible.
Consider the following:
You have a session that executes some DML, making changes to the database. As a result, some locks are taken on those rows that have been modified. As part of that, the SQL was parsed, cached in the library cache, and assigned a SQL_ID, correct? For the duration of the execution of that SQL, the SQL_ID was associated with that SID, and that was visible in V$SESSION. But, SQL in Oracle is shared. Once your session is done executing it, it's no longer associated w/ that session, and some other session may also execute that SQL. It remains in the shared pool, in the library cache. And, under pressure, it may be aged out of the shared pool. Once it's no longer being executed, it's eligible to be flushed from the library cache. So, it's possible you execute a SQL statement, and it gets aged out of the library cache, even before those changes it imposed have been committed. There is no retained history of which SQLs were executed by which sessions.
The only possible (though, in my view, cumbersome) solution, would be to enable SQL_TRACE=true. This would capture all SQL that was executed by the session being traced. It's fine for test purposes, but it's probably not practical to do instance wide.
Hope that helps,
-Mark

Similar Messages

  • SQL Timeouts and Blocking Locks

    SQL Timeouts and Blocking Locks
    Just wanted to check in and see if anyone here has feedback on application settings, ColdFusion settings, JBOSS settings or other settings that could help to limit or remove SQL Timeouts and blocking locks on SID's.
    We're using MS SQL 2000 with JBOSS and IIS5.
    We've been seeing the following error in our logs that starts blocking locks in SQL:
    java.sql.SQLException: [newScale] [SQLServer JDBC Drive] [SQLServer] Lock request time out period exceeded.
    Once this happens, we're hosed until we remove the blocking SID in SQL.  These are the connections to the application.
    Any feedback would be great.  Thanks!

    Hi
    This is your exact solution:
    Select a.username, a.sid, a.serial#, b.id1, c.sql_text
    From v$session a, v$lock b, v$sqltext c
    Where b.id1 in( Select distinct e.id1
    from v$session d , v$lock e
    where d.lockwait = e.kaddr ) and
    a.sid = b.sid and
    c.hash_value = a.sql_hash_value and
    b.request =0;
    Thanks
    Sarju
    Oracle DBA
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by I'm clueless:
    Can someone give me the SQL statement to
    show if there are any blocking database locks and if so - which user is locking the Database?
    Thanks in Advance<HR></BLOCKQUOTE>
    null

  • How to find out the user who locked the record

    i can't delete a particular record from a table while executing the delete command its showing an error specifying
    that "ORA-02049: timeout: distributed transaction waiting for lock"
    syntax i used
    delete from <table_name> where <column_name>='<value>'

    Hi,
    select username,lockwait,process,sql_hash_value from v$session. Find the user who is having more lock wait
    See the lock wait has more value notedown has_value
    select sql_text from v$sqltext where has_value="Noted value " find the query whether your table is calling by the user.

  • SQL to show blocking locks

    Can someone give me the SQL statement to
    show if there are any blocking database locks and if so - which user is locking the Database?
    Thanks in Advance

    Hi
    This is your exact solution:
    Select a.username, a.sid, a.serial#, b.id1, c.sql_text
    From v$session a, v$lock b, v$sqltext c
    Where b.id1 in( Select distinct e.id1
    from v$session d , v$lock e
    where d.lockwait = e.kaddr ) and
    a.sid = b.sid and
    c.hash_value = a.sql_hash_value and
    b.request =0;
    Thanks
    Sarju
    Oracle DBA
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by I'm clueless:
    Can someone give me the SQL statement to
    show if there are any blocking database locks and if so - which user is locking the Database?
    Thanks in Advance<HR></BLOCKQUOTE>
    null

  • BC4J application causes DB locks with iAS 1.0.2.2

    Hi,
    We've deployed a BC4J JSP application to iAS. After a few (not
    more then 5!!) requests, the application seems to hang. At
    first, we thought it was iAS that didn't respond, but after a
    while we noticed DB sessions with a lockwait.
    We configured the BC4J samples and did a few tests. The result
    was the same: we had a lock after a few requests.
    Here are the details about the lock:
    select sid, lockwait,status, sql_hash_value, prev_hash_value
    from v$session
    where username ='BC4J'
    and sid in (29,30)
    SID LOCKWAIT STATUS SQL_HASH_VALUE PREV_HASH_VALUE
    29 INACTIVE 2784278226 2784278226
    30 38117E20 ACTIVE 1756791003 1334541938
    select * from dba_blockers
    HOLDING_SESSION
    29
    select sql_text from v$sqltext
    where hash_value = '2784278226' -- Hash value and Previous hash
    value blocker
    order by piece
    SQL_TEXT
    SELECT InventoryItem.ID, InventoryItem.NAME, InventoryItem.DESCR
    IPTION, InventoryItem.IMAGE, InventoryItem.PRICE, InventoryItem.
    ONHAND, InventoryItem.SUPPLIER_ID, InventoryItem.CATEGORY_ID FRO
    M INVENTORY_ITEM InventoryItem WHERE (category_id=8)
    select * from dba_waiters
    WAITING_SESSION HOLDING_SESSION LOCK_TYPE
    MODE_HELD
    MODE_REQUESTED
    LOCK_ID1
    LOCK_ID2
    30 29 Transaction
    Exclusive
    Share
    327705
    63779
    select sql_text from v$sqltext
    where hash_value = '1756791003' -- Hash value waiter
    order by piece
    SQL_TEXT
    INSERT INTO LINE_ITEM(STATUS,QUANTITY,BACKORDER,ITEM_ID,ORD_ID,
    DISCOUNT) VALUES (:1,:2,:3,:4,:5,:6)
    select sql_text from v$sqltext
    where hash_value = '1334541938' -- Previous hash value waiter
    order by piece
    SELECT LINE_ITEM_SEQ.NEXTVAL FROM DUAL
    So my question is: what is causing the lock? I'm doing an insert
    and a select?
    Regards,
    Philip

    Can someone respond please!
    I tried to run the Online Orders sample application on iAS 1.0.2.1 and 1.0.2.2. On both iAS versions, the sample application created a DB session for each request to the page addtocart.jsp. After 2 (sometimes 3) requests, one DB session has a lockwait and the application stops responding.
    This problem is easy to reproduce. Just create the BC4J schema, go to http://localhost:7778/onlineorders_html/main.jsp and try to add a few items in your shopping cart....
    Thanks!

  • How to find sql statement which generates LOCK

    Hello,
    In my plsql procedure i have used SELECT FOR UPDATE NO WAIT statement to avoid the current record used by another user.
    Actually i want to find which sqlquery is locking the Object other than my procedure.
    I can find the session id which is locking the object but i can not able to find sql text.
    How to find the SQL text from particular LOCKING Session id as v$sql or v$sqltext or v$sqlarea dont have session id?
    Any help can be appreciated.
    Thanks in advance.

    It's not necessarily that easy to find the statement that was responsible for the lock.
    It depends.
    First of all, it depends on version.
    If you're >= 10g and you're lucky and you're licensed for Diagnostic Pack, you might find it in ASH.
    If the statement that's responsible for the lock is also waiting on something else or runs for long enough, then ASH will almost certainly have it.
    Doug Burns has a 10-part series on the subject.
    http://oracledoug.com/serendipity/index.php?/archives/1477-Diagnosing-Locking-Problems-using-ASH-Part-1.html

  • LOCK 문제 해결을 위한 SCRIPT

    제품 : ORACLE SERVER
    작성날짜 : 2002-04-12
    LOCK 문제 해결을 위한 SCRIPT
    ============================
    Purpose
    Lock이 걸리는 여러가지 현상에 대한 확인과 조치 방법을 알아보자.
    Explanation
    1. LOCK 문제를 일으키는 SQL 명령 찾기
    (1) 다음 Query는 Lock과 관련된 transaction을 출력해준다.
    column username format a10
    column sid format 999
    column lock_type format a15
    column MODE_HELD format a11
    column MODE_REQUESTED format a10
    column LOCK_ID1 format a8
    column LOCK_ID2 format a8
    select a.sid,
    decode(a.type,
    'MR', 'Media Recovery',
    'RT', 'Redo Thread',
    'UN', 'User Name',
    'TX', 'Transaction',
    'TM', 'DML',
    'UL', 'PL/SQL User Lock',
    'DX', 'Distributed Xaction',
    'CF', 'Control File',
    'IS', 'Instance State',
    'FS', 'File Set',
    'IR', 'Instance Recovery',
    'ST', 'Disk Space Transaction',
    'IR', 'Instance Recovery',
    'TS', 'Temp Segment',
    'IV', 'Library Cache Invalidation',
    'LS', 'Log Start or Switch',
    'RW', 'Row Wait',
    'SQ', 'Sequence Number',
    'TE', 'Extend Table',
    'TT', 'Temp Table',
    a.type) lock_type,
    decode(a.lmode,
    0, 'None', /* Non Lock equivalent */
    1, 'Null', /* N */
    2, 'Row-S (SS)', /* L */
    3, 'Row-X (SX)', /* R */
    3, 'Row-X (SX)', /* R */
    4, 'Share', /* S */
    5, 'S/Row-X (SSX)', /* C */
    6, 'Exclusive', /* X */
    to_char(a.lmode)) mode_held,
    decode(a.request,
    0, 'None', /* Mon Lock equivalent */
    1, 'Null', /* N */
    2, 'Row-S (SS)', /* L */
    3, 'Row-X (SX)', /* R */
    4, 'Share', /* S */
    5, 'S/Row-X (SSX)', /* C */
    6, 'Exclusive', /* X */
    to_char(a.request)) mode_requested,
    to_char(a.id1) lock_id1, to_char(a.id2) lock_id2
    from v$lock a
    where (id1,id2) in
    (select b.id1, b.id2 from v$lock b where b.id1=a.id1 and
    b.id2=a.id2 and b.request>0);
    (2) 출력 결과
    SID LOCK_TYPE MODE_HELD MODE_REQUE LOCK_ID1 LOCK_ID2
    5 Transaction Exclusive None 262172 90
    6 Transaction None Exclusive 262172 90
    9 Transaction None Exclusive 262172 90
    SID 6과 9는 SID 5가 걸고 있는 Lock이 풀리기를 기다리고 있음을 알 수 있다.
    2. Lock 관련된 테이블 확인하기
    (1) 다음 Query는 Lock과 관련된 테이블을 출력해 준다.
    column username format a10
    column lockwait format a10
    column sql_text format a80
    column object_owner format a14
    column object format a15
    select b.username username, c.sid sid, c.owner object_owner,
    c.object object, b.lockwait, a.sql_text SQL
    from v$sqltext a, v$session b, v$access c
    where a.address=b.sql_address and
    a.hash_value=b.sql_hash_value and
    b.sid = c.sid and c.owner != 'SYS';
    (2) 출력결과
    USERNAME SID OBJECT_OWNER OBJECT LOCKWAIT
    SQL
    LTO2 6 LTO EMP C3D320F4
    update lto.emp set empno =25 where empno=7788
    LTO3 9 LTO EMP C3D320C8
    delete from lto.emp where empno=7788
    LTO 5 LTO DEPT
    insert into lto.dept values (60,'PROGRAMMER','LOS ANGELOS')
    여기서는 USERNAME에 나와있는 유저가 OBJECT에 나와있는 테이블을 수정하려고
    함을 나타낸다. LT02, LT03는 LT0가 Commit, Rollback 하기를 기다리고 있음을
    알 수 있다. 하지만 여기에는 가장 최근의 DML 명령 하나만 나와있기 때문에
    여기 나온 명령이 반드시 Lock을 걸고 있는 명령이라고 단정지을 수는 없다.
    3. LOCK과 관련된 프로세스 찾기
    (1) 다음 Query를 실행해 보면 프로세스와 관련된 정보를 얻을 수 있다.
    column "ORACLE USER" format a11
    column SERIAL# format 9999999
    column "OS USER" format a8
    select substr(s.username,1,11) "ORACLE USER", p.pid "PROCESS ID",
    s.sid "SESSION ID", s.serial#, osuser "OS USER",
    p.spid "PROC SPID",s.process "SESS SPID", s.lockwait "LOCK WAIT"
    from v$process p, v$session s, v$access a
    where a.sid=s.sid and
    p.addr=s.paddr and
    s.username != 'SYS';
    (2) 위의 Query를 실행하면 다음과 같은 결과가 출력된다.
    ORACLE PROCESS SESSION SERIAL# OS USER PROC SESS LOCKWT
    USER ID ID SPID SPID
    LTO 19 5 31 usupport 17312 17309
    LTO2 25 6 43 usupport 17313 17310 C3D320F4
    LTO3 26 9 1 usupport 17314 17311 C3D320D8
    (3) 조치 방법
    a. LTO에게 Commit, Rollback 할 것을 요구한다.
    b. SQLDBA>ALTER SYSTEM KILL SESSION '5,31';
    c. %kill -9 17309 (유닉스상의 Shadown Process)
    stop/id=<SESS SPID> (PROC SPID=SESS SPID on vms running single task)
    여기서 SYS 유저는 제외시켰는데 필요하다면 Query의 Where 조건에서
    s.username != 'SYS' 부분을 삭제하면 된다.
    4. CATBLOCK.SQL & UTLLOCKT.SQL
    $ORACLE_HOME/rdbms/admin 디렉토리에 있는 스크립트 가운데 catblock.sql과
    utllockt.sql을 사용하여서 Lock 상황을 쉽게 파악할 수 있다.
    (1) 실행 방법
    %cd $ORACLE_HOME/rdbms/admin
    %sqldba lmode=y (svrmgrl
    SVRMGR>connect internal
    SVRMGR>@catblock
    (2) 결과 확인
    column waiting_session format a8
    select lpad(' ',3*(level-1)) || waiting_session,
    lock_type,
    mode_requested,
    mode_held,
    lock_id1,
    lock_id1,
    lock_id2
    from lock_holders
    connect by prior waiting_session = holding_session
    start with holding_session is null;
    WAITING_ LOCK_TYPE MODE_REQUE MODE_HELD LOCK_ID1 LOCK_ID2
    5 None
    6 Transaction Exclusive Exclusive 262172 90
    9 Transaction Exclusive Exclusive 262172 90
    여기서 Session 6, Session 9가 Session 5를 기다리고 있음을 알 수 있다.
    5. Lock & Hanging 문제를 추정하는 방법
    프로그램 상에서 어느 부분이 Lock, Hanging 문제를 일으키는지 알아내기가
    여의치 않을때 다음과 같은 방법을 사용해 보기 바란다.
    (1) init<SID>.ora의 sql_trace=ture로 세팅하면 연관된 SQL 명령이 출력될
    것이다.
    (2) OS 상에서도 Process 상태를 점검하여 본다.
    (3) OS 상의 Debugging 기능을 사용하거나 만약 가능하다면 oradbx를 사용한다.
    Platform 에 따라서 없을 수도 있다.
    (4) 여러가지 Monitoring 방법과 Locking/Blocking 스크립트를 이용한다.
    6. PROCESS STACKS 확인
    때로는 Hanging Process나 리소스를 점유하고 있는 Process의 Process Stack을
    점검해 보는 것이 문제 해결에 도움이 되는 경우가 있다.
    (1) OS Debugging 프로그램을 이용하여 Hangup 되기 전의 마지막 Call을
    확인한다.
    ex)%truss -p <shadow pid>
    (2) oradbx(오라클 debugging 프로그램)은 Support,Development 시에만
    사용된다.
    (3) oradbx 사용예제
    select substr(s.username,1,11) "ORACLE USER" ,
    p.pid "PROCESS ID", s.sid "SESSION ID", s.serial#,
    osuser "OS USER", p.spid "PROC SPID"
    from v$session s, v$access a, v$process p
    where a.sid=s.sid and
    p.addr=s.paddr and
    s.username != 'SYS';
    위의 Query를 실행하면 다음과 같은 결과가 출력된다.
    ORACLE PROCESS SESSION SERIAL# OS USER PROC SESS LOCKWT
    USER ID ID SPID SPID
    LTO 19 5 31 usupport 17312 17309
    LTO2 25 6 43 usupport 17313 17310 C3D320F4
    LTO3 26 9 1 usupport 17314 17311 C3D320D8
    만약 oradbx가 없다면 다음과 같이 해서 만들어 준다.
    %cd $ORACLE_HOME/rdbms/lib
    %make -f oracle.mk oradbx
    LTO Process가 무엇을 하고 있는지 알고 싶으면 Process Stack을 보면 알수
    있다.
    ps -ef | grep 17312
    usupport 17312 17309 0 Sep 15 ? 0:00 oracleV713(DESCRIPTION=(LOCAL=YE
    type <oradbx>
    debug 17312 (이 유저의 oracle shadow process)
    dump stack
    dump procstat
    위에서 생성된 트레이스 화일(user_dump_dest 에 생성됨)을 이용하면
    Hanging 문제를 해결하는데 큰 도움이 된다.
    7. 자주 발생하는 LOCK 문제들
    (1) Parent-Child 관계로 묶인 테이블에서 Child 테이블에 Index가 없는
    상황에서 Child 테이블을 수정하게 되면 Parent테이블에 TABLE LEVEL
    SHARE LOCK이 걸리게 되어서 Parent 테이블에 대한 모든 Update가
    금지된다.
    (2) 블럭의 PCTFREE가 매우 작다면 한 블럭에 여러개의 레코드가 들어 있기
    때문에 한 블럭에 과도한 트랜잭션이 들어와서 블럭의 Transaction
    Layer가 Release 되기를 기다리게 되는 경우도 있다.
    (3) 예제
    create table test (a number) initrans 1 maxtrans 1;
    SYSTEM: insert into test values (5); /* completed */
    SCOTT: insert into SYSTEM.test values (10); /* Scott waits */
    SID OWNER LOCK_TYPE MODE_HELD MODE_REQUE LOCK_ID1 LOCK_ID2
    7 System Transaction Exclusive None 196639 54
    10 Scott Transaction None Share 196639 54

  • How to see lock in oracle 10g

    hi,
    i m working on an application made in oracle 10g developer, & database is oracle 10g on aix ,
    some times i get some problem when user save any data through forms it gets hanged ,
    so tell me how to get rid of it , when i try to do it from sql navigator i see massges session is busy .
    so y this eror i m getting & how to resolve it.
    thxs

    Here you have some scripts:
    rem
    rem FUNCTION: Report all DB locks
    rem
    column osuser format a15 heading 'User'
    column session_id heading 'SID'
    column mode_held format a20 heading 'Mode|Held'
    column mode_requested format a20 heading 'Mode|Requested'
    column lock_id1 format a10 heading 'Lock|ID1'
    column lock_id2 format a10 heading 'Lock|ID2'
    column type heading 'Type|Lock'
    set feedback off echo off pages 59 lines 131
    start title132 'Report on All Locks'
    spool rep_out\&db\locks
    select nvl(a.osuser,'SYS') osuser,b.session_id,type,
    mode_held,mode_requested,
    lock_id1,lock_id2
    from sys.v_$session a, sys.dba_locks b
    where
    a.sid=b.session_id
    order by 2
    spool off
    pause press enter/return to continue
    clear columns
    set feedback on echo on pages 22 lines 80
    set headingsep ='|'
    set lines 160
    set pagesize 20
    ttitle 'Database Locking Conflict Report'
    btitle 'Mode Held = indicates the user holding the lock|Mode Request = indicates the user waiting on the later to finish to establish lock||** End of Locking Conflict Report **'
    column username      format a10     heading 'User'
    column terminal      format a15     heading 'Application|PC'
    column object           format a15     heading     'Table'
    column sql            format a15     heading 'SQL'
    column sid           format 999     heading 'SID'
    column lock_type      format a15     heading 'Lock|Type'
    column mode_held      format a11     heading 'Mode|Held'
    column mode_requested      format a10     heading 'Mode|Request'
    column lock_id1      format a8     heading 'Lock ID1'
    column lock_id2      format a8     heading 'Lock ID2'
    column first_load_time  format a19     heading 'Requested'
    break on lock_id1
    select a.sid,
           username,
           terminal,
           decode(a.type,'MR', 'Media Recovery',
                      'RT', 'Redo Thread',
                   'UN', 'User Name',
                   'TX', 'Transaction',
                   'TM', 'DML',
                   'UL', 'PL/SQL User Lock',
                   'DX', 'Distributed Xaction',
                     'CF', 'Control File',
                   'IS', 'Instance State',
                   'FS', 'File Set',
                   'IR', 'Instance Recovery',
                   'ST', 'Disk Space Transaction',
                   'IR', 'Instance Recovery',
                   'ST', 'Disk Space Transaction',
                   'TS', 'Temp Segment',
                   'IV', 'Library Cache Invalidation',
                   'LS', 'Log Start or Switch',
                   'RW', 'Row Wait',
                   'SQ', 'Sequence Number',
                   'TE', 'Extend Table',
                   'TT', 'Temp Table', a.type) lock_type,
            decode(a.lmode,0, 'None',           /* Mon Lock equivalent */
       1, 'Null',           /* N */
       2, 'Row-S (SS)',     /* L */
       3, 'Row-X (SX)',     /* R */
       4, 'Share',          /* S */
       5, 'S/Row-X (SSX)',  /* C */
       6, 'Exclusive',      /* X */
       to_char(a.lmode)) mode_held,
       decode(a.request,
       0, 'None',           /* Mon Lock equivalent */
       1, 'Null',           /* N */
       2, 'Row-S (SS)',     /* L */
       3, 'Row-X (SX)',     /* R */
       4, 'Share',          /* S */
       5, 'S/Row-X (SSX)',  /* C */
       6, 'Exclusive',      /* X */
       to_char(a.request)) mode_requested,
       to_char(a.id1) lock_id1, to_char(a.id2) lock_id2,
       c.object object,
       d.sql_text sql,
       e.first_load_time
    from v$lock a, v$session, v$access c, v$sqltext d, v$sqlarea e
       where (id1,id2) in
         (select b.id1, b.id2 from v$lock b where b.id1=a.id1 and
         b.id2=a.id2 and b.request>0) and
         a.sid = v$session.sid and
         a.sid = c.sid and
         d.address = v$session.sql_address and
         d.hash_value = v$session.sql_hash_value and
         d.address = e.address
    order by a.id1, a.lmode desc
    set headingsep ='|'
    set lines 160
    set pagesize 20
    ttitle 'Database Locking Conflict Report'
    btitle 'Mode Held = indicates the user holding the lock|Mode Request = indicates the user waiting on the later to finish to establish lock||** End of Locking Conflict Report **'
    column username      format a10     heading 'User'
    column terminal      format a15     heading 'Application|PC'
    column object           format a15     heading     'Table'
    column sql            format a15     heading 'SQL'
    column sid           format 999     heading 'SID'
    column lock_type      format a15     heading 'Lock|Type'
    column mode_held      format a11     heading 'Mode|Held'
    column mode_requested      format a10     heading 'Mode|Request'
    column lock_id1      format a8     heading 'Lock ID1'
    column lock_id2      format a8     heading 'Lock ID2'
    column first_load_time  format a19     heading 'Requested'
    break on lock_id1
    select a.sid,
           username,
           terminal,
           decode(a.type,'MR', 'Media Recovery',
                      'RT', 'Redo Thread',
                   'UN', 'User Name',
                   'TX', 'Transaction',
                   'TM', 'DML',
                   'UL', 'PL/SQL User Lock',
                   'DX', 'Distributed Xaction',
                     'CF', 'Control File',
                   'IS', 'Instance State',
                   'FS', 'File Set',
                   'IR', 'Instance Recovery',
                   'ST', 'Disk Space Transaction',
                   'IR', 'Instance Recovery',
                   'ST', 'Disk Space Transaction',
                   'TS', 'Temp Segment',
                   'IV', 'Library Cache Invalidation',
                   'LS', 'Log Start or Switch',
                   'RW', 'Row Wait',
                   'SQ', 'Sequence Number',
                   'TE', 'Extend Table',
                   'TT', 'Temp Table', a.type) lock_type,
            decode(a.lmode,0, 'None',           /* Mon Lock equivalent */
       1, 'Null',           /* N */
       2, 'Row-S (SS)',     /* L */
       3, 'Row-X (SX)',     /* R */
       4, 'Share',          /* S */
       5, 'S/Row-X (SSX)',  /* C */
       6, 'Exclusive',      /* X */
       to_char(a.lmode)) mode_held,
       decode(a.request,
       0, 'None',           /* Mon Lock equivalent */
       1, 'Null',           /* N */
       2, 'Row-S (SS)',     /* L */
       3, 'Row-X (SX)',     /* R */
       4, 'Share',          /* S */
       5, 'S/Row-X (SSX)',  /* C */
       6, 'Exclusive',      /* X */
       to_char(a.request)) mode_requested,
       to_char(a.id1) lock_id1, to_char(a.id2) lock_id2,
       c.object object,
       d.sql_text sql,
       e.first_load_time
    from v$lock a, v$session, v$access c, v$sqltext d, v$sqlarea e
       where (id1,id2) in
         (select b.id1, b.id2 from v$lock b where b.id1=a.id1 and
         b.id2=a.id2 and b.request>0) and
         a.sid = v$session.sid and
         a.sid = c.sid and
         d.address = v$session.sql_address and
         d.hash_value = v$session.sql_hash_value and
         d.address = e.address
    order by a.id1, a.lmode descCheers,
    Francisco Munoz Alvarez
    http://www.oraclenz.com

  • DEAD LOCK ERROR

    When we are using our oracle application, our session hang every time the user update records. the DBA said that we have a dead lock error... the only thing he did is to reset sa database every time we in counter this problem. but we have this error every day, and i don't have an ideal regarding what is dead lock.

    you don't have a deadlock problem, because a deadlock will be "solved" as oracle simply kills the blocking session and rollbacks the changes.He is right. you might have blocking problem not dead lock problem. Find out the blocker and waiter and kill the blocker session.
    Following query would give you an idea about who is blocking and who is waiting for :
    select /*+ ordered */
    a.sid blocker_sid,
    -- c.sql_text,
    a.username blocker_username,
    a.serial#,
    -- a.logon_time,
    b.type,
    b.lmode mode_held,
    b.ctime time_held,
    c.sid waiter_sid,
    c.request request_mode,
    c.ctime time_waited
    from v$lock b, v$enqueue_lock c, v$session a, v$sqltext c
    where c.address=a.prev_sql_addr and
    a.sid = b.sid
    and b.id1 = c.id1(+)
    and b.id2 = c.id2(+)
    and c.type(+) = 'TX'
    and b.type = 'TX'
    and b.block = 1
    order by time_held, time_waited
    Look for blocker_id and waiter_id. If possible, kill blocker using following command.
    select sid,serial# from v$session where sid = blocker_sid;
    alter system kill session 'sid,serial#'';
    Jaffar

  • Lock + Insert..

    Hi,
    I have a job in my Oracle Forms 10g/ Oracle DB 10g application that runs every minute to identify if there is a Blocking Lock in the database.
    I have been getting an INSERT statement as the cause of the blocking lock every day! How can an insert statement create a blocking?
    I have not used LOCK TABLE tab1 IN EXCLUSIVE MODE;
    The query I use in my job to get the Blocking SQL text is:
    SELECT vs.SID, vs.username, vs.logon_time, vs.machine, vs.sql_hash_value,
    vsql.piece, vsql.sql_text, vs.prev_hash_value
    FROM v$session vs, v$sqltext vsql
    WHERE SID IN (SELECT LPAD (' ', DECODE (vl.request, 0, 0, 1)) || SID
    FROM v$lock vl
    WHERE id1 IN (SELECT id1
    FROM v$lock vl2
    WHERE vl2.lmode = 0))
    AND vs.sql_hash_value = vsql.hash_value
    ORDER BY 2, 5, 6;
    Please advice
    Warm Regards
    Sajan

    DROP TABLE T1;
    CREATE TABLE T1 (C1 NUMBER PRIMARY KEY);
    -- Session 1:
    INSERT INTO T1 VALUES (0);
    -- Session 2:
    INSERT INTO T1 VALUES (0);
    -- The statement "hangs"
    -- Session 3 (SYSTEM)
    SELECT vs.SID, vs.username, vs.logon_time, vs.machine, vs.sql_hash_value,
         vsql.piece, vsql.sql_text, vs.prev_hash_value
         FROM v$session vs, v$sqltext vsql
         WHERE SID IN (SELECT LPAD (' ', DECODE (vl.request, 0, 0, 1)) || SID
         FROM v$lock vl
         WHERE id1 IN (SELECT id1
         FROM v$lock vl2
         WHERE vl2.lmode = 0))
         AND vs.sql_hash_value = vsql.hash_value
         ORDER BY 2, 5, 6;
    SID USERNAME   LOGON_TIME          ..  SQL_TEXT                    
    51 <......>   23.08.2006 13:15:50 ..  INSERT INTO T1 VALUES (0)
    and
    SELECT
               (SELECT USERNAME FROM V$SESSION WHERE SID = A.SID) Blocker
              ,A.SID
              ,' is blocking '
              ,(SELECT USERNAME FROM V$SESSION WHERE SID = B.SID) Blockee
              ,B.SID
         FROM V$LOCK A, V$LOCK B
         WHERE A.BLOCK = 1
              AND B.REQUEST > 1
              AND A.ID1 = B.ID1
              AND A.ID2 = B.ID2
    BLOCKER               SID 'ISBLOCKING'  BLOCKEE               SID
    <......>               31  is blocking  <......>                51

  • Lock in Insert?

    Hi,
    I have a job in my Oracle Forms 10g/ Oracle DB 10g application that runs every minute to identify if there is a Blocking Lock in the database.
    I have been getting an INSERT statement as the cause of the blocking lock every day! How can an insert statement create a blocking?
    I have not used LOCK TABLE tab1 IN EXCLUSIVE MODE;
    The query I use in my job to get the Blocking SQL text is:
    SELECT vs.SID, vs.username, vs.logon_time, vs.machine, vs.sql_hash_value,
    vsql.piece, vsql.sql_text, vs.prev_hash_value
    FROM v$session vs, v$sqltext vsql
    WHERE SID IN (SELECT LPAD (' ', DECODE (vl.request, 0, 0, 1)) || SID
    FROM v$lock vl
    WHERE id1 IN (SELECT id1
    FROM v$lock vl2
    WHERE vl2.lmode = 0))
    AND vs.sql_hash_value = vsql.hash_value
    ORDER BY 2, 5, 6;
    Please advice
    Warm Regards
    Sajan

    Do you know the issues that can happen due to the nolock hint usage?
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Oracle database locks

    Today I ran the following queries in my 2 node RAC database. Enterprise database server 11.7 linux version.
    SQL> select * from dba_blockers;
    no rows selected
    SQL> select * from dba_waiters;
    no rows selected
    SQL> SELECT substr(DECODE(request,0,'Holder: ','Waiter: ')||g.sid,1) sess,s.machine,s.serial#,s.sql_id sqlid,
    2 id1, id2, lmode, request, g.type, g.inst_id, seconds_in_wait
    3 FROM GV$LOCK g, gv$session s
    4 WHERE (id1, id2, g.type) IN
    5 (SELECT id1, id2, type FROM GV$LOCK WHERE request>0)
    6 and g.sid = s.sid
    7 and g.inst_id = s.inst_id
    order by sess desc;
    SESS MACHINE SERIAL# SQLID ID1 ID2 LMODE REQUEST TY INST_ID SECONDS_IN_WAIT
    Waiter: 6462 appserver 49027 2vzvm60fvf506 276026 0 0 6 TM 2 2078
    Holder: 6492 database server 8546 276026 0 3 0 TM 1 28815
    SQL> SELECT a.sql_text
    FROM gv$sqltext a,
    gv$session b
    WHERE a.address = b.sql_address
    AND a.hash_value = b.sql_hash_value
    AND b.sid = &1
    ORDER BY a.piece; 2 3 4 5 6 7
    Enter value for 1: 6492
    old 6: AND b.sid = &1
    new 6: AND b.sid = 6492
    no rows selected
    INST_ID SID OBJECT_OWNER OBJECT_NAME LOCKED_MODE OS_USER_NAME
    1 6492 ABC XYZ Row-X (SX) oracle
    2 6462 ABC XYZ None appuser
    I wanted to know why dba_blockers or dba_waiters not showing blocked or waiting sessions, why no sqlid associated to holder session ?
    Thanks for your time and help

    Thanks for your quick response. you provided good information
    I understood that currently no session is holding the lock for which other session is waiting, i.e dba_blockers showing zero rows.
    But how the below query is showing holder and waiting session and no sql query associated to holding session.
    SQL> SELECT substr(DECODE(request,0,'Holder: ','Waiter: ')||g.sid,1) sess,s.machine,s.serial#,s.sql_id sqlid,
    2 id1, id2, lmode, request, g.type, g.inst_id, seconds_in_wait
    3 FROM GV$LOCK g, gv$session s
    4 WHERE (id1, id2, g.type) IN
    5 (SELECT id1, id2, type FROM GV$LOCK WHERE request>0)
    6 and g.sid = s.sid
    7 and g.inst_id = s.inst_id
    order by sess desc;
    SESS MACHINE SERIAL# SQLID ID1 ID2 LMODE REQUEST TY INST_ID SECONDS_IN_WAIT
    Waiter: 6462 appserver 49027 2vzvm60fvf506 276026 0 0 6 TM 2 2078
    Holder: 6492 database server 8546 276026 0 3 0 TM 1 28815

  • How to resolve PL/SQL lock timer event

    We have EBS 11.5.10.2 on 9.2.0.8 db. the Accrual Reconciliation Rebuild Manager program always stuck on wait event PL/SQL lock timer. I want to know how to resolve the wait event. I use below query to identify wait
    SELECT vs.sid,vs.serial#,vs.inst_id,vs.osuser,vw.event,vw.p1,vw.p2,vw.p3 ,vt.sql_text , vs.program
    FROM gv$session_wait vw, gv$sqltext vt , gv$session vs
    WHERE vw.event = 'PL/SQL lock timer'
    AND vt.address=vs.sql_address
    AND vs.inst_id = vw.inst_id
    AND vs.sid = vw.sid;
    Thanks in Adv.

    Many concurrent managers in eBusiness Suite implement "sleeps" so that they they wake up to check fnd_concurrent_requests every N minutes.
    I would ignore this wait event (but i would check to see that the managers don't have very short sleeps and aren't scanning the requests queue too frequently and/or that there aren't too many manager processes doing such).
    Hemant K Chitale
    http://hemantoracledba.blogspot.com
    BTW: Are you very sure that the waits are in the program "Accrual Reconciliation Rebuild Manager" ? It seems to be a Manager to me.
    Edited by: Hemant K Chitale on Jul 31, 2009 12:08 AM

  • Session getting locked when running jobs

    Hello:
    I am trying to kick of jobs:
    DECLARE
    X NUMBER;
    BEGIN
    SYS.DBMS_JOB.SUBMIT
    ( job => X
    ,what => 'ABC.A1;'
    ,next_date => to_date('16/10/2008 08:05:00','dd/mm/yyyy hh24:mi:ss')
    ,interval => 'TRUNC(SYSDATE+30)'
    ,no_parse => TRUE
    SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
    END;
    commit;
    DECLARE
    X NUMBER;
    BEGIN
    SYS.DBMS_JOB.SUBMIT
    ( job => X
    ,what => 'ABC.A2;'
    ,next_date => to_date('16/10/2008 08:05:00','dd/mm/yyyy hh24:mi:ss')
    ,interval => 'TRUNC(SYSDATE+30)'
    ,no_parse => TRUE
    SYS.DBMS_OUTPUT.PUT_LINE('Job Number is: ' || to_char(x));
    END;
    commit;
    The first job starts fine. But the second job in encountering a session-locked error.
    What am I doing wrong?
    Venki

    With this query, you can show the sql blocker and blockee.
    Regards Salim.
    SELECT 'BLOCKER: '||BW.HOLDING_SESSION||'('||SB.USERNAME||') MODE: '||MODE_HELD||
            ' - SQL: '||BQ.SQL_TEXT BLOCKER,
           'BLOCKEE: '||BW.WAITING_SESSION||'('||SW.USERNAME||') MODE: '||MODE_HELD||
            ' - SQL: '||SQ.SQL_TEXT  BLOCKEE
         FROM DBA_WAITERS BW, V$SESSION SB, V$SESSION SW, V$SQLTEXT BQ, V$SQLAREA SQ
         WHERE BW.HOLDING_SESSION = SB.SID
        AND BW.WAITING_SESSION = SW.SID
        AND SB.PREV_SQL_ADDR = BQ.ADDRESS
        AND SW.SQL_ADDRESS = SQ.ADDRESS ;

  • How to find locked object query?

    There is random error ORA-00054 coming during execution of one process which is using SELECT FOR UPDATE NO WAIT statement.
    Logs of process is showing row is accessed only once but still it gets error of "resource busy".
    So there must be any other session which is locking object and it is not identifid. I want to identify which other session/user is locking object.
    I am trying with below query which shows session id, terminal name and object name which is locked.
    SELECT a.sid,a.serial#, a.username,c.os_user_name,a.terminal,
    b.object_id,substr(b.object_name,1,40) object_name,sysdate
    from v$session a, dba_objects b, v$locked_object c
    where a.sid = c.session_id
    and b.object_id = c.object_id But i want information of SQL query from v$sqltext so i can find out throughout the applicaiton where it is executed?
    Thanks

    Finding session that it locking is not a problem.
    Finding SQL responsible is not necessarily straightforward.
    You might be lucky. You might not.
    If the SQl responsible for locking the row ran for a long time or was blocked by something else, AND you're on version >= 10g AND you're licensed for Diagnostic Pack, then you should find some evidence in ASH - DBA_HIST_ACTIVE_SESS_HISTORY.
    Doug Burns has a 10-part series on the subject.
    http://oracledoug.com/serendipity/index.php?/archives/1477-Diagnosing-Locking-Problems-using-ASH-Part-1.html
    There is another current thread on the same issue:
    How to find sql statement which generates LOCK

Maybe you are looking for

  • FaceTime no longer working after 4.3.4 software update.

    I updated my ipod touch to 4.3.4 and ever since facetime no longer connects with the other person. I click call and it says the persons name and directly underneath it says "FaceTime..." as if it were calling the person, but it clearly is not. Somebo

  • Help needed regarding insertion of data into oracle

    Hi, I am student currently trying to do a project to up a semantic database using oracle. Have set up the semantic technologies for oracle 11gr2 and used the jena adapter to load an owl into oracle. But i am not sure how do i insert sample data that

  • Admin console cannot connect to Node Manager

    I've just installed WLS 10.3.2, configured a domain (TEST), a machine (PHILO), a server (TEST1), and a node manager running on PHILO. I logged onto PHILO, ran "startNodeManager.sh", no problems, it says it's listening on 5556, like I configured. Howe

  • Oracle 11G, access other schema's procedure

    Hi all, I have a peculiar problem while calling a procedure from JAVA. I have two schemas, SCH1 and SCH2. Java is connected to  SCH1. There is a procedure in SCH2, grant is given to SCH1. in SCH1 a synonym is created using the following commad. creat

  • Web link in SAPScript

    Hello, How can I embed a web link in the SAPScript so that when the form is sent out as an email, the receiver can click on the web link for more detail information. Thanks.