Using the code below one can find the tables/indexes that have stale statistics in a schema, 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 10g when the value of statistics_level is “typical” or “all” table monitoring is turned enabled. In 9i one can enable/disable table monitoring by calling DBMS_STATS.ALTER_SCHEMA_TABLE_MONITORING,and in 11g [no]MONITORING get the bounce,default is monitoring.
<pre>
create or replace procedure show_stale(p_owner varchar2 default user)
is
v_objs dbms_stats.ObjectTab;
BEGIN
dbms_stats.gather_schema_stats(ownname=>upper(p_owner),objlist=>v_objs, options=>'LIST STALE');
FOR i in v_objs.FIRST..v_objs.LAST
LOOP
dbms_output.put_line(v_objs(i).ownname || '.' || v_objs(i).ObjName || ' ' || v_objs(i).ObjType || ' ' || v_objs(i).partname);
END LOOP;
END;
SQL> conn sys/ as sysdba
Enter password:
Connected.
SQL> set serveroutput on
SQL> exec show_stale;
SYS.APPLY$_SOURCE_SCHEMA TABLE
SYS.AQ$_ALERT_QT_H TABLE
SYS.AQ$_KUPC$DATAPUMP_QUETAB_S TABLE
SYS.ARGUMENT$ TABLE
SYS.CCOL$ TABLE
SYS.CDEF$ TABLE
SYS.COL$ TABLE
...
SQL> exec show_stale('topbox_xj');
TOPBOX_XJ.TOPBOX_ORG_SC_M_VIEW TABLE
PL/SQL procedure successfully completed.
</pre>
参考oraspin
<pre>
create or replace procedure show_stale(p_owner varchar2 default user)
is
v_objs dbms_stats.ObjectTab;
BEGIN
dbms_stats.gather_schema_stats(ownname=>upper(p_owner),objlist=>v_objs, options=>'LIST STALE');
FOR i in v_objs.FIRST..v_objs.LAST
LOOP
dbms_output.put_line(v_objs(i).ownname || '.' || v_objs(i).ObjName || ' ' || v_objs(i).ObjType || ' ' || v_objs(i).partname);
END LOOP;
END;
SQL> conn sys/ as sysdba
Enter password:
Connected.
SQL> set serveroutput on
SQL> exec show_stale;
SYS.APPLY$_SOURCE_SCHEMA TABLE
SYS.AQ$_ALERT_QT_H TABLE
SYS.AQ$_KUPC$DATAPUMP_QUETAB_S TABLE
SYS.ARGUMENT$ TABLE
SYS.CCOL$ TABLE
SYS.CDEF$ TABLE
SYS.COL$ TABLE
...
SQL> exec show_stale('topbox_xj');
TOPBOX_XJ.TOPBOX_ORG_SC_M_VIEW TABLE
PL/SQL procedure successfully completed.
</pre>
参考oraspin
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




