Want to post your scripts here in this blog ? Email it to snojha@gmail.com. You will be rewarded for your scripts if selected by our experts.

Wednesday, May 20, 2009

Find the tables/indexes that have stale statistics in a database

Using the code below one can find the tables/indexes that have stale statistics in a database, when options=>’GATHER AUTO’
is used oracle gathers statistics analyzes the tables/indexes that have stale statistics. Table monitoring is
enabled by default in 10g to find table which is used to find table statistics, when STATISTICS_LEVEL is set
to BASIC table monitoring is disabled. In 9i one can enable/disable table monitoring by
calling DBMS_STATS.ALTER_SCHEMA_TABLE_MONITORING

SQL> SET SERVEROUTPUT ON

SQL> DECLARE
ObjList dbms_stats.ObjectTab;
BEGIN
dbms_stats.gather_database_stats(objlist=>ObjList, options=>’LIST STALE’);
FOR i in ObjList.FIRST..ObjList.LAST
LOOP
dbms_output.put_line(ObjList(i).ownname || ‘.’ || ObjList(i).ObjName || ‘ ‘ || ObjList(i).ObjType || ‘ ‘ || ObjList(i).partname);
END LOOP;
END;
/

SYS.COL_USAGE$ TABLE
SYS.DEPENDENCY$ TABLE
SYS.HISTGRM$ TABLE
SYS.HIST_HEAD$ TABLE


Note: To find schema level stats that are stale one can call
DBMS_STATS.GATHER_SCHEMA_STATS(ownname=>’SCOTT’, objlist=>ObjList, options=>’LIST STALE’);

2 comments:

Unknown said...


There are things in our life that is not eternal thus we stand still and never show weaknesses. This only means that we are strong enough to face everything either it is big or small. Visit my site for more good vibes and inspirational thoughts. Good day!

n8fan.net

www.n8fan.net

joemill00077711 said...

Good post. I study something more difficult on completely different blogs everyday. It is going to all the time be stimulating to read content material from other writers and practice slightly something from their store. I’d want to use some with the content on my blog whether you don’t mind. Natually I’ll give you a link on your web blog. Thanks for sharing. best online casinos