How Buffer Cache Works - Proligence

2 downloads 196 Views 1MB Size Report
where hladdr = '000007FF3C8B1568'. How Buffer Cache Works. 10 bh1.sql ... Process 1 and 2 will try to get the “latchâ€
How Buffer Cache Works Arup Nanda

Longtime Oracle DBA

Oracle Instance

Source: Oracle Database Documentation Concepts Guide

@ArupNanda

How Buffer Cache Works

2

Buffer Operation 1

2

3

4

5

11

12

13

14

15

21

22

23

24

25

31

32

33

34

35

Buffer Cache

SELECT … FROM EMP WHERE …

@ArupNanda

How Buffer Cache Works

3

Buffer Operation 1

2

3

4

5

11

12

13

14

15

21

22

23

24

25

31

32

33

34

35

1 Data Block

@ArupNanda

Buffer Cache

SELECT … FROM EMP WHERE …

How Buffer Cache Works

4

Buffer Insertion 10

20

30

10

20

25

@ArupNanda

25

30

How Buffer Cache Works

5

Buffer Header 1

2

11

12

21

22

3

23

24

31

2

3

4

5

11

12

13

14

15

21

22

23

24

25

31

32

33

34

35

Buffer Cache

Shared Pool

X$BH V$BH

@ArupNanda

1

How Buffer Cache Works

buffhan.sql

6

Buffer Header Management 10

20

10

20

30

20

25

25

1

2

1 1 2 1 3 1

1 2 2 2

3

1

2

4

5

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

3

30

Linked List

10

20

10

20

30

20

25

30

When a new buffer comes in, only the pointers are updated

@ArupNanda

How Buffer Cache Works

7

Hash Chain

@ArupNanda

H.C. 1

1

3

2

4

H.C. 2

11

13

12

14

How Buffer Cache Works

8

Linked List X$BH NXT_HASH PRV_HASH

@ArupNanda

How Buffer Cache Works

9

Test for Buffer Header select ltrim(addr,'0') buffer_address, ltrim(nxt_hash,'0') next_buffer, ltrim(prv_hash,'0') prev_buffer, case when nxt_hash = prv_hash then 'Unlinked' else 'Linked' end as linked from x$bh where hladdr = '000007FF3C8B1568' bh1.sql

@ArupNanda

How Buffer Cache Works

10

Where did I Park My Car?

@ArupNanda

How Buffer Cache Works

11

Data Block Address • Get the relative file# and block# select col1, dbms_rowid.rowid_relative_fno(rowid) rfile#, dbms_rowid.rowid_block_number(rowid) block# from cbctest; fblk.sql

• Get the DBA select dbms_utility.make_data_block_address (file#,block#) from dual;

get_dba.sql

@ArupNanda

How Buffer Cache Works

12

Chain Placement

Get the DBA

Find out the HC

H.C. 1

1

3

2

4

H.C. 2

11

13

12

14

1 SELECT … FROM EMP WHERE …

Data Block

@ArupNanda

How Buffer Cache Works

13

CBC Latch Latch

H.C.

1

3

2

4

Catch Buffer Chain (CBC) Latch

@ArupNanda

How Buffer Cache Works

14

Latches and Hash Chains Hash Chain Latch

HC1

14

10

7

11

5

HC2

3

12

17

6

2

HC3

9

4

8

13

1

L1

L2

No. of hash buckets = init.ora parameter _db_block_hash_buckets No. of latches = _db_block_hash_latches

@ArupNanda

How Buffer Cache Works

15

Identifying Buffer Latches • Demo – – – – – – –

Find out the rows and blocks – qsales.sql Find out the data object id – dobjid.sql Find out the data block address – dba1.sql Find out the child latch address – hladdr1.sql Find out the partition name – extents1.sql Find out the objects protected by a latch – latchobjs.sql Find out the total buffers per latch – clatchcount.sql

@ArupNanda

How Buffer Cache Works

16

Latches Latch

Process 1

Process 2

Process 1 and 2 will try to get the “latch”, a area in memory that does not have any required data. Whoever gets the latch now gets to access the memory area exclusively When done, the process releases the latch

@ArupNanda

How Buffer Cache Works

17

Linked List X$BH NXT_HASH PRV_HASH

@ArupNanda

How Buffer Cache Works

18

Linking/Unlinking Chain 1 Latch

Link

1

2

3

4

5

1

2

3

4

5

6

1

2

3

4

5

6

Chain 2 Latch

7

Unlink

Chain 3 Latch

Cache Buffer Chain Latch _db_block_hash_latches @ArupNanda

How Buffer Cache Works

19

Summary • • • • • • • • •

Buffers are placeholders in memory Empty when the instance comes up Server process brings a data block from database to occupy a buffer There is no “database” of which block is in which buffer. A process has to scan the buffers to find what it needs The buffers are spread over several hash chains to help in searching A data block address is fixed for the block DBA determines which chain the block may be found A latch prevents multiple processes from walking the chain

@ArupNanda

How Buffer Cache Works

20

Thank You! Blog: arup.blogspot.com Tweeter: @ArupNanda Facebook.com/ArupKNanda Google Plus: +ArupNanda @ArupNanda

How Buffer Cache Works

21