Home > Database, problem-cause-solution, tips > dba_locks does not show for both instances

dba_locks does not show for both instances


Problem: While working on blocking session script below, I figured out that blocking sessions are not displayed in both nodes of the rac, exadata.

SELECT
 decode (s2.sid,s1.FINAL_BLOCKING_SESSION,'*'||s2.sid,' '||s2.sid) Blocker_SID
 ,s2.serial# blocker_serial
 ,s2.inst_id blocker_inst_id
 ,s2.con_id Blocker_con_id
 ,s2.status Blocker_Status
 ,s2.username Blocker_User
 ,s2.osuser Blocker_OS_User
 ,s2.process Blocker_OS_PID
 ,s2.sql_id Blocked_sql_id
 ,o.owner Object_owner
 ,o.object_name Locked_Object
 ,o.object_type Locked_Object_Type
 ,l2.lock_type Blocking_Lock_Type
 ,substr(s2.program,1,10) Blocker_Program
 ,s2.client_info Blocker_Client
 ,s1.sid blocked_sid
 ,s1.inst_id blocked_inst_id
 ,s1.con_id Blocker_con_id
 ,s1.status Blocked_Status
 ,s1.username Blocked_User
 ,s1.osuser Blocked_OS_User
 ,s1.process Blocked_OS_PID
 ,s1.sql_id Blocked_sql_id
 ,s1.last_call_et Blocked_Age
 ,substr(s1.program,1,10) Blocked_Program
 ,s1.client_info Blocked_Client
 FROM gv$session s2
 join gv$session s1 ON (s1.blocking_session=s2.sid)
 join dba_objects o on (o.object_id=s1.ROW_WAIT_OBJ#)
 join dba_locks l2 on (s2.sid=l2.session_id)
 left join dba_locks l1 on (s1.sid=l1.session_id and l1.lock_type = l2.lock_type AND l1.lock_id1 = l2.lock_id1 AND l1.lock_id2 = l2.lock_id2)
 where s1.last_call_et>10 and upper(l2.MODE_HELD)='EXCLUSIVE';

Cause: Usual suspect in the from clause are dba_objects, gv$session, and dba_locks. I just look into the dba_locks, because dba_objects is just related with database physical structure which should be common in RAC. gv$session also cannot be, because it is gv$, it must surely include common information among instances again. So, it must be for dba_locks, and there it is,

desc DBA_LOCKS
SESSION_ID NUMBER
LOCK_TYPE VARCHAR2(26)
MODE_HELD VARCHAR2(40)
MODE_REQUESTED VARCHAR2(40)
LOCK_ID1 VARCHAR2(40)
LOCK_ID2 VARCHAR2(40)
LAST_CONVERT NUMBER
BLOCKING_OTHERS VARCHAR2(40)

Solution:

There must be alternative real RAC aware version of it. It is GV$LOCK, some small differences in column names, and values, it has same information, and it shows more for both nodes.

desc GV$LOCK
INST_ID NUMBER
ADDR RAW(8)
KADDR RAW(8)
SID NUMBER
TYPE VARCHAR2(2)
ID1 NUMBER
ID2 NUMBER
LMODE NUMBER
REQUEST NUMBER
CTIME NUMBER
BLOCK NUMBER
CON_ID

Before my script looks like this:

SELECT
 decode (s2.sid,s1.FINAL_BLOCKING_SESSION,'*'||s2.sid,' '||s2.sid) Blocker_SID
 ,s2.serial# blocker_serial
 ,s2.inst_id blocker_inst_id
 ,s2.con_id Blocker_con_id
 ,s2.status Blocker_Status
 ,s2.username Blocker_User
 ,s2.osuser Blocker_OS_User
 ,s2.process Blocker_OS_PID
 ,s2.sql_id Blocked_sql_id
 ,o.owner Object_owner
 ,o.object_name Locked_Object
 ,o.object_type Locked_Object_Type
 ,l2.lock_type Blocking_Lock_Type
 ,substr(s2.program,1,10) Blocker_Program
 ,s2.client_info Blocker_Client
 ,s1.sid blocked_sid
 ,s1.inst_id blocked_inst_id
 ,s1.con_id Blocker_con_id
 ,s1.status Blocked_Status
 ,s1.username Blocked_User
 ,s1.osuser Blocked_OS_User
 ,s1.process Blocked_OS_PID
 ,s1.sql_id Blocked_sql_id
 ,s1.last_call_et Blocked_Age
 ,substr(s1.program,1,10) Blocked_Program
 ,s1.client_info Blocked_Client
 FROM gv$session s2
 join gv$session s1 ON (s1.blocking_session=s2.sid)
 join dba_objects o on (o.object_id=s1.ROW_WAIT_OBJ#)
 join dba_locks l2 on (s2.sid=l2.session_id)
 left join dba_locks l1 on (s1.sid=l1.session_id and l1.lock_type = l2.lock_type AND l1.lock_id1 = l2.lock_id1 AND l1.lock_id2 = l2.lock_id2)
 where s1.last_call_et>10 and upper(l2.MODE_HELD)='EXCLUSIVE';

After making modifications on column names and, associated values, my script turns out to be as follows:

SELECT
 decode (s2.sid,s1.FINAL_BLOCKING_SESSION,'*'||s2.sid,' '||s2.sid) Blocker_SID
 ,s2.serial# blocker_serial
 ,s2.inst_id blocker_inst_id
 ,s2.con_id Blocker_con_id
 ,s2.status Blocker_Status
 ,s2.username Blocker_User
 ,s2.osuser Blocker_OS_User
 ,s2.process Blocker_OS_PID
 ,s2.sql_id Blocked_sql_id
 ,o.owner Object_owner
 ,o.object_name Locked_Object
 ,o.object_type Locked_Object_Type
 ,l2.type Blocking_Lock_Type
 ,substr(s2.program,1,10) Blocker_Program
 ,s2.client_info Blocker_Client
 ,s1.sid blocked_sid
 ,s1.inst_id blocked_inst_id
 ,s1.con_id Blocker_con_id
 ,s1.status Blocked_Status
 ,s1.username Blocked_User
 ,s1.osuser Blocked_OS_User
 ,s1.process Blocked_OS_PID
 ,s1.sql_id Blocked_sql_id
 ,s1.last_call_et Blocked_Age
 ,substr(s1.program,1,10) Blocked_Program
 ,s1.client_info Blocked_Client
 FROM gv$session s2
 join gv$session s1 ON (s1.blocking_session=s2.sid)
 join dba_objects o on (o.object_id=s1.ROW_WAIT_OBJ#)
 join gv$lock l2 on (s2.sid=l2.sid)
 left join gv$lock l1 on (s1.sid=l1.sid and l1.type = l2.type AND l1.id1 = l2.id1 AND l1.id2 = l2.id2)
 where s1.last_call_et>10 and l2.LMODE=6;

 

 

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Julian Dontcheff's Database Blog

Distinguished Product Manager - PL/SQL and JSON at Oracle

Bobby Durrett's DBA Blog

Oracle database performance

flashdba

Database Performance in the Cloud

Don Charisma

because anything is possible with Charisma

Carol no Mundo!

Aventuras de uma intercambista a trabalho pelo mundo!

nimaidba

Welcome to the world of Oracle with me....

Tech

News and reviews from the world of gadgets, gear, apps and the web

WordPress.com

WordPress.com is the best place for your personal blog or business site.

Gurcan Orhan's ODI and DWH Blog

Some words about Oracle Data Integrator and Data Warehousing.