Apress.Expert.Oracle.Database.Architecture.9i.and.10g.Programming.Techniques.and.Solutions.Sep.2005

rekharaghuram
from rekharaghuram More from this publisher
05.11.2015 Views

CHAPTER 4 ■ MEMORY STRUCTURES 141 Block Buffer Cache So far, we have looked at relatively small components of the SGA. Now we are going to look at one that is possibly huge in size. The block buffer cache is where Oracle stores database blocks before writing them to disk and after reading them in from disk. This is a crucial area of the SGA for us. Make it too small and our queries will take forever to run. Make it too big and we’ll starve other processes (e.g., we won’t leave enough room for a dedicated server to create its PGA, and we won’t even get started). In earlier releases of Oracle, there was a single block buffer cache, and all blocks from any segment went into this single area. Starting with Oracle 8.0, we had three places to store cached blocks from individual segments in the SGA: • Default pool: The location where all segment blocks are normally cached. This is the original—and previously only—buffer pool. • Keep pool: An alternate buffer pool where by convention you would assign segments that were accessed fairly frequently, but still got aged out of the default buffer pool due to other segments needing space. • Recycle pool: An alternate buffer pool where by convention you would assign large segments that you access very randomly, and which would therefore cause excessive buffer flushing but would offer no benefit, because by the time you wanted the block again it would have been aged out of the cache. You would separate these segments out from the segments in the Default and Keep pools so that they would not cause those blocks to age out of the cache. Note that in the Keep and Recycle pool descriptions I used the phrase “by convention.” There is nothing in place to ensure that you use neither the Keep pool nor the Recycle pool in the fashion described. In fact, the three pools manage blocks in a mostly identical fashion; they do not have radically different algorithms for aging or caching blocks. The goal here was to give the DBA the ability to segregate segments to hot, warm, and do not care to cache areas. The theory was that objects in the Default pool would be hot enough (i.e., used enough) to warrant staying in the cache all by themselves. The cache would keep them in memory since they were very popular blocks. You might have had some segments that were fairly popular, but not really hot; these would be considered the warm blocks. These segments’ blocks could get flushed from the cache to make room for some blocks you used infrequently (the “do not care to cache” blocks). To keep these warm segments blocks cached, you could do one of the following: • Assign these segments to the Keep pool, in an attempt to let the warm blocks stay in the buffer cache longer. • Assign the “do not care to cache” segments to the Recycle pool, keeping the Recycle pool fairly small so as to let the blocks come into the cache and leave the cache rapidly (decrease the overhead of managing them all). This increased the management work the DBA had to perform, as there were three caches to think about, size, and assign objects to. Remember also that there is no sharing between them, so if the Keep pool has lots of unused space, it won’t give it to the overworked Default or Recycle pool. All in all, these pools were generally regarded as a very fine, low-level tuning

142 CHAPTER 4 ■ MEMORY STRUCTURES device, only to be used after most all other tuning alternatives had been looked at (if I could rewrite a query to do one-tenth the I/O rather then set up multiple buffer pools, that would be my choice!). Starting in Oracle9i, the DBA had up to four more optional caches, the db_Nk_caches, to consider in addition to the Default, Keep, and Recycle pools. These caches were added in support of multiple blocksizes in the database. Prior to Oracle9i, a database would have a single blocksize (typically 2KB, 4KB, 8KB, 16KB, or 32KB). Starting with Oracle9i, a database can have a default blocksize, which is the size of the blocks stored in the Default, Keep, or Recycle pool, as well as up to four nondefault blocksizes, as explained in Chapter 3. The blocks in these buffer caches are managed in the same way as the blocks in the original Default pool—there are no special algorithm changes for them either. Let’s now move on to cover how the blocks are managed in these pools. Managing Blocks in the Buffer Cache For simplicity, assume in this discussion that there is just a single Default pool. Because the other pools are managed in the same way, we need only discuss one of them. The blocks in the buffer cache are basically managed in a single place with two different lists pointing at them: • The dirty list of blocks that need to be written by the database block writer (DBWn; we’ll take a look at that process a little later) • A list of nondirty blocks The list of nondirty blocks used to be a Least Recently Used (LRU) list in Oracle 8.0 and before. Blocks were listed in order of use. The algorithm has been modified slightly in Oracle8i and in later versions. Instead of maintaining the list of blocks in some physical order, Oracle employs a touch count algorithm, which effectively increments a counter associated with a block as you hit it in the cache. This count is not incremented every time you hit the block, but about once every three seconds—if you hit it continuously. You can see this algorithm at work in one of the truly magic sets of tables: the X$ tables. The X$ tables are wholly undocumented by Oracle, but information about them leaks out from time to time. The X$BH table shows information about the blocks in the block buffer cache (which offers more information than the documented V$BH view). Here, we can see the touch count get incremented as we hit blocks. We can run the following query against that view to find the five “currently hottest blocks” and join that information to the DBA_OBJECTS view to see what segments they belong to. The query orders the rows in X$BH by the TCH (touch count) column and keeps the first five. Then we join the X$BH information to DBA_OBJECTS by X$BH.OBJ to DBA_OBJECTS.DATA_OBJECT_ID: sys@ORA10G> select tch, file#, dbablk, 2 case when obj = 4294967295 3 then 'rbs/compat segment' 4 else (select max( '('||object_type||') ' || 5 owner || '.' || object_name ) || 6 decode( count(*), 1, '', ' maybe!' ) 7 from dba_objects

CHAPTER 4 ■ MEMORY STRUCTURES 141<br />

Block Buffer Cache<br />

So far, we have looked at relatively small components of the SGA. Now we are going to look at<br />

one that is possibly huge in size. The block buffer cache is where <strong>Oracle</strong> stores database blocks<br />

before writing them to disk <strong>and</strong> after reading them in from disk. This is a crucial area of the<br />

SGA for us. Make it too small <strong>and</strong> our queries will take forever to run. Make it too big <strong>and</strong> we’ll<br />

starve other processes (e.g., we won’t leave enough room for a dedicated server to create its<br />

PGA, <strong>and</strong> we won’t even get started).<br />

In earlier releases of <strong>Oracle</strong>, there was a single block buffer cache, <strong>and</strong> all blocks from<br />

any segment went into this single area. Starting with <strong>Oracle</strong> 8.0, we had three places to store<br />

cached blocks from individual segments in the SGA:<br />

• Default pool: The location where all segment blocks are normally cached. This is the<br />

original—<strong>and</strong> previously only—buffer pool.<br />

• Keep pool: An alternate buffer pool where by convention you would assign segments<br />

that were accessed fairly frequently, but still got aged out of the default buffer pool due<br />

to other segments needing space.<br />

• Recycle pool: An alternate buffer pool where by convention you would assign large segments<br />

that you access very r<strong>and</strong>omly, <strong>and</strong> which would therefore cause excessive buffer<br />

flushing but would offer no benefit, because by the time you wanted the block again it<br />

would have been aged out of the cache. You would separate these segments out from<br />

the segments in the Default <strong>and</strong> Keep pools so that they would not cause those blocks<br />

to age out of the cache.<br />

Note that in the Keep <strong>and</strong> Recycle pool descriptions I used the phrase “by convention.”<br />

There is nothing in place to ensure that you use neither the Keep pool nor the Recycle pool in<br />

the fashion described. In fact, the three pools manage blocks in a mostly identical fashion;<br />

they do not have radically different algorithms for aging or caching blocks. The goal here was<br />

to give the DBA the ability to segregate segments to hot, warm, <strong>and</strong> do not care to cache areas.<br />

The theory was that objects in the Default pool would be hot enough (i.e., used enough) to<br />

warrant staying in the cache all by themselves. The cache would keep them in memory since<br />

they were very popular blocks. You might have had some segments that were fairly popular,<br />

but not really hot; these would be considered the warm blocks. These segments’ blocks could<br />

get flushed from the cache to make room for some blocks you used infrequently (the “do not<br />

care to cache” blocks). To keep these warm segments blocks cached, you could do one of the<br />

following:<br />

• Assign these segments to the Keep pool, in an attempt to let the warm blocks stay in the<br />

buffer cache longer.<br />

• Assign the “do not care to cache” segments to the Recycle pool, keeping the Recycle<br />

pool fairly small so as to let the blocks come into the cache <strong>and</strong> leave the cache rapidly<br />

(decrease the overhead of managing them all).<br />

This increased the management work the DBA had to perform, as there were three caches<br />

to think about, size, <strong>and</strong> assign objects to. Remember also that there is no sharing between<br />

them, so if the Keep pool has lots of unused space, it won’t give it to the overworked Default<br />

or Recycle pool. All in all, these pools were generally regarded as a very fine, low-level tuning

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!