FAQ: Automatic Statistics Collection (文档 ID 1233203.1)
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 |
APPLIES TO:
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.
PURPOSE
QUESTIONS AND ANSWERS
What kind of statistics do the Automated tasks collect
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.
How do I revert to a previous set of statistics?
From Oracle 10g, Oracle retains collected statistics for 31 days after they are changed.
Refer to:
Does the automatic statistic collection jobs populate CHAIN_CNT?
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.
11g+ Automatic Maintenance Tasks
What is the name of the default stats gathering job on 11g?
The automatic statistics gathering job on 11g is called "auto optimizer stats collection".
What are the default windows for the automated maintenance task to run?
In 11g daily maintenance windows are provided. by default these are defined as :
- Weeknights: Starts at 10 p.m. and ends at 2 a.m.
- Weekends: Starts at 6 a.m. is 20 hours long.
See:
Oracle® Database Administrator's Guide
11g Release 2 (11.2)
Part Number E17120-05
Automated Maintenance Tasks Reference
Table 26-1 Predefined Maintenance Windows
http://docs.oracle.com/cd/E18283_01/server.112/e17120/tasks006.htm#CIHJHGCADocument 743507.1 How to Benefit from Automatic Maintenance Tasks Following the Removal of the GATHER_STATS_JOB in 11g?
How do you change the default windows for the automated maintenance task to run?
Maintenance windows can be modified using the DBMS_SCHEDULER PL/SQL package. For details see:
Oracle® Database Administrator's Guide
11g Release 2 (11.2)
Part Number E17120-05
Configuring Maintenance Windows
http://docs.oracle.com/cd/E18283_01/server.112/e17120/tasks004.htmHere is an example to change the default time for the daily maintenance window for example to 2:00 AM instead of 10:00 PM using the following commands :
BEGIN
dbms_scheduler.disable(
name => 'SATURDAY_WINDOW');
dbms_scheduler.set_attribute(
name => 'SATURDAY_WINDOW',
attribute => 'repeat_interval',
value => 'freq=daily;byday=SAT;byhour=02;byminute=0;bysecond=0');
dbms_scheduler.enable(
name => 'SATURDAY_WINDOW');
END;
/BEGIN
dbms_scheduler.disable(
name => 'SUNDAY_WINDOW');
dbms_scheduler.set_attribute(
name => 'SUNDAY_WINDOW',
attribute => 'repeat_interval',
value => 'freq=daily;byday=SUN;byhour=02;byminute=0;bysecond=0');
dbms_scheduler.enable(
name => 'SUNDAY_WINDOW');
END;
/BEGIN
dbms_scheduler.disable(
name => 'MONDAY_WINDOW');
dbms_scheduler.set_attribute(
name => 'MONDAY_WINDOW',
attribute => 'repeat_interval',
value => 'freq=daily;byday=MON;byhour=02;byminute=0;bysecond=0');
dbms_scheduler.enable(
name => 'MONDAY_WINDOW');
END;
/BEGIN
dbms_scheduler.disable(
name => 'TUESDAY_WINDOW');
dbms_scheduler.set_attribute(
name => 'TUESDAY_WINDOW',
attribute => 'repeat_interval',
value => 'freq=daily;byday=TUE;byhour=02;byminute=0;bysecond=0');
dbms_scheduler.enable(
name => 'TUESDAY_WINDOW');
END;
/BEGIN
dbms_scheduler.disable(
name => 'WEDNESDAY_WINDOW');
dbms_scheduler.set_attribute(
name => 'WEDNESDAY_WINDOW',
attribute => 'repeat_interval',
value => 'freq=daily;byday=WED;byhour=02;byminute=0;bysecond=0');
dbms_scheduler.enable(
name => 'WEDNESDAY_WINDOW');
END;
/BEGIN
dbms_scheduler.disable(
name => 'THURSDAY_WINDOW');
dbms_scheduler.set_attribute(
name => 'THURSDAY_WINDOW',
attribute => 'repeat_interval',
value => 'freq=daily;byday=THU;byhour=02;byminute=0;bysecond=0');
dbms_scheduler.enable(
name => 'THURSDAY_WINDOW');
END;
/BEGIN
dbms_scheduler.disable(
name => 'FRIDAY_WINDOW');
dbms_scheduler.set_attribute(
name => 'FRIDAY_WINDOW',
attribute => 'repeat_interval',
value => 'freq=daily;byday=FRI;byhour=02;byminute=0;bysecond=0');
dbms_scheduler.enable(
name => 'FRIDAY_WINDOW');
END;
/Whats new/changed in 11g with respect to automatic statistics collection?
The GATHER_STATS_JOB does not exist in 11g (the name does not exist). Instead it has been included in Automatic Maintenance Tasks. The accuracy of the statistics gathered has been significantly improved by the implementation of a better version of AUTO_SAMPLE_SIZE. In 11g, using auto size for ESTIMATE_PERCENT defaults to 100% and therefore is as accurate as possible for the table itself. In prior versions a 100% sample may have been impossible due to time collection constraints, however 11g implements a new hashing algorithm to compute the statistics rather than sorting (in 9i and 10g the "slow" part was typically the sorting) which significantly improves collection time and resource usage. There is more on this in the following blog:
http://blogs.oracle.com/optimizer/entry/how_does_auto_sample_sizeThe following are the tasks that AutoTask automatically schedules in these maintenance windows:
select CLIENT_NAME from DBA_AUTOTASK_CLIENT CLIENT_NAME
----------------------------------------------------------------
auto optimizer stats collection
auto space advisor
sql tuning advisorHow to enable auto stats collection?
If for some reason automatic optimizer statistics collection is disabled, you can enable it using the ENABLE procedure in the DBMS_AUTO_TASK_ADMIN package:
exec DBMS_AUTO_TASK_ADMIN.ENABLE(
client_name => 'auto optimizer stats collection',
operation => NULL,
window_name => NULL);How to disable the auto stats collection?
In situations when you want to disable automatic optimizer statistics collection, you can disable it using the DISABLE procedure in the DBMS_AUTO_TASK_ADMIN package:
exec DBMS_AUTO_TASK_ADMIN.DISABLE(
client_name => 'auto optimizer stats collection',
operation => NULL,
window_name => NULL);How can I check the status of the 'auto optimizer stats collection'?
The status of the automatic statistics collection can be checked using:
select client_name, JOB_SCHEDULER_STATUS
from DBA_AUTOTASK_CLIENT_JOB
where client_name='auto optimizer stats collection';The possible Job status:
- DISABLED
- RETRY SCHEDULED
- SCHEDULED
- RUNNING
- COMPLETED
- BROKEN
- FAILED
- REMOTE
- SUCCEEDED
- CHAIN_STALLED
How can I check whether or not the database has the 'auto optimizer stats collection' job enabled to run during the next maintenance window?
SELECT CLIENT_NAME,
STATUS
FROM DBA_AUTOTASK_CLIENT
WHERE CLIENT_NAME = 'auto optimizer stats collection';How can I see the history of the automatic stats job for each day?
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 2How to manually execute the Optimizer Statistics Auto Task?
In 11g the Auto-Task infrastructure replaced the need for the gather_stats_job and you can execute the following command to accomplish manual statistics collection:
SQL> exec DBMS_AUTO_TASK_IMMEDIATE.GATHER_OPTIMIZER_STATS;
This will prompt the Automated Maintenance Tasks subsystem into starting a job that will gather optimizer statistics, unless such a job is already running (for example if a maintenance window is currently open). If an immediate job is created it will be named ORA$_AT_OS_MANUAL_nnnnnn (nnnnn is one or more decimal digits). Unlike regular Automated Maintenance jobs, the "MANUAL" job is not tied to a specific maintenance window.
How do to check values of parameter( estimate percent, type of histograms etc) used by the job?
DBMS_STATS.GET_PARAM (pname IN VARCHAR2) RETURN VARCHAR2;
If there were any non-default preferences set for the job:
DBMS_STATS.GET_PREFS (pname IN VARCHAR2,ownname IN VARCHAR2 DEFAULT NULL, tabname IN VARCHAR2 DEFAULT NULL)
RETURN VARCHAR2;Possible preferences: -
- AUTOSTATS_TARGET
- CASCADE
- DEGREE
- ESTIMATE_PERCENT
- METHOD_OPT
- NO_INVALIDATE
- GRANULARITY
- PUBLISH
- INCREMENTAL
- STALE_PERCENT
How to set preference for the next maintenance job run to pick?
The automatic statistics-gathering job uses the default parameter values for the DBMS_STATS procedures. If you wish to change these default values you can use the DBMS_STATS.SET_GLOBAL_PREFS procedure. Remember these values will be used for all schemas including 'SYS'. There are 2 different procedures that you can use to set parameters depending on whether you have existing preferences or not:
- SET_GLOBAL_PREFS - This procedure enables you to change the default values of the parameters used by the DBMS_STATS.GATHER_*_STATS procedures for any object in the database that does not have an existing table preference or for any new objects created after this.
- SET_DATABASE_PREFS - This procedure enables you to change the default values of the parameters used by the DBMS_STATS.GATHER_*_STATS procedures for all user-defined schemas in the database.
How to I change the "STALE PERCENT", for example?
If the stale percentage does not collect statistics frequently enough to reflect changes in the data accurately, then you can use the "DBMS_STATS.SET_GLOBAL_PREFS" procedure to change this (and other parameters) so that statistics are collected more frequently in future. For Example:
To change the 'STALE_PERCENT' you can use:exec DBMS_STATS.SET_GLOBAL_PREFS('STALE_PERCENT','5');Note that if you only want to do this for a small subset of the objects and not all of them, you may be better creating a custom statistics gathering schemeDoes the auto stats gathering job gather statistics on all schemas in the instance?
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:
Document 457926.1 How to Gather Statistics on SYS Objects and 'Fixed' Objects?Oracle® Database SQL Tuning Guide
12c Release 1 (12.1)
E15858-15
Chapter 12 Managing Optimizer Statistics: Basic Topics
Section 12.4.5 Gathering Statistics for Fixed Objects
http://docs.oracle.com/cd/E16655_01/server.121/e15858/tgsql_stats.htm#CHDDGHBAWhat is the AUTOSTATS_TARGET of SET_GLOBAL_PREFS?
This additional parameter controls which objects the automatic statistic gathering job (that runs in the nightly maintenance window) will monitor. The possible values for this parameter are:
- ALL
This setting means that the automatic statistics gathering job will gather statistics on all objects in the database.
From 12c this includes statistics on fixed objects. See:Oracle® Database SQL Tuning Guide
12c Release 1 (12.1)
E15858-15
Chapter 12 Managing Optimizer Statistics: Basic Topics
Section 12.4.5 Gathering Statistics for Fixed Objects
http://docs.oracle.com/cd/E16655_01/server.121/e15858/tgsql_stats.htm#CHDDGHBAOn 11g and below this was APART FROM statistics on fixed objects.
Since Fixed objects record current database activity, the representative workload you want to capture may not be active at the time of automatic statistics collection. You should gather statistics when the database has representative activity. You can manually collect statistics on fixed objects, such as the dynamic performance tables, using GATHER_FIXED_OBJECTS_STATS procedure.
- ORACLE
ORACLE means that the automatic statistics gathering job will only gather statistics for Oracle owned schemas (sys, system, etc) - AUTO (default)
means that Oracle will decide what objects to gather statistics on. Currently AUTO and ALL behave the same.
- ALL
How does auto optimizer stats collection prioritize which tables are analyzed first?
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.
How do you disable automatic statistics gathering for a specific schema?
You can do this by using DBMS_STATS.LOCK_SCHEMA_STATS to lock the statistics. See:
Document 283890.1 Preserving Statistics using DBMS_STATS.LOCK_TABLE_STATSIs there be any reason to gather full schema stats regularly in addition to the automatic stats gathering job?
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.
10g Collection: Via GATHER_STATS_JOB
What is the name of the default stats gathering job on 10g?
The automatic statistics gathering job on 10g is called "GATHER_STATS_JOB"
What are the default windows for the GATHER_STATS_JOB ?
In 10g, Two Scheduler windows are predefined upon installation of Oracle Database:
- WEEKNIGHT_WINDOW starts at 10 p.m. and ends at 6 a.m. every Monday through Friday.
- WEEKEND_WINDOW covers whole days Saturday and Sunday.
Together these windows constitute the MAINTENANCE_WINDOW_GROUP in which all system maintenance tasks are scheduled.
How do you disable the GATHER_STATS_JOB?
The most direct approach is to disable the GATHER_STATS_JOB as follows:
SQL> exec sys.dbms_scheduler.disable ('GATHER_STATS_JOB');How do you enable the GATHER_STATS_JOB?
This is enabled by default. If you have disabled it, then you can re-enable it as
SQL> exec sys.dbms_scheduler.enable ("SYS"."GATHER_STATS_JOB");
How do you Determine That the GATHER_STATS_JOB Completed
SELECT job_name, state
FROM dba_scheduler_jobs
WHERE job_name='GATHER_STATS_JOB';There are four types of jobs that are not running:
- FAILED
- BROKEN
- DISABLED
- COMPLETED
Note that if a job has recently completed successfully, but is scheduled to run again, the job state is set to 'SCHEDULED'. A job is marked as 'COMPLETED' if 'end_date' or 'max_runs' (in dba_scheduler_jobs) is reached.How to Change the NEXT_RUN_DATE on the GATHER_STATS_JOB ?
You can adjust the predefined maintenance windows to a time suitable to your database environment using the DBMS_SCHEDULER.SET_ATTRIBUTE procedure
For Example:
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;to run job on weekends only:
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"' );
REFERENCES
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)的更多相关文章
- 11i - 12 Gather Schema Statistics fails with Ora-20001 errors after 11G database Upgrade (文档 ID 781813.1)
11i - 12 Gather Schema Statistics fails with Ora-20001 errors after 11G database Upgrade (文档 ID 7818 ...
- [转载]——Automatic Tuning of Undo_retention Causes Space Problems (文档 ID 420525.1)
Automatic Tuning of Undo_retention Causes Space Problems (文档 ID 420525.1) 转到底部 In this Document Sy ...
- 针对数据泵导出 (expdp) 和导入 (impdp)工具性能降低问题的检查表 (文档 ID 1549185.1)
针对数据泵导出 (expdp) 和导入 (impdp)工具性能降低问题的检查表 (文档 ID 1549185.1) 文档内容 适用于: Oracle Database – Enterprise Edi ...
- Rolling Cursor Invalidations with DBMS_STATS.AUTO_INVALIDATE (文档 ID 557661.1)
Rolling Cursor Invalidations with DBMS_STATS.AUTO_INVALIDATE (文档 ID 557661.1) 转到底部 In this Documen ...
- ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决方案(文档ID 1623284.1)
ORA-01578和ORA-26040--NOLOGGING操作引起的坏块-错误解释和解决方案(文档ID 1623284.1) (一)NOLOGGING操作引起的坏块(ORA-01578和ORA-26 ...
- 转://【MOS】关于在不同版本和平台之间进行还原或复制的常见问题 (文档 ID 1526162.1)--跨版本恢复
Questions and Answers 1) 我能用更高版本的 Oracle 还原或复制旧版本的数据库吗? 2) 我能在两个不同的补丁程序集之间进行还原或复制吗? 3) 我能在同一操作系统的不同版 ...
- xtts v4for oracle 11g&12c(文档ID 2471245
xtts v4for oracle 11g&12c(文档ID 2471245.1) 序号 主机 操作项目 操作内容 备注: 阶段一:初始阶段 1.1 源端 环境验证 migrate_check ...
- OERR: ORA-1410 "invalid ROWID" Master Note / Troubleshooting, Diagnostic and Solution (文档ID 1410.1)
OERR: ORA-1410 "invalid ROWID" Master Note / Troubleshooting, Diagnostic and Solution (文档I ...
- sphinx索引分析——文件格式和字典是double array trie 检索树,索引存储 – 多路归并排序,文档id压缩 – Variable Byte Coding
1 概述 这是基于开源的sphinx全文检索引擎的架构代码分析,本篇主要描述index索引服务的分析.当前分析的版本 sphinx-2.0.4 2 index 功能 3 文件表 4 索引文件结构 4. ...
随机推荐
- 查看SQL执行计划
一用户进入某界面慢得要死,查看SQL执行计划如下(具体SQL语句就不完全公布了,截断的如下): call count cpu elapsed disk ...
- (转帖)BootStrap入门教程 (一)
2011年,twitter的“一小撮”工程师为了提高他们内部的分析和管理能力,用业余时间为他们的产品构建了一套易用.优雅.灵活.可扩展的前端工具集--BootStrap.Bootstrap由MAR ...
- 会话控制:SESSION,COOKIE
1.http协议: HTTP—超文本传输协议,在TCP协议(长连接.像一个硬件)基础上; 特点:短连接,无状态协议,没法记录本次连接的状态;适用于静态页面的访问,对于后期某些页面是需要浏览器预知客户信 ...
- 微信浏览器里location.reload问题
微信浏览器里location.reload问题会导致有时候post数据丢失.建议不要用此方式,尽量ajax方式获取或不要为了获取新的UI而刷新页面 2015-12-26 00:51:34array ( ...
- .NET去掉HTML标记
using System.Text.RegularExpressions; /// <summary> /// 去除HTML标记 /// </summary> /// < ...
- Python基础(二) —— 字符串、列表、字典等常用操作
一.作用域 对于变量的作用域,执行声明并在内存中存在,该变量就可以在下面的代码中使用. 二.三元运算 result = 值1 if 条件 else 值2 如果条件为真:result = 值1如果条件为 ...
- 高性能MySQL --- 读书笔记(2) - 2016/8/2
第1章 MySQL架构 MySQL架构与其他数据库服务器大不相同,这使它能够适应广泛的应用.MySQL足够灵活,能适应高要求架构.例如Web应用,同时还适用于嵌入式应用.数据仓库.内容索引和分发软件. ...
- 战胜忧虑<2>——忙碌可以消除忧虑
忙碌可以消除忧虑 当你的脑筋空出来时,也会有东西进去补充,是什么呢?通常都是你的感觉.为什么?因为忧虑.恐惧.憎恨.嫉妒.和羡慕等等情绪,都是由我们的思想所控制的,这种情绪都非常猛烈.会把我们思想中所 ...
- HDU3516 树的构造
题目大意:平面上有n个点,构成一个单调递减的序列.即对于任意的i<j,有xi<xj,yi>yj.现在要用一棵树连接这n个点.树边为有向边,只能向右或向上.求最小的权值. 分析:本题其 ...
- [hibernate]基本值类型映射之日期类型
hibernate基本值类型映射中日期类型支持date,time,timestamp这三个选项,其中 date:对应数据库中的date类型,表示只显示日期 time:对应数据库中的time类型,表示只 ...