标签:
In this Document
Purpose |
Questions and Answers |
What kind of statistics do the Automated tasks collect |
How do I revert to a previous set of statistics? |
Does the automatic statistic collection jobs populate CHAIN_CNT? |
11g+ Automatic Maintenance Tasks |
What is the name of the default stats gathering job on 11g? |
What are the default windows for the automated maintenance task to run? |
How do you change the default windows for the automated maintenance task to run? |
Whats new/changed in 11g with respect to automatic statistics collection? |
How to enable auto stats collection? |
How to disable the auto stats collection? |
How can I check the status of the ‘auto optimizer stats collection‘? |
How can I check whether or not the database has the ‘auto optimizer stats collection‘ job enabled to run during the next maintenance window? |
How can I see the history of the automatic stats job for each day? |
How to manually execute the Optimizer Statistics Auto Task? |
How do to check values of parameter( estimate percent, type of histograms etc) used by the job? |
How to set preference for the next maintenance job run to pick? |
How to I change the "STALE PERCENT", for example? |
Does the auto stats gathering job gather statistics on all schemas in the instance? |
What is the AUTOSTATS_TARGET of SET_GLOBAL_PREFS? |
How does auto optimizer stats collection prioritize which tables are analyzed first? |
How do you disable automatic statistics gathering for a specific schema? |
Is there be any reason to gather full schema stats regularly in addition to the automatic stats gathering job? |
10g Collection: Via GATHER_STATS_JOB |
What is the name of the default stats gathering job on 10g? |
What are the default windows for the GATHER_STATS_JOB ? |
How do you disable the GATHER_STATS_JOB? |
How do you enable the GATHER_STATS_JOB? |
How do you Determine That the GATHER_STATS_JOB Completed |
How to Change the NEXT_RUN_DATE on the GATHER_STATS_JOB ? |
References |
Oracle Database - Personal Edition - Version 10.1.0.2 and later
Oracle Database - Standard Edition - Version 10.1.0.2 and later
Oracle Database - Enterprise Edition - Version 10.1.0.2 and later
Information in this document applies to any platform.
The statistics jobs automatically gather Missing and Stale statistics on tables, indexes and partitions for use by the Cost Based Optimizer (CBO) in determining the most optimal access paths for queries. The Automatic Statistics Gathering Job was built to assist with the collection of statistics from the start with newly created databases so that there are accurate statistics to use rather than relying on defaults. The statistics collected are generic one and not customized; however since they use "AUTO" by default, a number of decisions are automatically tailored to the data.
For many database these automatic statistics are adequate, however, since these provide basic and general statistics it may be possible to collect better statistics by customizing the statistics collection. The flexibility is there to allow you to gathers stats daily for some tables, collect hourly statistics for others and just once for static data. You can decide to collect more accurate statistics depending on the data volatility and the performance of the current statistics.
From Oracle 10g, Oracle retains collected statistics for 31 days after they are changed.
Refer to:
No. Chain count is not a statistic used as by the Optimizer and as such the job does not populate the chained rows information. Historically the legacy analyze command could be used to capture chain count but this functionality was not included in the DBMS_STATS package and is not collected by the automated jobs.
You can use the Automatic segment advisor for the purpose; it provides Chained row analysis??.
The automatic statistics gathering job on 11g is called "auto optimizer stats collection".
select CLIENT_NAME from DBA_AUTOTASK_CLIENT CLIENT_NAME ---------------------------------------------------------------- auto optimizer stats collection auto space advisor sql tuning advisor
exec DBMS_AUTO_TASK_ADMIN.ENABLE( client_name => ‘auto optimizer stats collection‘, operation => NULL, window_name => NULL);
exec DBMS_AUTO_TASK_ADMIN.DISABLE( client_name => ‘auto optimizer stats collection‘, operation => NULL, window_name => NULL);
select client_name, JOB_SCHEDULER_STATUS from DBA_AUTOTASK_CLIENT_JOB where client_name=‘auto optimizer stats collection‘;
SELECT client_name, window_name, jobs_created, jobs_started, jobs_completed FROM dba_autotask_client_history WHERE client_name like ‘%stats%‘; JOBS JOBS JOBS CLIENT_NAME WINDOW_NAME CREATED STARTED COMPLETED ------------------------------- ---------------- ------- -------- ---------- auto optimizer stats collection THURSDAY_WINDOW 1 1 1 auto optimizer stats collection SUNDAY_WINDOW 3 3 3 auto optimizer stats collection MONDAY_WINDOW 1 1 1 auto optimizer stats collection SATURDAY_WINDOW 2 2 2
SQL> exec DBMS_AUTO_TASK_IMMEDIATE.GATHER_OPTIMIZER_STATS;
DBMS_STATS.GET_PARAM (pname IN VARCHAR2) RETURN VARCHAR2;
DBMS_STATS.GET_PREFS (pname IN VARCHAR2,ownname IN VARCHAR2 DEFAULT NULL, tabname IN VARCHAR2 DEFAULT NULL) RETURN VARCHAR2;
exec DBMS_STATS.SET_GLOBAL_PREFS(‘STALE_PERCENT‘,‘5‘);
By default ‘auto optimizer stats collection‘ is controlled by the Global preference AUTOSTATS_TARGET which defaults to AUTO collecting all schemas including SYS. On 12c this includes fixed object statistics, however, on 11g it does not. See:
Accurate statistics are important on all objects. The GATHER_DATABASE_STATS_JOB_PROC procedure called by the ‘auto optimizer stats collection‘ job prioritizes database objects that have no statistics. This means that objects that most need statistics are processed first. Once these are done then objects with stale statistics are addressed. For these, there is no particular prioritization. The statistics may be ordered in some way but it is cursory, ordering by owner,object_name,part_name just to be consistent.
You can do this by using DBMS_STATS.LOCK_SCHEMA_STATS to lock the statistics. See:
If your data changes very frequently then it the automatic job may not collect the statistics frequently enough (for example, it may be collecting other tables on occasion) and so you may find that you get better statistics by manually collecting on that table to keep up with the changes that are happening. There may also be cases where the default sample size does not pick representative data and you need to select a different sample.
The automatic statistics gathering job on 10g is called "GATHER_STATS_JOB"
SQL> exec sys.dbms_scheduler.disable (‘GATHER_STATS_JOB‘);
SQL> exec sys.dbms_scheduler.enable (?"SYS"."GATHER_STATS_JOB");
SELECT job_name, state FROM dba_scheduler_jobs WHERE job_name=‘GATHER_STATS_JOB‘;
begin dbms_scheduler.disable(‘gather_stats_job‘); dbms_scheduler.set_attribute_null(‘gather_stats_job‘,‘schedule_name‘); dbms_scheduler.set_attribute(- ‘gather_stats_job‘,‘repeat_interval‘,- ‘freq=minutely;byminute=1,11,21,31,41,51;byhour=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,22,23;bysecond=0‘- ); dbms_scheduler.enable(‘gather_stats_job‘); end;
SQL> exec sys.dbms_scheduler.disable( ‘"SYS"."GATHER_STATS_JOB"‘ ); SQL> exec sys.dbms_scheduler.set_attribute( name => ‘"SYS"."GATHER_STATS_JOB"‘, attribute =>‘schedule_name‘, value => ‘SYS.WEEKEND_WINDOW‘); SQL> exec sys.dbms_scheduler.enable( ‘"SYS"."GATHER_STATS_JOB"‘ );
NOTE:452011.1 - Restoring Table Statistics
NOTE:457926.1 - How to Gather Statistics on SYS Objects and ‘Fixed‘ Objects?
NOTE:283890.1 - Preserving Statistics using DBMS_STATS.LOCK_TABLE_STATS
NOTE:743507.1 - How to Benefit from Automatic Maintenance Tasks Following the Removal of the GATHER_STATS_JOB in 11g?
FAQ: Automatic Statistics Collection (文档 ID 1233203.1)
标签:
原文地址:http://www.cnblogs.com/future2012lg/p/4352040.html