1 Reply Latest reply on Jun 11, 2012 7:50 AM by 713555

    Get the table's rowid of the session that is locking in RAC database

      I am a developer and not a DBA and I need to find th correct query to find the exact rowid of the record locked on a table. This is for a RAC database and locked record can be from the web form in oracle application server. When I try to get the correct row id, I get the following error:
      ORA-01410 - Invalid row id
      For the criteria, the output is Dbms_Rowid.rowid_create(1, -1, 36, 7845, 0), why I get a -1 for the ROW_WAIT_OBJ#?
      Additional Information: The lock type is DML and the lock mode is: Row Exclusive, the table is locked and the program is web oracle forms executiong.

      I am executing the query in Oracle Database 11g Enterprise Edition Release

      How to accomplish gettting the correct rowid? Below is the selection criteria I have:

      select vs.inst_id,
      vs.audsid audsid,
      locks.sid sid,
      locks.id1 id1,
      locks.id2 id2,
      locks.lmode lmode,
      locks.request request,
      locks.ctime ctime,
      locks.block block,
      vs.serial# serial#,
      vs.username oracle_user,
      vs.osuser os_user,
      vs.program program,
      vs.module module,
      vs.action action,
      vs.process process,
      0, '0 None',
      1, '1 NULL',
      2, '2 Row Share',
      3, '3 Row Exclusive',
      4, '4 Share',
      5, '5 Share Row Exclusive',
      6, '6 Exclusive', '?') lock_mode_held,
      0, '0 None',
      1, '1 NULL',
      2, '2 Row Share',
      3, '3 Row Exclusive',
      4, '4 Share',
      5, '5 Share Row Exclusive',
      6, '6 Exclusive', '?') lock_mode_requested,
      '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',
      'TS', 'Temp Segment',
      'IV', 'Library Cache Invalidation',
      'LS', 'Log Start or Log Switch',
      'RW', 'Row Wait',
      'SQ', 'Sequence Number',
      'TE', 'Extend Table',
      'TT', 'Temp Table',
      locks.type) lock_type,
      vs.row_wait_obj# row_wait_obj#,
      vs.row_wait_file# row_wait_file,
      vs.row_wait_block# row_wait_block#,
      vs.row_wait_row# row_wait_row#,
      dbms_rowid.rowid_create ( 1, vs.ROW_WAIT_OBJ#, vs.ROW_WAIT_FILE#, vs.ROW_WAIT_BLOCK#, vs.ROW_WAIT_ROW# ) rowid_created,
      objs.owner object_owner,
      objs.object_name object_name,
      objs.object_type object_type,
      round( locks.ctime/60, 2 ) lock_time_in_minutes,
      from gv$session vs,
      gv$lock locks,
      dba_objects objs,
      dba_tables tbls
      where locks.id1 = objs.object_id
      and vs.sid = locks.sid
      and objs.owner = tbls.owner
      and objs.object_name = tbls.table_name
      and objs.owner != 'SYS'
      -- and locks.type in ('TM', 'TX')
      order by lock_time_in_minutes;

      Edited by: user3564713 on Jun 10, 2012 10:56 PM
        • 1. Re: Get the table's rowid of the session that is locking in RAC database
          Firstly, read this thread
          Identifying locked rows

          And the last bit from Randolf

          It is a common misconception that you can locate a locked row in Oracle via a query. The point is that the information that you're querying only gets populated in case of a blocking lock, and even then not in every case, since you might have blocking locks that do not refer to a particular row.

          Oracle stores the lock information within the block, so if you identified in which block the row is located that you've attempted to lock, you could get detailed information about the row locks of that block by performing a block dump.

          Other than that Oracle doesn't maintain this information anywhere else and it is only externalized for blocking situations - it is a matter of design that there is no central lock manager in Oracle that would inherently limit scalability, hence the downside of that approach is that there is no central information pool where you could obtain detailed information about row level locks.

          However, if you see support note "Sample Code to Select from a Table EXCLUDING Locked Rows [ID 186531.1]"

          You can take the same code from the script in that note to identify rowid of the locked rows.