Hello Tom
I want to ask what should be the correct approach for a enterprise standard on statstics gathering (for Oracle DBs). The point is we want to keep it as standard as possible for new builds, upgrades and migrations as possible, but in the meantime are flexible enough to go "on-demand" changes in statistics gathring (like addressing special needs on skipping stats, being more frequent, building histograms etc.).
Right now, what we are doing to our 10g and 11g DBs is:
spool analyze_no_stat.list
select 'exec dbms_stats.gather_table_stats(ownname=>'||chr(39)||owner||chr(39)||',tabname=>'||chr(39)||table_name||chr(39)||',estimate_percent=>$epct,degree=>$dgr,cascade=>TRUE);'
from (select owner,table_name from dba_tables
where owner not in ('SYS','SYSTEM','SYSMAN','DBSNMP','OUTLN','PUBLIC','SCOTT','OPS\$ORACLE','CTXSYS','WKSYS','WMSYS','ORDSYS','MDSYS','TSMSYS','APPLSYS')
and owner not in ('PERFSTAT')
and table_name not like '%IOT_OVER%'
and temporary = 'N'
and table_name = upper(table_name)
and (owner,table_name) not in (select owner,table_name from dba_external_tables)
and table_name not in (select distinct table_name from dba_tab_partitions)
and last_analyzed is null)
/
spool off
Also we change the above query to order by last_analyzed or do a last_analyzed < (sysdate - 5) etc and call it analyze_oldest.list or analyze_stale.list etc and run it alternately.
The problem is, in some cases, we've come across scenarios where we gather stats on a bunch of tables with method_opt=>'for all columns' and building histograms helps us a lot. I understand we can't be doing one or the other thing without much analysis, but want to know if there's a preferred approach?
Thanks!