什么是system statistics
System statistics describe the system's hardware characteristics, such as I/O and CPU performance and utilization, to the query optimizer. When choosing an execution plan, the optimizer estimates the I/O and CPU resources required for each query. System statistics enable the query optimizer to more accurately estimate I/O and CPU costs, enabling the query optimizer to choose a better execution plan.
--描述系统硬件特性,比如I/O和CPU的性能,当选择执行计划时,优化器需要评估每个query所需的I/O和CPU资源,system statistics能帮助优化器选择最佳执行计划;
System statistics又分为workload和noworkload,通过执行dbms_stats.gather_system_stats完成,但用户必须具备DBA或者gather_system_statistics权限以更新相应数据字典;
Oracle收集完system statistics后不会invalidate已经解析的sql,这一点不同于常见的统计信息,但新解析的sql会使用到新的统计信息;
什么是workload statistics
Workload statistics, introduced in Oracle 9i, gather single and multiblock read times, mbrc, CPU speed (cpuspeed), maximum system throughput, and average slave throughput. The sreadtim, mreadtim, and mbrc are computed by comparing the number of physical sequential and random reads between two points in time from the beginning to the end of a workload. These values are implemented through counters that change when the buffer cache completes synchronous read requests. Since the counters are in the buffer cache, they include not only I/O delays, but also waits related to latch contention and task switching. Workload statistics thus depend on the activity the system had during the workload window. If system is I/O bound—both latch contention and I/O throughput—it will be reflected in the statistics and will therefore promote a less I/O intensive plan after the statistics are used. Furthermore, workload statistics gathering does not generate additional overhead.
--9i引入,主要是收集系统的I/O和CPU性能信息用以调节系统性能;假如现在系统I/O比较繁忙,信息收集完成后系统则倾向于生存消耗I/O较少的执行计划,且此操作不会对系统产生额外压力;
如何收集
--有两种方法
1 调用dbms_stats.gather_system_stats(‘start’)开始收集,dbms_stats.gather_system_stats(‘stop’)手工结束
2 调用dbms_stats.gather_system_stats(‘interval’, interval => N),指定运行时间到时会自动结束
--可调用dbms_stats.delete_system_stats()删除
多块读和MBRC
在10.2中,优化器使用mbrc来预测全表扫描,而数据库一次I/O所能读取的最大块数目则由db_file_mutiblock_read_count决定;
但在实际情形中,至少以下三种情况会导致oracle无法读取最大块
1 段头需要单块读
2 物理读不能跨越多个extent
3 若数据块已在buffer cache中,除非direct path read,否则不会再次从磁盘读取
因为并非每次多块读都会读取db_file_multiblock_read_count定义的数值,故oracle引入mbrc替代其计算IO cost,
其公式为io_cost =(blocks/mbrc)*(mreadtim/sreadtim);
只有当workload statistics不可用时,才使用db_file_multiblock_read_count,公式大致为io_cost = blocks/(1.6765*db_file_multiblock_read_count(0.6581)),
此时该参数值越大,系统则越倾向使用全表扫描;
还有一点需要注意,在收集工作量统计信息的时候如果系统没有全表扫描,则mbrc和mreadtim可能不被收集,oracle则可能只用cpuspeed和sreadtim计算costing,
全表扫描时会沿用以前版本的算法(10R2之前)。
什么是noworkload statistics
非工作量统计信息包含I/O transfer speed, I/O seek time和CPU speed(cpuspeednw),与工作量统计信息最主要的差别在于收集方法的不同,应在系统没有负载的时候进行;
Noworkload statistics gather data by submitting random reads against all data files, while workload statistics uses counters updated when database activity occurs.
Isseektim即磁盘寻道时间,一般为5-15ms,取决于磁盘转速和存储性能;
i/o transfer speed为系统进程从I/O子系统读取数据的速度,其范围波动比较大,从几兆到几百兆不等;
非工作量统计信息在实例启动时会自动被初始化;
Ioseektim = 10ms
Iotrfspeed = 4096 bytes/ms
Cpuspeednw = gatherer value, varied based on system
当工作量统计信息被收集后,非工作量统计信息则会被忽略;
如何收集noworkload statistics
直接调用dbms_stats.gather_system_stats()(不带任何参数),将会占有一定的I/O开销,也可手工设置dbms_stats.set_system_stats;
当系统统计信息可用时,oracle会计算I/O cost和CPU cost,上面列出了I/O cost的计算公式,关于cpu cost,Joze Senegacnik 给出过访问一个列的cost
Cpu_cost = column_position * 20,当列位置越靠后其cpu cost就越高;
由于I/O cost和CPU cost的计算单位不同,不能直接相加,可用以下公式作参考
Cost = io_cost + cpu_cost/(cpuspeed * sreadtim * 1000)—非工作量统计信息则把cpuspeed替换为cpuspeednw
通过查询AUX_STATS$可以看出当前系统统计信息
SQL> select * from AUX_STATS$;
SNAME PNAME PVAL1 PVAL2
------------------------------ ------------------------------ ---------- ------------------------------
SYSSTATS_INFO STATUS COMPLETED
SYSSTATS_INFO DSTART 07-16-2010 07:46
SYSSTATS_INFO DSTOP 07-16-2010 07:46
SYSSTATS_INFO FLAGS 1
SYSSTATS_MAIN CPUSPEEDNW 1899.72752
SYSSTATS_MAIN IOSEEKTIM 10
SYSSTATS_MAIN IOTFRSPEED 4096
SYSSTATS_MAIN SREADTIM
SYSSTATS_MAIN MREADTIM
SYSSTATS_MAIN CPUSPEED
SYSSTATS_MAIN MBRC
SYSSTATS_MAIN MAXTHR
SYSSTATS_MAIN SLAVETHR
|
Parameter Name |
Description |
Initialization |
Options for Gathering or Setting Statistics |
Unit |
|
cpuspeedNW |
Represents noworkload CPU speed. CPU speed is the average number of CPU cycles in each second. |
At system startup |
Set gathering_mode = NOWORKLOAD or set statistics manually. |
Millions/sec. |
|
ioseektim |
I/O seek time equals seek time + latency time + operating system overhead time. |
At system startup 10 (default) |
Set gathering_mode = NOWORKLOAD or set statistics manually. |
ms |
|
iotfrspeed |
I/O transfer speed is the rate at which an Oracle database can read data in the single read request. |
At system startup 4096 (default) |
Set gathering_mode = NOWORKLOAD or set statistics manually. |
Bytes/ms |
|
cpuspeed |
Represents workload CPU speed. CPU speed is the average number of CPU cycles in each second. |
None |
Set gathering_mode = NOWORKLOAD, INTERVAL, or START|STOP, or set statistics manually. |
Millions/sec. |
|
maxthr |
Maximum I/O throughput is the maximum throughput that the I/O subsystem can deliver. |
None |
Set gathering_mode = NOWORKLOAD, INTERVAL, or START|STOP, or set statistics manually. |
Bytes/sec. |
|
slavethr |
Slave I/O throughput is the average parallel slave I/O throughput. |
None |
Set gathering_mode = INTERVAL or START|STOP, or set statistics manually. |
Bytes/sec. |
|
sreadtim |
Single block read time is the average time to read a single block randomly. |
None |
Set gathering_mode = INTERVAL or START|STOP, or set statistics manually. |
ms |
|
mreadtim |
Multiblock read is the average time to read a multiblock sequentially. |
None |
Set gathering_mode = INTERVAL or START|STOP, or set statistics manually. |
ms |
|
mbrc |
Multiblock count is the average multiblock read count sequentially. |
None |
Set gathering_mode = INTERVAL or START|STOP, or set statistics manually. |
blocks |
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/15480802/viewspace-736516/ ,如需转载,请注明出处,否则将追究法律责任。