Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Ik.

Asked: October 18, 2002 - 10:22 pm UTC

Last updated: July 12, 2006 - 4:45 pm UTC

Version: 8.1.7

Viewed 10K+ times! This question is

You Asked

Tom,
Given below are the details from the database i work on. I understand that very high cache hit ratios are also very bad, but here the value seems to be negative. Am i doing something wrong here?

Is it (1 - (Physical reads /(db block gets+consistent gets)))*100?

db block gets 2267538243.00
consistent gets 18446744034366600000.00
physical reads 18446744066965700000.00
Buffer Cache Hit Ratio -0.000000164427738

dbblock buffers is set to 40000

This a Datawarehouse and yes, we do have serious performance problems. We are using 8.1.7. Should we increase the buffers?

Also, please tell me why is a high value of consistent gets bad. Consistent gets mean reading from disk into buffers and then reading blocks from the buffer, right? We would want our queries to be accessing data from the buffers rather than from disk. Am i wrong again?

thanks a zillion.......

and Tom said...

Its a bug (if you contact support and reference bug 818237 there may be a patch) -- they are overflowing a number. Using the query below -- we mask it out (strip the high bytes). Based on those numbers:


ops$tkyte@ORA920.US.ORACLE.COM> create or replace function v( p_num in number ) return number
2 as
3 begin
4 return to_number(substr( to_char(p_num,'fm'||rpad('0',15,'0')||'x'), 9 ), rpad('x',8,'x'));
5 end;
6 /

Function created.

ops$tkyte@ORA920.US.ORACLE.COM>
ops$tkyte@ORA920.US.ORACLE.COM> select (1- (v(18446744066965700000)/(v(2267538243)+v(18446744034366600000))))
2 from dual
3 /

(1-(V(18446744066965700000)/(V(2267538243)+V(18446744034366600000))))
---------------------------------------------------------------------
.685733504


Looks like a 68.5% cache hit.

Rating

  (7 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Thanks...

Ik, October 19, 2002 - 12:09 pm UTC


formula in 8i

sl, November 28, 2002 - 3:22 am UTC

Hi Tom,
I 've read from Metalink that the Buffer Cache Hit Ratio formula stated in Oracle 8i Tuning Guide is wrong. The formula should be:

Hit Ratio = 1-(physical reads - physical reads direct)
/(db block gets + consistent gets)

Is it correct?

Tom Kyte
November 28, 2002 - 8:03 am UTC

it isn't really relevant. cache hit ratios -- yuck. you know what, in so many years, I've never looked at one.

that one you provide takes into consideration that temp and parallel query bypass the buffer cache. So, do you want to count those reads or not. It is just a way to inflate your cache hit ratio, which seems to make people "happy" - Yeah! I have a 98% cache hit.

goto www.hotsos.com and get the paper "are you still using cache hit ratios"

Shreyas, November 29, 2002 - 2:33 am UTC

I have really not understood that with the same values how can the hit ratio be different using the same formula because this is simple maths.
Or am I interpreting your explanation wrongly


Tom Kyte
November 29, 2002 - 10:10 am UTC

I have no idea where you are coming from with this?

what "same values" do you see?

Shreyas, November 29, 2002 - 11:21 pm UTC

I think I interpreted your reply wrongly. I just went through the explaination on the bug you mentioned on the metalink site. What I understood from the site is as the values are exorbitantly high one has to mask higher byte to get the right values. In this particular case if you convert the values to hexadecimal, hex value has leading 0xFFFFFFFF. Is the criteria to find out overflowing numbers as mentioned in metalink.

Tom Kyte
November 30, 2002 - 8:50 am UTC

I am masking out the high bytes which are set wrong, yes. getting rid of the leading ffffff's

STILL Problem

Riaz Shahid, April 02, 2003 - 7:06 am UTC

Hello Tom !

Consider this:

cr@STARR.LHR> show sga

Total System Global Area 214964252 bytes
Fixed Size 75804 bytes
Variable Size 107335680 bytes
Database Buffers 106496000 bytes
Redo Buffers 1056768 bytes

cr@STARR.LHR> SELECT phy.value "Physical Reads",
2 cur.value "DB Block Gets",
3 con.value "Consistent Gets",
4 1-((phy.value)/((cur.value)+(con.value)))*100 "Cache hit ratio"
5 FROM v$sysstat cur, v$sysstat con, v$sysstat phy
6 WHERE cur.name='db block gets'
7 AND con.name='consistent gets'
8 AND phy.name='physical reads'
9 /

Physical Reads DB Block Gets Consistent Gets Cache hit ratio
============== ============= =============== ===============
4372475 737385 17855646 -22.516741


1 SELECT phy.value "Physical Reads",
2 cur.value "DB Block Gets",
3 con.value "Consistent Gets",
4 1-((v(phy.value))/((v(cur.value))+(v(con.value))))*100 "Cache hit ratio"
5 FROM v$sysstat cur, v$sysstat con, v$sysstat phy
6 WHERE cur.name='db block gets'
7 AND con.name='consistent gets'
8* AND phy.name='physical reads'
9 /

Physical Reads DB Block Gets Consistent Gets Cache hit ratio
============== ============= =============== ===============
4421265 741421 18892425 -21.518589

My Question:

Why i am still getting cache hit ratio in -ve ? V is the name of function u suggested.

CREATE OR REPLACE FUNCTION "CR"."V" ( p_num in number )
return number
as
begin
return to_number(substr( to_char(p_num,'fm'||rpad('0',15,'0')||'x'), 9
), rpad('x',8,'x'));
end;


Regards

Tom Kyte
April 02, 2003 - 8:10 am UTC

you have your parans in the wrong place.

it is

( 1 - PIO/LIO ) * 100

you have

1 - (PIO/LIO)*100




Negative buffer cache ration

vijay k bangera, August 07, 2003 - 3:57 pm UTC

Tom,

Please answer only if relevent. Do you think the function that strips the high bytes in calculating the ratio work for all types of OS or version of OS irrespective of whether it is 32 or 64 bit machine?



Tom Kyte
August 10, 2003 - 11:00 am UTC

should work regardless.  you'll know right away if it doesn't ;)

It just takes a number -- turns it into a 16 character hex string and then returns only the last 8 hex char's:

ops$tkyte@ORA920> select to_char(:x,'fm'||rpad('0',15,'0')||'x') from dual;

TO_CHAR(:X,'FM'||
-----------------
fffffff6d6fa3340

ops$tkyte@ORA920> select substr( to_char(:x,'fm'||rpad('0',15,'0')||'x'), 9 ) from dual;

SUBSTR(TO
---------
d6fa3340

ops$tkyte@ORA920> select to_number(substr( to_char(:x,'fm'||rpad('0',15,'0')||'x'), 9 ), rpad('x',8,'x')) result from dual;

    RESULT
----------
3606721344


 

A reader, July 12, 2006 - 7:37 am UTC

Is it still right is 10 G that Buffer Cache Hit Ratio has no importance. You referred to "Why a 99%+ Database Buffer Cache Hit Ratio is Not Ok" from hotsos.com

Tom Kyte
July 12, 2006 - 4:45 pm UTC

It is not of "no importance"

It just has never been "a goal"

and nothing about that has changed.


99% does not mean "good"
99.99999% does not mean "good"

it just means 99% of the requests where fed from the buffer cache without going to disk. It does not mean you are going to cache as infrequently as you should (eg:

</code> http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:6749454952894#6760861174154 <code>

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library