Enqueue Waits : Locks

Wait Tree - Locks
Buffer Cache Disk I/O TM 3 Row Lock

#.2

TX 6 Row Lock
TX 4 ITL Lock TX 4 PK/FK HW Lock

Enqueue
Waits Library Cache Redo SQL*Net Undo

ST Lock
TS Lock

Copyright 2006 Kyle Hailey

#.3

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

Copyright 2006 Kyle Hailey

#.4

Statspack
Top 5 Timed Events ~~~~~~~~~~~~~~~~~~ Event Waits Time (s) Avg wait (ms) %Total Call Time

-------------------------- ------------ ----------- ------ ------

Enqueue
CPU time db file sequential read control file sequential read

42

126
4

3000

96.5
2.8

165 214

1 0

4 1

.4 .1

log file switch completion

2

0

40

.1

Need more info from v$session_wait
Copyright 2006 Kyle Hailey

---------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 Copyright 2006 Kyle Hailey .p2.-------------.5 v$session_wait SQL> select event.---------.p3 from v$session_wait.#. p1. EVENT P1 P2 P3 ----------------.

depends on P1 Copyright 2006 Kyle Hailey .#.6 Enqueue : Args  P1 = Type | mode  P2 = ID1 . depends on P1  P3 = ID2 .

7 Translating P1 to Lock and Mode SQL> select p1.-------1415053318 54580006 Type Mode Copyright 2006 Kyle Hailey . P1 P1RAW ---------. p1raw from v$session_wait where sid=151.#.

8 Translating P1 to Lock and Mode P1RAW -------54580006 Type: 5458 Hex Decimal 54 = 84 58 = 88 ASCII = “T” = “X” Mode: 0006 Lock = TX 6 Copyright 2006 Kyle Hailey .#.

---.9 Translating P1 to Lock and Mode column Type format a4 column Mode format a4 select sid.1))) Type.3.---151 TX 06 Copyright 2006 Kyle Hailey . substr(p1raw.#.1.1))) || chr(to_number(substr(p1raw.4.8. chr(to_number(substr(p1raw.1) as "Mode" from v$session_wait where name=‘enqueue’.1)) * 16 + to_number(substr(p1raw.1)) * 16 + to_number(substr(p1raw. SID TYPE Mode --.2.

-16777216)/16777215)|| chr(bitand(p1. mod(p1.16) as "mode" FROM V$SESSION_WAIT Where sid=151 / bitand(p1.#. 16711680)/65535) "Lock". 65536) "Mode" Copyright 2006 Kyle Hailey .10 Translating p1 to Lock and Mode SELECT chr(bitand(p1.

16711680)/65535) as "Type".---240 enqueue TX 6 2686995 433 Copyright 2006 Kyle Hailey .-16777216)/16777215)|| chr(bitand(P1. event. #. mod(p1.------.16) as "mode" from v$session_wait where event = 'enqueue‘.------.Translating P1 to Lock and Mode select sid.11 SID EVENT Ty mode P2 P3 --. chr(bitand(P1.-.---.

12 Modes 1 2 3 4 5 6 Null SS SX S SSX X Null Sub share Sub exclusive Share Share/sub exclusive Exclusive Copyright 2006 Kyle Hailey .#.

Sequence ST .13 Types CF – Control File HW – High Water SQ .Space Transaction TM .DML TS – Temporary Segment / Table Space TX –Transaction UL – DBMS_LOCK UN – User Named US – Undo Segment Copyright 2006 Kyle Hailey .#.

---------.------.14 TY ID1 ID2 LMODE REQUEST CTIME BLOCK -.----.Looking at v$lock select * from v$lock where type in ('TX'. 'TM'). SID --151 135 151 135 #.----.----TX 589855 1592 0 6 4049 0 TM 53737 0 3 0 4058 0 TM 53737 0 3 0 4049 0 TX 589855 1592 6 0 4058 1 TX ID1 = RBS seg# | RBS slot # ID2 = rbs wrap # TM ID1 = object id ID2 = 0 Copyright 2006 Kyle Hailey .---------.

15 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 Copyright 2006 Kyle Hailey .#.

16 Select substr(name.parameter2.parameter1.ID1 and ID2 Definitions column parameter1 format a15 column parameter2 format a15 column parameter3 format a15 column lock format a8 #.1.7) as "lock".parameter3 from v$event_name where name like 'enq%' LOCK ------enq: CF enq: HW enq: SQ enq: ST enq: TM enq: TS enq: TX Parmeter1 --------name|mode name|mode name|mode name|mode name|mode name|mode name|mode Parmeter2(ID1) ------------0 table space # object # 0 object # tablespace ID usn<<16 | slot Parameter3(ID2) --------------operation block 0 0 table/partition dba sequence Copyright 2006 Kyle Hailey .

contention Administrative enq: TX .contention Administrative Copyright 2006 Kyle Hailey #.contention Configuration enq: KO .17 .Enqueues Decoded in 10g  10gR2 waits distinguish 208 enqueues enq: DB .row lock contention Application enq: UL .contention Configuration enq: TM .contention Application enq: TW .index contention Concurrency enq: TX .contention Configuration enq: SS .contention Application enq: ZG .contention Administrative enq: HW .fast object checkpoint Application enq: PW .contention Configuration enq: ST .flush prewarm buffers Application enq: RO .allocate ITL entry Configuration enq: TX .contention Application enq: RO .fast object reuse Application enq: SQ .

User Lock find out what application is doing Copyright 2006 Kyle Hailey . freelists.18 TX . pre-allocate extents.Space Transaction only one per database used for space allocations uet.mode 4 probably ITL problem find the object and SQL HW – High Water Look at object and SQL use LMT.mode 6 – application problem Look at what application is doing Find SQL Look at locked data TX . ST .Enqueue Solutions SQ – Sequence Lock logon/logoff problem #. fet Find object use LMT UL .

Enqueue Data Needed  If highest wait time is Enqueue .19 out the kind of Enqueue and tune it  To tune enqueues we need one of the following to determine the type of enqueue  ASH Data  v$session_wait data  Sql Trace with waits Copyright 2006 Kyle Hailey .  Find #.

-------14 10 Transaction Exclusive Exclusive 458765 2379 Copyright 2006 Kyle Hailey .------------. WAITING HOLDING LOCK_TYPE MODE_HELD MODE_REQUESTE LOCK_ID1 LOCK_ID2 ------.---------.20 Blockers and Waiters SQL> select * from dba_blockers.---------.------.#.-------. HOLDING_SESSION --------------10 SQL> select * from dba_waiters.

lockwait from v$session. row_wait_obj#. row_wait_block#. 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 #.V$session select sid.21 10g Lockwait not null is blocker Pre-10g Lockwait not null is the waiter Copyright 2006 Kyle Hailey .------------. row_wait_file#. row_wait_row#.------------.-------------.

User 2 Copyright 2006 Kyle Hailey .22 Enqueue : TX 6 Example Exclusive Row Level Lock User 1 SQL> delete from emp where empno = 7934.#. SQL> update emp set sal=2000 Where empno = 7934.

EVENT P1 P2 P3 ----------------.p2.-------------. p1.---------enqueue 1415053318 589855 1592 What can we do with this info? Copyright 2006 Kyle Hailey .---------.23 Enqueue : TX 6 v$session_wait SQL> select event.p3 from v$session_wait.#.

---240 enqueue TX 6 2686995 433 Copyright 2006 Kyle Hailey .------.24 Enqueue : TX 6 Type and Mode select sid.16711680)/65535) as "Type".-.---.16) as "mode" from v$session_wait where event = 'enqueue‘.------. event. mod(p1.#. SID EVENT Ty mode P2 P3 --. chr(bitand(P1.-16777216)/16777215)|| chr(bitand(P1.

------.----TX 589855 1592 0 6 4049 0 TM 53737 0 3 0 4058 0 TM 53737 0 3 0 4049 0 TX 589855 1592 6 0 4058 1 TX ID1 = RBS seg# | RBS slot # ID2 = rbs wrap # TM ID1 = object id ID2 = 0 Copyright 2006 Kyle Hailey .----.----.---------.25 TY ID1 ID2 LMODE REQUEST CTIME BLOCK -. 'TM').Enqueue : TX 6 v$lock select * from v$lock where type in ('TX'. SID --151 135 151 135 #.---------.

------------.---------.26 Enqueue : TX 6 Blockers and Waiters SQL> select * from dba_blockers.-------.#.---------.------. WAITING HOLDING LOCK_TYPE MODE_HELD MODE_REQUESTE LOCK_ID1 LOCK_ID2 ------. HOLDING_SESSION --------------10 SQL> select * from dba_waiters.-------14 10 Transaction Exclusive Exclusive 458765 2379 Copyright 2006 Kyle Hailey .

27 10g Lockwait not null is blocker Pre-10g Lockwait not null is the waiter Copyright 2006 Kyle Hailey .------------. lockwait from v$session.-------------. row_wait_obj#.Enqueue : TX 6 V$session select sid. row_wait_block#. row_wait_file#. row_wait_row#.-------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 #.------------. SID ROW_WAIT_OBJ# ROW_WAIT_FILE# ROW_WAIT_BLOCK# ROW_WAIT_ROW# LOCKWAIT --.--------------.

28 Enqueue : TX 4 Index on p(id) User 1 SQL> insert into p values(3).#. User 2 SQL> insert into p values(3). Copyright 2006 Kyle Hailey .

---.---240 enqueue TX 4 2686995 433 Copyright 2006 Kyle Hailey . #. event.------.Enqueue : TX 4 select sid. chr(bitand(P1.-16777216)/16777215)|| chr(bitand(P1.-.16711680)/65535) as "Type". mod(p1.29 SID EVENT Ty mode P2 P3 --.------.16) as "mode" from v$session_wait where event = 'enqueue‘.

'TM').---------.---------.30 Enqueue : TX 4 SQL> select sid. SID ---------139 146 146 139 139 139 146 TY ID1 ID2 LMODE REQUEST -. id2. type. id1. lmode . request from v$lock where type in ('TX'.---------.#.---------TX 327689 1901 0 4 TM 55166 0 3 0 TM 55168 0 2 0 TM 55166 0 3 0 TM 55168 0 2 0 TX 720914 168 6 0 TX 327689 1901 6 0 Copyright 2006 Kyle Hailey .

#.31 Enqueue : TX 4 .difficult Difficult – uses modifying different data  ITL  Unique Key  Bitmap Index Rare  Read only Tablespace  Free Lists  Two phase commit Copyright 2006 Kyle Hailey .

32 Enqueue : TX 4 – ITL Transaction 1 Info Data Block Data Block Header Header ITL Transaction 2 Info Data Copyright 2006 Kyle Hailey .#.

#.33 Enqueue : TX 4 – ITL Data Block Data Block Header Header Transaction 1 Transaction 2 Row 3 Row 2 Data Row 1 Transaction 3 Copyright 2006 Kyle Hailey .

---------. type. id1.---------148 TX 135 TM 151 TM 148 TM 135 TX 151 TX 65559 54557 54557 54557 524312 65559 1284 0 0 0 1592 1284 0 3 3 3 6 6 4 0 0 0 0 0 Copyright 2006 Kyle Hailey . request from v$lock where type in ('TX'.---------. SID TY ID1 ID2 LMODE REQUEST ---------.---------.34 Enqueue : TX 4 – ITL SQL> select sid.-. lmode . id2.#. 'TM').

insert into parent values (1). insert into child values (1. . delete from parent. commit.2).#.35 Enqueue : TX 4 – Unique Key Exclusive Row Level Lock User 1 create table parent ( id number primary key). Copyright 2006 Kyle Hailey User 2 insert into child values (1.2). create table child ( id number references parent. name varchar2(20)).

solution lock child Enqueue TX 4 Copyright 2006 Kyle Hailey .#.36 Enqueue : TX 4 – Unique Key PK Parent Child ID Name ID ID Value Session 1: Insert into Child ID=1 Session 2: Delete from Parent ID=2 : would require a FTS of child still not atomic.

lmode .Unique Key SQL> select sid.---------.#.-.--------151 TM 54548 0 2 0 151 TM 54550 0 3 0 151 TX 524306 1590 6 0 135 TM 54548 0 3 0 135 TM 54550 0 0 4 Copyright 2006 Kyle Hailey .---------. SID TY ID1 ID2 LMODE REQUEST ---------. id1. request from v$lock where type in ('TX'. 'TM').---------. id2. type.37 Enqueue : TX 4 .

38 ID ID Value ID Session 1: Insert into Child ID=1 Session 2: Delete from Parent ID=2 OK – can Copyright verify quickly in the child index 2006 Kyle Hailey .Enqueue : TX 4 – Unique Key Solution PK Parent Index Child ID Name #.

40 Enqueue : TX 4 – Bitmap Indexes  Two sessions update keys in same key range Copyright 2006 Kyle Hailey .#.

#.41 Enqueue : ST  Space Transaction Lock  Used in Dictionary Managed Tables  Solution  Got to Locally Managed Tablespaces Copyright 2006 Kyle Hailey .

#.42 Enqueue : HW Table Header Data High Water Mark Empty Copyright 2006 Kyle Hailey .

---.Enqueue : HW select sid. mod(p1.43 SID EVENT Ty mode P2 P3 --.------240 enqueue HW 6 4 16777715 Copyright 2006 Kyle Hailey . #.-16777216)/16777215)|| chr(bitand(P1.16) as "mode" from v$session_wait where event = 'enqueue‘.16711680)/65535) as "Type". event.------.---. chr(bitand(P1.-.

44 Enqueue : HW  Use Freelists  Cause multiple jumps in High Water Mark  Pre-Allocate Extents  Alter table XXXX allocate extent.  Hidden Parameter  bump_highwater_mark_count  ASSM  Automatic segment space management Copyright 2006 Kyle Hailey .#.

Sign up to vote on this title
UsefulNot useful