Académique Documents
Professionnel Documents
Culture Documents
Arup Nanda
What is a Latch
From Glossary in Oracle Manuals:
Agenda
Latches
Process 1
Process 2
If process 1 and 2 both go after the memory area at the same time,
they will end up corrupting the area.
Who makes sure they get their turns?
Latches
Latch
Process 1
Process 2
Latches
100 or 200 bytes memory in SGA (depending on 32 or 64 bit Oracle)
Value depends on how it has been taken
Latch 123
Latch 123
Latch 123
Latch 123
0xFF
pid
count
Untaken
Exclusive
Sharable; but
taken
exclusively
Resolving Latch Contention
Sharable;
taken by many
processes
7
Information on Latches
V$LATCH latch
V$LATCH_CHILDREN the child latches
V$LATCH_PARENT the parent latches
V$LATCHHOLDER the holder of latches
Locks
On logical structures like rows
Queues
No ordering
The sessions get the lock in the
order they wait
Oracle Instance
10
Buffer Operation
1
11
12
13
14
15
21
22
23
24
25
31
32
33
34
35
Buffer Cache
SELECT
FROM EMP
WHERE
11
Buffer Operation
1
11
12
13
14
15
21
22
23
24
25
31
32
33
34
35
1
Data Block
Buffer Cache
SELECT
FROM EMP
WHERE
12
Buffer Insertion
10
20
30
10
20
25
25
30
13
Buffer Header
1
11
12
21
22
23
24
31
11
12
13
14
15
21
22
23
24
25
31
32
33
34
35
Buffer Cache
Shared Pool
X$BH
V$BH
Resolving Latch Contention
buffhan.sql
14
20
10
20
30
20
25
25
1
1
2
1
3
1
1
2
2
2
2
3
1
1
2
1
3
1
1
1
1
2
3
4
2
2
2
2
3
4
3
3
3
2
3
4
Buffer Cache
1
5
2
5
3
5
2
4
30
Linked List
10
20
10
20
30
20
25
30
When a new buffer comes in, only the pointers are updated
15
Buffer Cache
H.C. 1
H.C. 2
11
13
12
14
16
Linked List
X$BH
NXT_HASH
PRV_HASH
17
18
Buffer Cache
Latch
H.C.
19
Latch
HC1
14
10
11
HC2
12
17
HC3
13
L1
L2
20
21
Diagnosis
22
23
Connects to SGA
Use OraDebug
SQL> oradebug setmypid
SQL> oradebug dump hanganalyze 12
24
Alternative
Find an existing process (from ps aef)
Use this PID
SQL> oradebug setospid <ProcessID>
Statement processed.
SQL> oradebug hanganalyze 12
Statement processed.
SQL> oradebug tracefile_name
C:\APP\ORACLE\diag\rdbms\al121\al121\trace\al121_ora_14500.trc
25
SELECT EN
SEL
Shared Pool
26
PIN
LOCK
27
Demo
Create procedure cr_testproc.sql
Session 1 and 2
exec testproc (300)
Session 3
alter procedure testproc compile;
28
x$kglob ob Objects
kglnaown - owner
Kglnaobj name
Kglhdadr the latch address
x$ksuse Sessions
Indx the session SID
Resolving Latch Contention
29
30
Chain of Waiters
Session 1 waits
On Session 2, which in turn, waits
On Session 3, which in turn, waits
On Session 4
View V$WAIT_CHAIN
31
32
Mutex
Latches contain much more information sometimes not needed
Mutex = Mutual Exclusion
Mutextes
are smaller than latches, 28 bytes instead of 110 bytes
take less number of instruction: ~30 instead of ~150
33
Summary
34
Thank You!
Blog: arup.blogspot.com
Tweeter: @ArupNanda
Facebook.com/ArupKNanda
Google Plus: +ArupNanda
Resolving Latch Contention
35