enqueue waits : locks. #.2 copyright 2006 kyle hailey wait tree - locks waits disk i/o library cache...

Download Enqueue Waits : Locks. #.2 Copyright 2006 Kyle Hailey Wait Tree - Locks Waits Disk I/O Library Cache Enqueue Undo TX 6 Row Lock TX 4 ITL Lock HW Lock

Post on 14-Dec-2015

218 views

Category:

Documents

1 download

Embed Size (px)

TRANSCRIPT

  • Slide 1

Enqueue Waits : Locks Slide 2 #.2 Copyright 2006 Kyle Hailey Wait Tree - Locks Waits Disk I/O Library Cache Enqueue Undo TX 6 Row Lock TX 4 ITL Lock HW Lock Redo Buffer Cache SQL*Net TM 3 Row Lock ST Lock TS Lock TX 4 PK/FK Slide 3 #.3 Copyright 2006 Kyle Hailey Enqueue Types DDL Locks Data Dictionary Row Cache Library Cache Locks DML Locks Data Locks Row locks Table Locks Internal Structure Locks High Water Buffer Header Sequence Cache Space Transaction Temporary Space Slide 4 #.4 Copyright 2006 Kyle Hailey Statspack Top 5 Timed Events Avg %Total ~~~~~~~~~~~~~~~~~~ wait Call Event Waits Time (s) (ms) Time -------------------------- ------------ ----------- ------ ------ Enqueue 42 126 3000 96.5 CPU time 4 2.8 db file sequential read 165 1 4.4 control file sequential read 214 0 1.1 log file switch completion 2 0 40.1 Top 5 Timed Events Avg %Total ~~~~~~~~~~~~~~~~~~ wait Call Event Waits Time (s) (ms) Time -------------------------- ------------ ----------- ------ ------ Enqueue 42 126 3000 96.5 CPU time 4 2.8 db file sequential read 165 1 4.4 control file sequential read 214 0 1.1 log file switch completion 2 0 40.1 Need more info from v$session_wait Slide 5 #.5 Copyright 2006 Kyle Hailey v$session_wait SQL> select event, p1,p2,p3 from v$session_wait; EVENT P1 P2 P3 ----------------- -------------- ---------- ---------- enqueue 1415053318 589855 1592 SQL> select event, p1,p2,p3 from v$session_wait; EVENT P1 P2 P3 ----------------- -------------- ---------- ---------- enqueue 1415053318 589855 1592 What can we do with this info? Note: v$session_wait is for current waits. Need ASH or some similar data source for historic analysis Slide 6 #.6 Copyright 2006 Kyle Hailey Enqueue : Args P1 = Type | mode P2 = ID1, depends on P1 P3 = ID2, depends on P1 Slide 7 #.7 Copyright 2006 Kyle Hailey Translating P1 to Lock and Mode SQL> select p1, p1raw from v$session_wait where sid=151; P1 P1RAW ---------- -------- 1415053318 54580006 Mode Type Slide 8 #.8 Copyright 2006 Kyle Hailey Translating P1 to Lock and Mode Type: 5458 P1RAW -------- 54580006 Hex Decimal ASCII 54 = 84 = T 58 = 88 = X Lock = TX 6 Mode: 0006 Slide 9 #.9 Copyright 2006 Kyle Hailey Translating P1 to Lock and Mode column Type format a4 column Mode format a4 select sid, chr(to_number(substr(p1raw,1,1)) * 16 + to_number(substr(p1raw,2,1))) || chr(to_number(substr(p1raw,3,1)) * 16 + to_number(substr(p1raw,4,1))) Type, substr(p1raw,8,1) as "Mode" from v$session_wait where name=enqueue; SID TYPE Mode --- ---- ---- 151 TX 06 Slide 10 #.10 Copyright 2006 Kyle Hailey Translating p1 to Lock and Mode SELECT chr(bitand(p1,-16777216)/16777215)|| chr(bitand(p1, 16711680)/65535) "Lock", mod(p1,16) as "mode" FROM V$SESSION_WAIT Where sid=151 / bitand(p1, 65536) "Mode" Slide 11 #.11 Copyright 2006 Kyle Hailey Translating P1 to Lock and Mode select sid, event, chr(bitand(P1,-16777216)/16777215)|| chr(bitand(P1,16711680)/65535) as "Type", mod(p1,16) as "mode" from v$session_wait where event = 'enqueue; select sid, event, chr(bitand(P1,-16777216)/16777215)|| chr(bitand(P1,16711680)/65535) as "Type", mod(p1,16) as "mode" from v$session_wait where event = 'enqueue; SID EVENT Ty mode P2 P3 --- ------- -- ---- ------- ---- 240 enqueue TX 6 2686995 433 SID EVENT Ty mode P2 P3 --- ------- -- ---- ------- ---- 240 enqueue TX 6 2686995 433 Slide 12 #.12 Copyright 2006 Kyle Hailey Modes 1 Null Null 2 SS Sub share 3 SX Sub exclusive 4 S Share 5 SSX Share/sub exclusive 6 X Exclusive Slide 13 #.13 Copyright 2006 Kyle Hailey Types CF Control File HW High Water SQ - Sequence ST - Space Transaction TM - DML TS Temporary Segment / Table Space TX Transaction UL DBMS_LOCK UN User Named US Undo Segment Slide 14 #.14 Copyright 2006 Kyle Hailey Looking at v$lock select * from v$lock where type in ('TX', 'TM'); SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK --- -- ---------- ---------- ----- ------- ----- ----- 151 TX 589855 1592 0 6 4049 0 135 TM 53737 0 3 0 4058 0 151 TM 53737 0 3 0 4049 0 135 TX 589855 1592 6 0 4058 1 select * from v$lock where type in ('TX', 'TM'); SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK --- -- ---------- ---------- ----- ------- ----- ----- 151 TX 589855 1592 0 6 4049 0 135 TM 53737 0 3 0 4058 0 151 TM 53737 0 3 0 4049 0 135 TX 589855 1592 6 0 4058 1 TX ID1 = RBS seg# | RBS slot # ID2 = rbs wrap # TM ID1 = object id ID2 = 0 Slide 15 #.15 Copyright 2006 Kyle Hailey ID1 and ID2 Examples Lock = TX ID1 = RBS seg# | RBS slot # ID2 = rbs wrap # Lock = TM ID1 = object id ID2 = 0 ID1 and ID2 meanings can be determined from v$event_name in 10g Slide 16 #.16 Copyright 2006 Kyle Hailey ID1 and ID2 Definitions column parameter1 format a15 column parameter2 format a15 column parameter3 format a15 column lock format a8 Select substr(name,1,7) as "lock",parameter1,parameter2,parameter3 from v$event_name where name like 'enq%' LOCK Parmeter1 Parmeter2(ID1) Parameter3(ID2) ------- --------- ------------- --------------- enq: CF name|mode 0 operation enq: HW name|mode table space # block enq: SQ name|mode object # 0 enq: ST name|mode 0 0 enq: TM name|mode object # table/partition enq: TS name|mode tablespace ID dba enq: TX name|mode usn #.20 Copyright 2006 Kyle Hailey Blockers and Waiters SQL> select * from dba_blockers; HOLDING_SESSION --------------- 10 SQL> select * from dba_waiters; WAITING HOLDING LOCK_TYPE MODE_HELD MODE_REQUESTE LOCK_ID1 LOCK_ID2 ------- ------- ---------- ---------- ------------- -------- -------- 14 10 Transaction Exclusive Exclusive 458765 2379 Slide 21 #.21 Copyright 2006 Kyle Hailey V$session select sid, row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#, lockwait from v$session; SID ROW_WAIT_OBJ# ROW_WAIT_FILE# ROW_WAIT_BLOCK# ROW_WAIT_ROW# LOCKWAIT --- ------------- -------------- --------------- ------------- -------- 141 53651 3 53980 0 143 -1 0 0 0 144 -1 0 0 0 149 -1 0 0 0 151 53737 4 428 0 410343AC 10g Lockwait not null is blocker Pre-10g Lockwait not null is the waiter Slide 22 #.22 Copyright 2006 Kyle Hailey Enqueue : TX 6 Example User 1 SQL> delete from emp where empno = 7934; User 2 SQL> update emp set sal=2000 Where empno = 7934; Exclusive Row Level Lock Slide 23 #.23 Copyright 2006 Kyle Hailey Enqueue : TX 6 v$session_wait SQL> select event, p1,p2,p3 from v$session_wait; EVENT P1 P2 P3 ----------------- -------------- ---------- ---------- enqueue 1415053318 589855 1592 SQL> select event, p1,p2,p3 from v$session_wait; EVENT P1 P2 P3 ----------------- -------------- ---------- ---------- enqueue 1415053318 589855 1592 What can we do with this info? Slide 24 #.24 Copyright 2006 Kyle Hailey Enqueue : TX 6 Type and Mode select sid, event, chr(bitand(P1,-16777216)/16777215)|| chr(bitand(P1,16711680)/65535) as "Type", mod(p1,16) as "mode" from v$session_wait where event = 'enqueue; select sid, event, chr(bitand(P1,-16777216)/16777215)|| chr(bitand(P1,16711680)/65535) as "Type", mod(p1,16) as "mode" from v$session_wait where event = 'enqueue; SID EVENT Ty mode P2 P3 --- ------- -- ---- ------- ---- 240 enqueue TX 6 2686995 433 SID EVENT Ty mode P2 P3 --- ------- -- ---- ------- ---- 240 enqueue TX 6 2686995 433 Slide 25 #.25 Copyright 2006 Kyle Hailey Enqueue : TX 6 v$lock select * from v$lock where type in ('TX', 'TM'); SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK --- -- ---------- ---------- ----- ------- ----- ----- 151 TX 589855 1592 0 6 4049 0 135 TM 53737 0 3 0 4058 0 151 TM 53737 0 3 0 4049 0 135 TX 589855 1592 6 0 4058 1 select * from v$lock where type in ('TX', 'TM'); SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK --- -- ---------- ---------- ----- ------- ----- ----- 151 TX 589855 1592 0 6 4049 0 135 TM 53737 0 3 0 4058 0 151 TM 53737 0 3 0 4049 0 135 TX 589855 1592 6 0 4058 1 TX ID1 = RBS seg# | RBS slot # ID2 = rbs wrap # TM ID1 = object id ID2 = 0 Slide 26 #.26 Copyright 2006 Kyle Hailey Enqueue : TX 6 Blockers and Waiters SQL> select * from dba_blockers; HOLDING_SESSION --------------- 10 SQL> select * from dba_waiters; WAITING HOLDING LOCK_TYPE MODE_HELD MODE_REQUESTE LOCK_ID1 LOCK_ID2 ------- ------- ---------- ---------- ------------- -------- -------- 14 10 Transaction Exclusive Exclusive 458765 2379 Slide 27 #.27 Copyright 2006 Kyle Hailey Enqueue : TX 6 V$session select sid, row_wait_obj#, row_wait_file#, row_wait_block#, row_wait_row#, lockwait from v$session; SID ROW_WAIT_OBJ# ROW_WAIT_FILE# ROW_WAIT_BLOCK# ROW_WAIT_ROW# LOCKWAIT --- ------------- -------------- --------------- ------------- -------- 141 53651 3 53980 0 143 -1 0 0 0 144 -1 0 0 0 149 -1 0 0 0 151 53737 4 428 0 410343AC 10g Lockwait not null is blocker Pre-10g Lockwait not null is the waiter Slide 28 #.28 Copyright 2006 Kyle Hailey Enqueue : TX 4 User 1 SQL> insert into p values(3); User 2 SQL> insert into p values(3); Index on p(id) Slide 29 #.29 Copyright 2006 Kyle Hailey Enqueue : TX 4 select sid, event, chr(bitand(P1,-16777216)/16777215)|| chr(bitand(P1,16711680)/65535) as "Type", mod(p1,16) as "mode" from v$session_wait where event = 'enqueue; select sid, event, chr(bitand(P1,-16777216)/16777215)|| chr(bitand(P1,16711680)/65535) as "Type", mod(p1,16) as "mode" from v$session_wait where event = 'enqueue; SID EVENT Ty mode P2 P3 --- ------- -- ---- ------- ---- 240 enqueue TX 4 2686995 433 SID EVENT Ty mode P2 P3 --- ------- -- ---- ------- ---- 240 enqueue TX 4 2686995 433 Slide 30 #.30 Copyright 2006 Kyle Hailey Enqueue : TX 4 SQL> select sid, type, id1, id2, lmode, request from v$lock where type in ('TX', 'TM'); SID TY ID1 ID2 LMODE REQUEST ---------- -- ---------- ---------- ---------- ---------- 139 TX 327689 1901 0 4 146 TM 55166 0 3 0 146 TM 55168 0 2 0 139 TM 55166 0 3 0 139 TM 55168 0 2 0 139 TX 720914 168 6 0 146 TX 327689 1901 6 0 Slide 31 #.31 Copyright 2006 Kyle Hailey Enqueue : TX 4 - difficult Difficult uses modifying different data ITL Unique Key Bitmap Index Rare Read only Tablespace Free Lists Two phase commit Slide 32