Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with the cache hit ratio

sono99Oct 18 2009 — edited Nov 9 2009
Hello,

I ma having a problem with the cache hit ratio I am geting. I am sure, 100% sure, that something has got to be wrong with the cache hit ratio I am fetching!

1) I will post the code that I am using to retrieve the cache hit ratio. I've seen about a thousand different equations, all equivalent in the end.

In oracle cache hit ratio seems to be:
cache hits / cache lookups,
where cache hits <=> logica IO - physical reads
cache lookups <=> logical IO

Now some people use the session logical Reads stat, from teh view v$sysstat; others use db block gets + db consistent gets; whatever. At the end of the day its all the same, and this is what i Use:

-----
SELECT (P1.value + P2.value - P3.value) AS CACHE_HITS, (P1.value + P2.value) AS CACHE_LOOKUPS, P4.value AS MAX_BUFFS_SIZEB
FROM v$sysstat P1, v$sysstat P2, v$sysstat P3, V$PARAMETER P4
WHERE
P1.name = 'db block gets' AND
P2.name = 'consistent gets' AND
P3.name = 'physical reads' AND
P4.name = 'sga_max_size'
-----


2) The problem:
The cache hit ratio I am retrieving cannot be correct. In this case i was benchamarking a HUGELY inneficient query, consisting of the Union of 5 Projections over the same source table, and Oracle is configured with a relatively small SGA of 300 MB. They query plan is awful, the database will read the source database table 5 times.
And I can see in the physical data statistics of the source tablespace, that total Bytes read is aproximatly 5 times the size of the text file that I used to bulk load data into the databse.

Some of the relevant stats, wait events:
db file scattered read 1129,93 seconds

Elapsed time: 1311,9 seconds
CPU time: 179,84

SGA max Size: 314572800 Bytes

And total bytes read: 77771964416 B (aproximatly 72 Gga bytes)
the source txt loaded to the database was aprox 16 G
Number of reads was like 4.5 times the source datafile.


I would say this, given the difference between CPU time and Elapsed Time, it is clear that the query spent almost all of its time doin DB file scattered reads. How is it possible that i get the following cache hit ratio:
Cache hit Ratio: 0,92
Cache hits: 109680186
Cache lookups: 119173819

I mean only 8% of that Logical I/O corresponded to physical I/O? It is just not possible.


3) Procedure of taking stats:
Now to retrieve these stats I snapshot the system 2 times. One before the query, one after the query.
But: this is not done in a single session. In total 3 sessions are created. One session two retrieve the stats before the query, one session to run the query, a last session to snapshot after the query.

Could the problem, assuming there is one, be related to this:

"The V$SESSTAT view contains statistics on a per-session basis and is only valid for the session currently connected. When a session disconnects all statistics for the session are updated in V$SYSSTAT. The values for the statistics are cleared until the next session uses them."

What does this paragraph mean. Does it mean that the v$sysstat only shows you the stats of the last session that closed? Or does it mean thtat v$sysstat is increamented with the statistics of each v$sessionstat once a session terminates? If so, then my procedure for gathering those stats should be correct.

Can anyone help me sort out the origin of such a high cache hit ratio, with so much I/O being done?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 7 2009
Added on Oct 18 2009
28 comments
6,912 views