Professional Documents
Culture Documents
06 Buffer Cache
06 Buffer Cache
#.2
In This Section
1. latch: cache buffers chains
Buffer Cache
Locks
Network
IO
#.4
Oracle Memory Structures
SGA
Log Library Buffer
Buffer Cache Cache
Buffer Cache
Log Buffer
DBWR
LGWR
User1
User2
User3
Query
Select ename from emp where empno = 12;
0. Parse statement
1. Find object information in data dictionary
2. Calculate execution plan
3. If full table scan
Look at all blocks of table
4. If index find root of index and follow to key
5. Data Dictionary will have info about table or index block
File #
Block #
6. Once you know the block DBA (file# + block#) …
#.7
Is Block in cache?
Now you have a file# and block#
How do you know if a block is cached?
Shadow
Process
?
Do you search all the blocks?
Could be 1000s of blocks to search.
Buffer caches are in the multi Gig
#.8
Buffer Cache
Find a block by:
1) Hash of What is a hash value
What are Buckets
Data file #
What is the linked list?
Block#
2) Result = Bucket #
3) Search linked list for that bucket #
#.9
Concepts
To understand contention on the buffer cache,
need to understand :
1. Linked Lists
2. Hashing
3. Buckets
#.10
Hashing Function
Simple hash could be a Mod function
1 mod 4 = 1
2 mod 4 = 2
3 mod 4 = 3
4 mod 4 = 0
5 mod 4 = 1
6 mod 4 = 2
7 mod 4 = 3
8 mod 4 = 0
3 ? (1+437) mod 4 = 2
Cache
ADDR 03C38F60 03C39000 03C39478
NXT_HASH 03C39000 03C39478
PRV_HASH 03C38F60 03C39000
#.16
NXT_HASH
x$bh PRV_HASH
ADDR
DBARFIL
DBABLK
OBJ DBARFIL
HLADDR
NXT_HASH DBABLK
PRV_HASH OBJ
To Find a Block
#.17
Shadow
Process
2 3 4 5
s3
s2
s1
Examples
1. Look up Table
S1 S2 S3 S4
t1 t2
Index_t2
2. Nested Loops
Select t1.val, t2.val
from t1, t2
where t1.c1 = {value}
and t2.id = t1.id;
#.20
CBC Solutions
Find SQL ( Why is application hitting the block so hard? )
Nested loops, possibly
Hash Partition
Uses Hash Join
Hash clusters
Look up tables (“select language from lang_table where ...”)
Change application
Use plsql function
Spread data out to reduce contention
Select from dual
Possibly use x$dual
Top
Top 55 Timed
Timed Events
Events
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~ %% Total
Total
Event
Event
Top 5 Timed Events Waits
Waits Time
Time (s)
(s) Ela
Ela Time
Time
~~~~~~~~~~~~~~~~~~
---------------------------- % Total
---------------------------- ------------
------------ -----------
----------- --------
--------
Event Sleep breakdown for DB: CDB
Latch Waits Time (s)
Instance: cdb ElaSnaps:
Time 1 -2
Latch
latch
latch Sleep breakdown for DB:
free
free
---------------------------- CDB Instance:
21,428
21,428
------------ 1,914cdb --------
1,914
----------- Snaps: 1 -2
81.37
81.37
->
->
CPU ordered
latch
CPU time free by
ordered
time by misses
misses desc
desc 21,428 1,914
360
360
81.37
15.29
15.29
CPU time 360 15.29
PL/SQL
PL/SQL lock
PL/SQL lock timer
lock timer
timer 16
16 48
48
48 2.04
2.04
2.04
Latch
SQL*Net
Latch Name
message fromdblink
Name Requests
dblink Misses
4,690
Requests 4,690
Misses Sleeps
Sleeps14Sleeps 1->4
.58
SQL*Net
SQL*Net message
message from
from dblink 4,690 14 Sleeps
14 .58 1->4
.58
db file sequential read 1,427 5 .19
db file
cache sequential
filebuffers read
chains
read 12,123,500 1,427
608,415 55 0/0/0/0/0
.19
db
cache sequential
buffers chains 608,415 15,759
12,123,500 1,427 15,759 .19
0/0/0/0/0
library
library cache
cache pin
pin 12,027,599
12,027,599 173,446
173,446 2,862
2,862 172694/743/8/1/0
172694/743/8/1/0
library
library cache
cache 12,072,503
12,072,503 98,065
98,065 2,373
2,373 97739/279/47/0/0
97739/279/47/0/0
simulator
simulator lru
lru latch
latch 606
606 436
436 434
434 6/426/4/0/0
6/426/4/0/0
select
count(*),
sql_id,
nvl(o.object_name,ash.current_obj#) objn,
substr(o.object_type,0,10) otype,
CURRENT_FILE# fn,
SQL Statement:
CURRENT_BLOCK# blockn Success
from v$active_session_history ash
, all_objects o
where event like 'latch: cache buffers chains'
and o.object_id (+)= ash.CURRENT_OBJ# Extra: Hot block
group by sql_id, current_obj#, current_file#,
current_block#, o.object_name,o.object_type
order by count(*)
/
CBC: OEM
#.25
CBC: ADDM
Problem
SQL Statement
Solution?
#.26
CBC – Further Investigation
select * from v$event_name
where name = 'latch: cache buffers chains'
EVENT# NAME
58 latch: cache buffers chains
s1 s2
Update Select
#.32
CBC: Consistent Read Blocks
Hash Block
latches Buckets Headers
s5
Cache Buffer Chain
s4
s3
Max length :
s2 _db_block_max_cr_dba
10g = 6
s1
CBC : Solution
Fine the SQL causing the problem
Change Application Logic
select
Eliminate hot spots ash.sql_id,
Look up tables count(*),
sql_text
Uses pl/sql functions from v$active_session_history ash,
Minimize data per block v$sqlstats sql
Possibly using x$dual instead of dual where
Index Nested loops event='latch: cache buffers chains'
and sql.sql_id(+)=ash.sql_id
Hash join
group by ash.sql_id, sql_text;
Hash partition index
Hah Cluster
Updates, inserts , select for update on blocks while reading those
blocks
Cause multiple copies
#.35
Process
#.39
= entry in x$bh
#.41
X$bh
Describes Buffer Headers
SQL> desc x$bh
Name Type
---------------------- ---------
ADDR RAW(4)
DBARFIL NUMBER
DBABLK NUMBER
OBJ NUMBER
HLADDR
HLADDR Cache RAW(4)
RAW(4)
NXT_HASH
NXT_HASH buffer RAW(4)
RAW(4)
PRV_HASH
PRV_HASH chains RAW(4)
RAW(4)
NXT_REPL
NXT_REPL RAW(4)
RAW(4)
LRU
PRV_REPL RAW(4)
#.42
LRU Chain
ADDR 03C38F60 03C39000 03C39478
NXT_HASH 03C39000 03C38F60
PRV_HASH 03C38F60 03C39000
“Hot” “Cold”
LRU = Least Recently Used
MRU = Most Recently Used
Hot End
Mid-Point
Find Free
Insertion
Block
Mid-Point
Insertion
LRU Latch 1
Set 2
LRU Latch 2
_db_block_lru_latches = 8
10gR2 with cpu_count = 2
X$KCBWDS – set descriptor
#.52
Working Sets
select
ds.set_id,
ds.blk_size ,
SET_ID BLK_SIZE BUFFERS NAME
bp.BUFFERS, ---------- ---------- -------- -------
nvl(bp.name.’unused’) 16 32768
15 32768
from 14 16384
x$kcbwds ds, 13 16384
12 8192
v$buffer_pool bp
11 8192
where 10 4096
9 4096
ds.set_id >= bp.lo_setid (+) and
8 2048
ds.set_id <= bp.hi_setid (+) 7 2048
/ 6 8192 4972 DEFAULT
5 8192 4972 DEFAULT
4 8192
3 8192
2 8192
1 8192
#.53
Test Case
8 Sessions
reading separate tables
Tables were too big to hold in cache
cache option set on each table
Group “other” is
very small
compared to I/O
wait time – not a
problem
#.57
3
User2
User1
#.59
BBW Solution Paths
There is a hot block,
eliminate the hot block
1. Find Block type Block Types:
Resolve if possible Undo Header
use AUM (or add more RBS)
2. Tune SQL Undo Block – hot spot in UNDO
Find SQL Data
How often is it called index – hot spot, partition
table – free lists, ASSM, partition
By how many Users
Segment header – free lists
3. Eliminate Hot Block table datablock -> freelists
Find Object Freelist blocks – free lists groups
Find Block Type File Header Block – look at extent
allocation
#.60
BBW: Statspack
Top
Top 55 Timed
Timed Events
Events Avg
Avg %Total
%Total
~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~ wait
wait Call
Call
Event
Event Waits
Waits Time(s)
Time(s) (ms)
(ms) Time
Time
buffer
buffer busy
busy waits
waits 5,832
5,832 263
263 45
45 28.228.2
log
log file
file parallel
parallel write
write 248
248 125
125 505 505 13.413.4
read
read byby other
other session
session 902
902 103
103 114 114 11.111.1
db
db file
file parallel
parallel write
write 2,166
2,166 94
94 43
43 10.110.1
db Class Waits
Waits Wait Time (s) Avg Time
Time (ms)
db file
file sequential
Classsequential read
read 653
653 Time 81
Wait (s)
81 Avg125
125 8.7
(ms)
8.7
file
file header
header block
block 264
264 203
203 769
769
data
data block
block 6,070
6,070 162
162 27
27
undo
undo header
header 355
355 00 11
segment
segment header
header 44
44 00 11
BBW: ASH
Finds
Object
Block Type
SQL Statement
CNT OBJ OTYPE SQL_ID BLOCK_TYPE TBS
--- --------------- ----- ------------- ----------------- --------
2 BBW_INDEX_VAL_I INDEX 635xhydd6fzgg segment header SYSTEM
2 0 635xhydd6fzgg usn 5 header UNDOTBS1
3 0 1hsb81ypyrfs5 file header block UNDOTBS1
32 BBW_INDEX_VAL_I INDEX 1hsb81ypyrfs5 data block SYSTEM
33 BBW_INDEX_VAL_I INDEX 6avm49ys4k7t6 data block SYSTEM
34 BBW_INDEX_VAL_I INDEX 5wqps1quuxqr4 data block SYSTEM
BBW: OEM #.62
Solutions #.63
#.64
BBW Block Types
select rownum n,ws.class
from v$waitstat;
select * from v$event_name N CLASS
where name = 'buffer busy waits'
1 data block
2 sort block
NAME
NAME P1
P1 P2
P2 P3
P3 3 save undo block
buffer 4 segment header
buffer busy
busy waits
waits file#
file# block#
block# class#
class#
5 save undo header
6 free list
7 extent map
4 Sessions running
Insert into toto
values (null, ‘a’);
Commit;
S1 S2 S3 S4
S1 S2 S3 S4
4 Sessions running
Insert into toto values (null, ‘a’);
Commit;
#.70
Solution 2: ASSM
Multiple Bitmap Blocks Track Free Space
Unformatted
Up to 25% Free
Up to 50% Free
Up to 75% Free
Full
Solution 2: ASSM
Header
BBW: ASSM
Consider using Freelists instead of ASSM
Normally waits on ASSM blocks should be
too small to warrant using Freelists
ASSM is easier, automatically managed
Session 1
Increasing index
key creates a hot
Session 2 spot on the leading
index leaf
Session 3
#.75
14 9 87 72wa5hjpzr0by 1
14 9 87 72wa5hjpzr0by 1
14 9 87 3gkmtvxzu6p2m 1
14 9 87 3gkmtvxzu6p2m 1
6 561325 1 7zx1krfcgn88t select8 segment_name,
select data block
segment_name,
14 9 87 8s29zyzr55z2t 1 segment_type
segment_type
from
from dba_extents
dba_extents
where
where file_id
file_id==P1
P1
SEGMENT_NAME SEGMENT_TYPE and
andP2
P2 between
between
block_id
block_idand
andblock_id
block_id++blocks
blocks––1;1;
R2 ROLLBACK
#.79
Solution is make initial and next extent larger in Temp Table Space
#.82
Sessio
DBWR
n
#.84
Buffer Exterminate
Buffer cache dynamically resized