In this Document
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
To provide one stop shop for automated statistics collection (operation) provided in 10g and 11g.
For general questions on statistics gathering see the Statistics FAQ:
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:
-
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:
-
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_size
The 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 advisor
-
How 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 2
-
How 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 scheme
-
Does 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:
-
What 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:
On 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.
-
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:
-
Is 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?
参考至:https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=85576203901982&id=1233203.1&_adf.ctrl-state=trmk3tpwg_57
如有错误,欢迎指正
邮箱:czmcj@163.com
分享到:
相关推荐
# ethminer [!...[!...[!... > Ethereum miner with OpenCL, CUDA and stratum support ...**Ethminer** is an Ethash GPU mining worker: with ethminer you can mine every coin ... * PCI_BUS_ID - orders devices by PCI bus ...
V8版帮助文档:http://faq.duoduo123.com/v8/ 使用必看:http://faq.duoduo123.com/v8/scr/15-0.htm 新站常见问题解答:http://faq.duoduo123.com/v8/scr/17-1.htm 购买地址:http://auth.duoduo123.com 在线...
dubbo-doc-static 是 Dubbo 的文档镜像。 http://code.alibabatech.com/wiki/display/dubbo的拷贝。 HTML文件在分支gh-pages上,打包下载ZIP包。 关键的文档的链接: 用户指南: ...
android system webview 适配系统>=5.0
https://www.openssl.org/docs/faq.html what standards (RFC's) are implemented https://www.openssl.org/docs/standards.html manual pages的master下的所有内容 https://www.openssl.org/docs/manmaster/
在使用PhpMyAdmin进行数据库管理时,用户可能会遇到“export.php: Missing parameter: what (FAQ 2.8)”和“export.php: Missing parameter: export_type (FAQ 2.8)”的错误,这通常意味着在尝试导出数据时,系统...
jGuru 是一个非常流行的 Java 开发社区,提供了丰富的技术文档、FAQ、代码示例等资源。 2. 中文 JAVA 技术网-- 为 Java 爱好者服务推荐:http://www.cn-java.com/ - 中文 这是一个中文的 Java 开发社区,提供了丰富...
同时,对于遇到的问题,可以参考 FAQ 或者在线社区的讨论,寻找解决方案。 总的来说,ElementUI 是前端开发的强大工具,其离线文档则为开发者提供了便捷的学习和参考资料。无论是在新建项目还是维护现有项目时,...
换行Linux:\ n Windows:\ n \ r空格Linux:LF Windows:CR LF在NotePad ++软件中:编辑->文档格式转换->转为Windows。Auto.js开源版本已不再维护(原因参见Auto.js Pro FAQ),后续将仅维护Auto.js Pro专业版。请...
3. **Linux内核文档项目(LDP)**:`http://www.linuxdoc.org/`是LDP的主页,包含了大量关于Linux内核的指南、FAQ和HOWTO文档,对于学习和解决内核相关问题非常有帮助。 4. **GCC对C语言的扩展**:`...
v4.0使用手册(FAQ) Q:后台管理地址及默认账号? A:后台地址:admin/manage.asp 用户名和密码:admin/admin888 [注]为了安全,请使用前修改管理文件夹名admin,登陆之后,请及时新增管理员,并删 除初始管理员...
1. **权限控制**:当一个应用试图请求ROOT权限时,SuperSU会弹出提示,让用户决定是否授予该权限。这种透明度有助于防止恶意应用滥用ROOT权限。 2. **日志记录**:SuperSU会记录每个应用的权限使用情况,方便用户...
### 存储中间件-MQ常见问题解决方法FAQ #### 1. 无法创建MQ队列管理器 **错误现象**: ``` javax.jms.JMSException:MQJMS2005:未能为‘192.168.1.21:'创建MQQueueManager ``` **堆栈跟踪**: ```java at ...
1. **ClearWindow.py**:这是主要的Python源代码文件,其中包含了实现清屏功能的代码。可能包括一些特定的IDLE扩展接口调用,或者使用Python的Turtle库或者其他图形用户界面相关的库来模拟清屏操作。 2. **说明.txt*...
TradingView的中文开发文档详细介绍了其Charting Library图表库的使用方法,以及如何通过其JavaScript API将图表与个人或机构的数据源进行连接。此外,还涉及了如何自定义图表,创建个性化的研究工具,并介绍交易...
- **学习资源**: 包括教程、FAQ 和其他学习材料。 #### 廖雪峰 Python 教程 - **链接**: [https://www.liaoxuefeng.com/wiki/1016959663602400](https://www.liaoxuefeng.com/wiki/1016959663602400) - **介绍**: ...
1. **序列光线追踪**:这是一种传统的光线追踪方法,其中光线按顺序经过场景中的每个物体。这种方法适用于大多数情况,但对于某些特殊配置(如屋脊棱镜、光管等)则不太适用。 2. **非序列光线追踪**:对于那些不能...
- **简介**:这个网站是Java技术官方合作平台,提供最新的Java技术动态和技术文档,是学习和了解Java最新进展的最佳去处。 #### 2. **jGuru: FAQ Homepage 推荐** - **网址**:[http://www.jguru.com/faq/]...