【信息统计】dbms_stat 的文档

简介:

General
Note: The drawback to collecting REDUNDANT column stats is that they have to be loaded into the dictionary cache, and they have to be considered when the query is optimised. This waste shared pool space and CPU.

On the other hand, if the statistics add value about the data - which does mean EVEN on unindexed columns - queries can run faster.

Most systems should have only a few column histograms in place, but there is no obvious requirement that they should only be on indexed columns.
Source {ORACLE_HOME}/rdbms/admin/dbmsstat.sql
First Available 8.1.5
Character Sets For DBMS_STATS to run properly may require the US numeric separators. If problems exist try the following:

alter session set NLS_NUMERIC_CHARACTERS='.,';

Constants Constant Data Type Usage
AUTO_CASCADE BOOLEAN Whether to collect statistics for indexes or not
AUTO_DEGREE NUMBER Select the degree of parallelism
AUTO_INVALIDATE BOOLEAN Decide when to invalidate dependent cursors
AUTO_SAMPLE_SIZE NUMBER Indicate that auto-sample size algorithms should be used
DEFAULT_DEGREE NUMBER Used to determine the system default degree of parallelism
 

Default Constants Constant Data Type Value
DEFAULT_CASCADE BOOLEAN NULL
DEFAULT_DEGREE_VALUE NUMBER 32766
DEFAULT_ESTIMATE_PERCENT NUMBER 101
DEFAULT_METHOD_OPT VARCHAR2(1) 'Z'
DEFAULT_NO_INVALIDATE BOOLEAN NULL
DEFAULT_GRANULARITY VARCHAR2(1) 'Z'
DEFAULT_PUBLISH BOOLEAN TRUE
DEFAULT_INCREMENTAL BOOLEAN FALSE
DEFAULT_STALE_PERCENT NUMBER 10
DEFAULT_AUTOSTATS_TARGET VARCHAR2(1) 'Z'
 

Method_opt Constants Accepts:

* FOR ALL [INDEXED | HIDDEN] COLUMNS [size_clause]
* FOR COLUMNS [size clause] column|attribute [size_clause] [,column|attribute [size_clause]...]

size_clause is defined as size_clause := SIZE {integer | REPEAT | AUTO | SKEWONLY}

- integer : Number of histogram buckets: Range [1,254].
- REPEAT : Collects histograms only on columns that already have
histograms.
- AUTO : Determines the columns to collect histograms based on
data distribution and the workload of the columns.
- SKEWONLY : Determines the columns to collect histograms based on
the data distribution of the columns.

The default is FOR ALL COLUMNS SIZE AUTO.The default value can be changed using the SET_PARAM Procedure.
Degree Constants Degree of parallelism. The default for degree is NULL. The default value can be changed using the SET_PARAM Procedure. NULL means use the table default value specified by the DEGREE clause in the CREATE TABLE or ALTER TABLE statement. Use the constant DBMS_STATS.DEFAULT_DEGREE to specify the default value based on the initialization parameters. The AUTO_DEGREE value determines the degree of parallelism automatically. This is either 1 (serial execution) or DEFAULT_DEGREE (the system default value based on number of CPUs and initialization parameters) according to size of the object.

Granularity Constants Granularity of statistics to collect (only pertinent if the table is partitioned).
Constant Description
ALL Gathers all (subpartition, partition, and global) statistics
AUTO Determines the granularity based on the partitioning type. This is the default value
DEFAULT Gathers global and partition-level statistics. This option is obsolete, and while currently supported, it is included in the documentation for legacy reasons only. You should use the 'GLOBAL AND PARTITION' for this functionality
GLOBAL Gathers global statistics
GLOBAL AND PARTITION gathers the global and partition level statistics. No subpartition level statistics are gathered even if it is a composite partitioned object
PARTITION gathers partition-level statistics
SUBPARTITION gathers subpartition-level statistics
 

Data Types TYPE numarray IS VARRAY(256) OF NUMBER;
TYPE datearray IS VARRAY(256) OF DATE;
TYPE chararray IS VARRAY(256) OF VARCHAR2(4000);
TYPE rawarray IS VARRAY(256) OF RAW(2000);
TYPE fltarray IS VARRAY(256) OF BINARY_FLOAT;
TYPE dblarray IS VARRAY(256) OF BINARY_DOUBLE;

TYPE StatRec IS RECORD (
epc    NUMBER,
minval RAW(2000),
maxval RAW(2000),
bkvals NUMARRAY,
novals NUMARRAY,
chvals CHARARRAY,
eavs   NUMBER);

Types for listing stale tables include:
TYPE ObjectElem IS RECORD (
ownname     VARCHAR2(30), -- owner
objtype     VARCHAR2(6),   -- 'TABLE' or 'INDEX'
objname     VARCHAR2(30), -- table/index
partname    VARCHAR2(30), -- partition
subpartname VARCHAR2(30), -- subpartition
confidence NUMBER);       -- not used

TYPE ObjectTab IS TABLE OF ObjectElem;
/

Dependencies SELECT name
FROM dba_dependencies
WHERE referenced_name = 'DBMS_STATS'
UNION
SELECT referenced_name
FROM dba_dependencies
WHERE name = 'DBMS_STATS';

Exceptions Error Code Reason
20000 Table already exists or insufficient privileges (or) Insufficient privileges
(or) Index does not exist or insufficient privileges (or) Object does not exist or insufficient privileges
20001 Tablespace does not exist (or) Bad input value (or) Invalid or inconsistent values in the user statistics table
20002 Bad user statistics table; may need to be upgraded
20003 Unable to set system statistics (or) Unable to gather system statistics
20004 Parameter does not exist (or) Error in the INTERVAL mode: system parameter job_queue_processes must be >0
20005 Object statistics are locked
20006 Unable to restore statistics, statistics history not available
 

Granularity Parameters Parameter Description
ALL Gathers all (subpartition, partition, and global) stats.
AUTO Determines the granularity based on the partitioning type, and collects the global, partition level and subpartition level statistics if the subpartitioning method is LIST, and the global and partition level only otherwise. This is the default value.
DEFAULT Gathers global and partition-level statistics. This option is obsolete, and while currently supported, it is included in the documentation for legacy reasons only. You should use the 'GLOBAL AND PARTITION' for this functionality. Note that the default value is now 'AUTO'.
GLOBAL Gathers global statistics.
GLOBAL AND PARTITION Gathers the global and partition level statistics. No subpartition level statistics are gathered even if it is a composite partitioned object.
PARTITION Gathers partition-level statistics.
SUBPARTITION Gathers subpartition-level statistics.
 

Options Parameters Parameter Description
GATHER Gathers statistics on all objects in the schema
GATHER AUTO Gathers all necessary statistics automatically. Oracle implicitly determines which objects need new statistics, and determines how to gather those statistics. When GATHER AUTO is specified, the only additional valid parameters are stattab, statid, objlist and statown; all other parameter settings are ignored. Returns a list of processed objects
GATHER STALE Gathers statistics on stale objects as determined by looking at the *_tab_modifications views. Also, return a list of objects found to be stale
GATHER EMPTY Gathers statistics on objects which currently have no statistics. Return a list of objects found to have no statistics
LIST AUTO Returns a list of objects to be processed with GATHER AUTO
LIST STALE Returns a list of stale objects determined by looking at the *_tab_modifications views
LIST EMPTY Returns a list of objects which currently have no statistics
 

pname Parameter for GET and SET PARAM Parameter Description
CASCADE The default value for CASCADE set by SET_PARAM is not used by export/import procedures.It is used only by gather procedures
DEGREE Degree of parallelism
ESTIMATE_PERCENT 
METHOD_OPT 'FOR COLUMNS REPEAT'
'FOR ALL COLUMNS SIZE REPEAT'
'FOR ALL COLUMNS SIZE 1'
NO_VALIDATE 
 

pname Parameter for GET_SYSTEM_STATS Parameter Description
CPUSPEED Average number of CPU cycles for each second, in millions, captured for the workload (statistics collected using 'INTERVAL' or 'START' and 'STOP' options)
SPUSPEEDNW Average number of CPU cycles for each second, in millions, captured for the noworkload (statistics collected using 'NOWORKLOAD' option
IOSEEKTIM Seek time + latency time + operating system overhead time, in milliseconds
IOTFRSPEED I/O transfer speed in bytes for each millisecond
MAXTHR Maximum I/O system throughput, in bytes/second
MBRC Average multiblock read count for sequential read, in blocks
MREADTIM Average time to read an mbrc block at once (sequential read), in milliseconds
SLAVETHR Average slave I/O throughput, in bytes/second
SREADTIM Average time to read single block (random read), in milliseconds
 
System Privileges For some of the DBMS_STATS procedures one or more of the following may be required:

ANALYZE ANY DICTIONARY
ANALYZE ANY
Enable automatic statistics collection exec dbms_scheduler.enable('GATHER_STATS_JOB');
Disable automatic statistics collection exec dbms_scheduler.disalbe('GATHER_STATS_JOB'); 

相关文章
|
5月前
|
安全 Linux
使用 stat命令查看文件信息
使用 stat命令查看文件信息
113 0
|
Oracle 关系型数据库 OLAP
[20160904]表统计信息lock.txt
[20160904]表统计信息lock.txt 晚上看链接:https://blogs.oracle.com/Database4CN/entry/%E8%AF%8A%E6%96%AD%E7%BB%9F%E8%AE%A1%E4%BF%A1%E6%81%AF%E4%B8...
946 0
|
SQL 网络协议 Oracle
[20151202]表统计信息stale百分比.txt
[20151202]表统计信息stale百分比.txt --昨天被别人问及一个问题缺省如果某个表修改信息超过10%,oracle即认为这个表需要重新统计分析。 --这个百分比如何计算的,实际上只要自己仔细观察就可以确定oracle如何算的。
868 0
|
关系型数据库 数据库 Oracle
oracle 统计信息收集包:DBMS_STATS
 DBMS_STATS包 DBMS_STAS包不仅能够对表进行分析,它还可以对数据库分析进行管理。 按照功能可以分一下几类: (1)       性能数据的收集 (2)       性能数据的设置 (3)       性能数据的删除 (4)     ...
1009 0
|
数据库 数据库管理
DBMS_STATS收集统计信息的问题及解决
收集数据库的统计信息是dba工作的一部分,如果在数据快速增长的库上,统计信息如果收集的频率太慢,会对执行计划有一定的影响。 而对于逐渐客户饱和的系统来说,统计信息就可以很长时间收集或者尽量不收集。
1361 0
|
SQL 算法 索引
使用dbms_stat采集统计信息时estimate_percent和cascade的默认值
收集统计信息可以用dbms_stats包,通常用这样的语法:exec dbms_stat.gather_table_stats(ownname=>'xxx', tabname=>'xxx', estimate_percent=>xxx, method_opt=>'xxx', cascade=>xxx); 其中estimate_percent表示选择的采样比例,如果太低,收集速度会快,但可能不会很准确,如果太高,收集速度会慢,但比较准确,各有利弊。
972 0
PLSQL_统计信息系列10_统计信息过旧导致程序出现性能问题
2014-11-15 Created By BaoXinjian 一、摘要 在性能的稳定数据库中,所有的job都需要在一定时间内完成 以前在一个银行系统中,突然某一个job原本在30minutes内完成的,但是在3hours之后,还在运行 排除了数据量大小变化的影响,需要查看该程序的解析计...
1024 0
|
监控
PLSQL_统计信息系列06_统计信息的历史和日志
20150506 Created By BaoXinjian  一、摘要 通过使用dbms_stats包来收集系统和对象的统计信息,在写新的统计信息时,系统会将当前的统计信息备份到数据字典中,从而保留一段时间的统计信息,如果新的统计信息导致低效的执行计划,可以恢复到旧的合适的统计信息 1.
781 0
|
关系型数据库
PLSQL_统计信息系列08_统计信息生成和还原
2015-02-01 Created By BaoXinjian 一、摘要 统计信息在重新生成后,发现并不能改善程序的性能,甚至更差的时候 Oracle提供了dbms_stat包,对统计信息进行还原 1.
746 0