We help IT Professionals succeed at work.

Library cache and database buffer cache.

sakthikumar
sakthikumar asked
on
Dear Experts,

I have a basic question, please help in understanding.

I understand library cache stores sqls in LRU mechanism,  
whenever a new sql is parsed, SQL will be loaded into library cache and the data block for the sql will be loaded into DB buffer cache.

My question is, will DB buffer cache will contain all the related data for all the sqls stored in library cache?
Comment
Watch Question

Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Cache and buffer are independent, but of course it is more likely to have data for cached plans in the data buffer, because those are used more often and have more "weight". It is much more complex in fact ...
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
>>My question is, will DB buffer cache will contain all the related data for all the sqls stored in library cache?

I suppose there is a reason for the question.  I see this as more of a theoretical question over a practical one.

In theory: Sure.  Given a large enough SGA or small enough sql cache.

Very likely on a fresh cache.  Think about this:  You flush the shared pool and run a select statement.  Pretty good chance that everything will be cached.

Author

Commented:
Yes right,
Suppose if I am running a query which is having a FTS on a very large table.
Then the datablocks for FTS will get occupied with other sqls' data.
That case we will not have data for all sqls.

Is my assumption correct?
Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Yes, correct. FTS data is not likely to get buffered at all, unless for small tables. Usage stats will tell other data is more important to keep.
Most Valuable Expert 2012
Distinguished Expert 2019

Commented:
>>That case we will not have data for all sqls.

I'm still not seeing what you are attempting to answer with this question.

Are you attempting to understand how Oracle manages the different pieces of the SGA?

>>FTS data is not likely to get buffered at all

Small addition:  The blocks will be read into the buffer cache.  How long they remain there has a lot to do with what else is going on in the system.
Most Valuable Expert 2011
Top Expert 2012
Commented:
>>FTS data is not likely to get buffered at all

The data is loaded into the LRU end of the cache, to ensure the FTS doesn't erase all other cached data.  In fact, each new block read (or set of blocks with multi-block reads)  overwrites the previous block(s).  Thus the only thing left in the buffer cache when you are done is the data from the last read of the table.