Professional Documents
Culture Documents
ASDASVRRSDASD
ASDASVRRSDASD
#.2
Locks
Locks REDO Lib Cache Buffer Cache
Network
IO
Enqueues = Locks
CI TM Buffer Cache Disk I/O Enqueue TX - row lock contention TX - allocate ITL entry TX - index contention
#.3
Waits
Library Cache
Redo
HW
ST
Locks
Come in Many
SQL*Net Undo
TS US
Copyright 2006 Kyle Hailey
Types
SQ
#.4
#.5
time
Solving Enqueues
Need SQL and Object/row
Statspack
#.6
v$session
dba_blockers dba_waiters ?/rdbms/admin/utllockt.sql http://www.evdbt.com/enqwaits.sql
Statspack 9i
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
#.7
Statspack is INSUFFICIENT, missing Who is blocked Who Blocks What blocks How they are blocked
Copyright 2006 Kyle Hailey
#.8
9i Investigation
Select * from v$event_name where name=enqueue;
Parameter1 ---------Name|mode parameter2 ---------id1 parameter3 ---------id2
#.9
Mode: 0006
Lock = TX 6
Copyright 2006 Kyle Hailey
#.10
#.11
Wait : enqueue
10g
208 enq: enq: enq: enq: enq: enq: enq: enq: enq: enq: HW SQ SS ST TM TW TX TX TX TX
Configuration Configuration Configuration Configuration Application Administrative Configuration Concurrency Application Application
Version 9 : P2 and P3
Parameter1 ---------Name|mode ID1 and ID2
#.12
parameter2 ---------id1
parameter3 ---------id2
#.13
Statspack 10g
5 Timed Events Avg %Total ~~~~~~~~~~~~~~~~~~ wait Call Event Waits Time (s) (ms) Time ----------------------------- ------ -------- ------ -----enq: TX - row lock contention 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
#.14
10g Better, tells what kind of lock But still not who is blocked, who blocks them what they are blocked on
Copyright 2006 Kyle Hailey
#.15
V$active_session_history
Succeeds
Who is waiting
SESSION_ID SESSION_SERIAL# USER_ID
On what object
CURRENT_OBJ# CURRENT_FILE# CURRENT_BLOCK#
SQL_ID
OEM 10g
#.16
#.17
PARAMETER1 ---------name|mode
select distinct event, p1, to_char(p1,'XXXXXXXX') p1raw from v$active_session_history where event like 'enq:%;
EVENT P1 ------------------------------ ---------enq: TX - row lock contention 1415053316 enq: TX - row lock contention 1415053318 enq: TX - allocate ITL entry 1415053316
Copyright 2006 Kyle Hailey
P1 = name | mode
P1 (parameter1) same for all locks
select distinct parameter1 from v$event_name where name like 'enq:%'
#.18
select distinct event, p1, mod(p1,16) as "mode" from v$active_session_history where event like 'enq:%;
EVENT ----------------------------enq: TX - allocate ITL entry enq: TX - row lock contention enq: TX - row lock contention
PARAMETER1 ---------name|mode
#.19
#.20
Lock Modes
# Type --- ------1 Null 2 SS 3 SX 4 S 5 SSX 6 X Name --------------------------Null Sub share Sub exclusive Share Share/sub exclusive Exclusive
Copyright 2006 Kyle Hailey
#.21
block spilt Unique Index Key enforcement Foreign key enforcement ITL space waits Bitmap chunk conflicts Alter tablespace read only; Free Lists slot waits Possible with two phase commit
Copyright 2006 Kyle Hailey
#.22
4. enq: TX contention
Mode 6 classic row lock Mode 4 - pk violation, fk violation, bitmap chunk wait Wait for a data file extension, Alter tbs read only
TX Lock
Session B
update toto set name = ADAMS where id = 1;
#.23
Undo Segment
Session a
update toto set name = SMITH where id = 1;
Row 1
#.24
User 2
#.25
#.26
#.27
TX Mode 4
#.28
#.29
User 2
#.30
ID 2?
ID Value 2?
Session 1: Insert key no commit Session 2: Insert into same key : Enqueue TX 4
Copyright 2006 Kyle Hailey
#.31
User 10
#.32
ID 2?
ID Value 2?
#.33
1
2
01010000111000011100001100
000.000.0000 000.000.000
#.34
Session 2
#.35
01010000111000011100001100
01010000111000011100001100
200.0 205.6
block
row
Copyright 2006 Kyle Hailey
#.36
01010000111000011100001100 01010000111000011100001100
200.0 205.6
#.37
SID LM P2 P3 OBJ --- --- ------ ---- ----144 4 179681 7074 CHILD 144 4 179681 7074 CHILD 144 4 179681 7074 CHILD
OTYPE FN BLOCKN SQL_ID ----- --- ------ -TABLE 1 60954 ahm7c9rupbz9r TABLE 1 60954 ahm7c9rupbz9r TABLE 1 60954 ahm7c9rupbz9r
BSID 1 1 1
SID LM P2 P3 OBJ --- --- ------ ---- ----143 4 966081 4598 I1 143 4 966081 4598 I1 143 4 966081 4598 I1 143 4 966081 4598 I1
OTYPE FN BLOCKN SQL_ID ----- --- ------ -INDEX 0 0 azav296xxqcjx INDEX 0 0 azav296xxqcjx INDEX 0 0 azav296xxqcjx INDEX 0 0 azav296xxqcjx
#.38
Data
#.39
#.40
#.41
enq: TX - contention
Example Session 1 start transaction, dont commit Session 2 alter tablespace read only Example Data File Extension waiter waitng for another session to extend file Index Block Split waiter waiting for another session to split the block
Others ?
Free Lists
Non-ASSM Sessions freeing block If no txs free lists available (min 16, grow up depending on block size) , pick one and wait TX 4
First does a prepare the commit Any read or write access in the intervening time waits TX 4
Copyright 2006 Kyle Hailey
TX Further Investigation
select event, sql_id, CURRENT_OBJ# || ' ' || name obj ,CURRENT_FILE# file# ,CURRENT_BLOCK# block# from v$active_session_history ash, obj$ o where event like 'enq: TX%' and o.obj# (+)= ash.current_obj# order by sample_time
SQL_ID ------------ahm7c9rupbz9r bjvx94vnxtxgv ahm7c9rupbz9r bjvx94vnxtxgv ahm7c9rupbz9r
#.42
EVENT -----------------------------enq: TX - row lock contention enq: TX - row lock contention enq: TX - row lock contention enq: TX - row lock contention enq: TX - row lock contention
OBJ FILE# BLOCK# --------- --- -----53363 FOO 1 123586 53363 FOO 1 123586 53363 FOO 1 123586 53363 FOO 1 123586 53363 FOO 1 123586
#.43
TX Further Investigation
Who is the blocker:
#.44
enq: TM - contention
TX locks have a corresponding TM lock TM locks the structure from change
Parameter1
= object id
Parmeter2(ID1) ------------object # Parameter3(ID2) --------------table/partition
LOCK ------enq: TM
Parmeter1 --------name|mode
#.45
enq: TM - contention
Exclusive Row Level Lock User 1 create table parent ( id number primary key); create table child ( id number references parent, name varchar2(20)); insert into parent values (1); insert into parent values (2); commit; delete from parent where id=2;
Copyright 2006 Kyle Hailey
User 2
#.46
enq: TM - contention
PK Parent Child ID Name 1
ID 1 X 2
ID 1 X 2
Value
Session 1 Session 2
Enqueue TM 4 Session 2 doesnt know the value Session 1 inserted Session 2 only knows there is an outstanding change
Copyright 2006 Kyle Hailey
#.47
ID 1 2
ID
Value
Foreign Key
Session 1: Insert into Child ID=1 Session 2: Delete from Parent ID=2 OK can verify quickly in the child index
Copyright 2006 Kyle Hailey
TM Further Investigation
select event, sql_id, mod(p1,16) as "mode", p2|| ' ' || o.name obj from v$active_session_history ash, obj$ o where event like 'enq: TM%' and o.obj# (+)= ash.p2 order by sample_time;
EVENT -----------------------------enq: TM - contention enq: TM - contention enq: TM - contention enq: TM - contention enq: TM - contention enq: TM - contention
#.48
SQL_ID mode OBJ ------------- ---- --------------8zw36yw3fq4yy 4 53372 CHILD 8zw36yw3fq4yy 4 53372 CHILD 8zw36yw3fq4yy 4 53372 CHILD 8zw36yw3fq4yy 4 53372 CHILD 8zw36yw3fq4yy 4 53372 CHILD 8zw36yw3fq4yy 4 53372 CHILD
#.49
UL Locks
User-defined Locks
dbms_lock
Wait Event enq: UL - contention Parameter2 id Parameter3 0
Internal Locks
CI Cross Instance CU Cursor Bind HW High Water RO Reuse Object ST Space Transaction
#.50
#.51
enq: CI - contention
Cross Instance not OPS lock. invoke actions in background processes
#.52
CI Cross Instance
Id1 Meaning (parameter2)
0 Flush buffers for reuse as new class 1 LGWR checkpointing and Hot Backup 2 DBWR synchronization of SGA with control file 3 Log file add/drop/rename notification 4 Write buffer for CR read 5 Test Call 6 Invalidate KCK cache in all instances 7 Alter rollback segment optimal 8 Signal Query Servers/coordinator 9 Create Remote Parallel Query Server 10 Set Global Partitions 11 Stop Disk Writes 12 Drop Sort Segments 13 Release unused space from Sort Segments 14 Instance Recovery for Parallel operation Group 15 Validate parallel slave Lock Value 16 Check Transaction State Objects
CI Locks
select substr(sql_text,0,20) sql_text, p2,p3, CURRENT_OBJ# || ' ' || name obj ,CURRENT_FILE# file# ,CURRENT_BLOCK# block# from v$active_session_history ash, obj$ o, v$sqltext sql where event like 'enq: CI%' and o.obj# (+)= ash.current_obj# and sql.sql_id (+)= ash.sql_id order by sample_time;
SQL_TEXT P2 P3 OBJ FILE# BLOCK# -------------------- ----- ------- ------------ ------ ------INSERT INTO TOTO1 VA 1 5 54225 TOTO1 6 682721
#.53
CI Locks
SQL_TEXT P2 P3 ---------------------------------------- --- -alter table XXXXX drop partition YYYYY 1 5 ID1 = 2 " LGWR checkpointing and Hot Backup " ID2 = 5. "Used to queue up interested clients"
#.54
If p2=1 and p3=5, then contention on blocks being checkpointed, try raising fast_start_mttr_target alter system set fast_start_mttr_target=600 scope=both;
Copyright 2006 Kyle Hailey
#.55
enq: CU - contention
cursor bind From Jonathan Lewis: Protects the variable definitions while the cursor is being optimized.
8i
enq: HW - contention
Wait Event enq: HW - contention Parameter2 table space # Parameter3 block
#.56
Session 1 Session 2
Header
Table
Data
Session 3
HW
Use Freelists
#.57
Cause multiple jumps in High Water Mark Alter table XXXX allocate extent;
Pre-Allocate Extents
Hidden Parameter
_bump_highwater_mark_count alter session set "_bump_highwater_mark_count"=100;
ASSM
Partition Object
HW Further Investigation
select event, sql_id, CURRENT_OBJ# || ' ' || name obj ,CURRENT_FILE# file# ,CURRENT_BLOCK# block# from v$active_session_history ash, obj$ o where event like 'enq: HW%' and o.obj# (+)= ash.current_obj# order by sample_time;
#.58
EVENT SQL_ID OBJ FILE# BLOCK# -------------------- ------------- ----------- ----- -----enq: HW - contention 49ch3jfkncnsp 53410 T1_I1 13 29734
Copyright 2006 Kyle Hailey
#.59
#.60
Solution
Smaller
cache Tune DBWR using smaller MTTR Use GTT Truncate/drop less often alter system set fast_start_mttr_target=17 scope=both;
SELECT TARGET_MTTR, ESTIMATED_MTTR, CKPT_BLOCK_WRITES FROM V$INSTANCE_RECOVERY
Copyright 2006 Kyle Hailey
#.61
enq: ST - contention
Space Transaction management lock Space Transaction Lock Allocating/deallocating extents Dictionary Managed Tablespaces Id1, Id2 Combinations:
Always
0, Always 0.
Solution
Got
Other Resources
#.62
@?/rdbms/admin/utllockt
WAITING_SESSION LOCK_TYPE MODE_REQUESTED MODE_HELD LOCK_ID1 LOCK_ID2 --------------- ----------- -------------- --------- --------- -------144 139 None Transaction Share Exclusive 131113 7507
Blocking Sessions
#.63
#.64
Look at object and SQL use LMT, freelists, pre-allocate extents PQO
RO reusable object
SQ Sequence Lock
ST - Space Transaction