oracle系统统计信息(一)

2014-11-24 08:55:59 · 作者: · 浏览: 1

系统统计信息主要描述了与系统硬件相关的某些特性,例如cpu和io系统的性能和利用率等。这些信息对于查询优化器来说是非常重要的,在选择执行计划的过程中,oracle优化器会利用系统统计信息来评估执行计划的成本,因此,准确无误的系统统计信息可以帮助优化器做出正确的选择。

我们可以通过DBMS_STATS.GATHER_SYSTEM_STATS过程来收集系统统计信息,收集的方式有两种:负载统计(WORKLOAD STATISTICS)在具有真实系统负载的数据库系统上,收集某一时间段内的系统信息;非负载统计(NOWORKLOAD STATISTICS)oracle数据库基于某种方式(如持续读磁盘)模拟系统负载来获取系统统计信息。

通各方资料和oracle官方文档中可以看出,我们最好采用系统负载的方式来收集系统统计信息,收集的时间间隔至少要30分钟,条件允许的情况下,最好多次收集,择优使用。处理使用DBMS_STATS.GATHER_SYSTEM_STATS来收集系统统计信息,我们也可以手工设定某些信息选项,这一点在后面会有示例。

oracle的系统统计信息最终是存储在aux_stats$数据基表中的,首先来看一下该表的结构:

SQL> desc aux_stats$
 名称			       是否为空  类型
 ----------------------------- -------- --------------------
 SNAME			       NOT NULL VARCHAR2(30)
 PNAME			       NOT NULL VARCHAR2(30)
 PVAL1					NUMBER
 PVAL2					VARCHAR2(255)
aux_stats$表中存储的数据量是非常有限的,如
SQL> select * from aux_stats$;

SNAME		     PNAME		       PVAL1 PVAL2
-------------------- -------------------- ---------- ------------------------------
SYSSTATS_INFO	     STATUS			     COMPLETED
SYSSTATS_INFO	     DSTART			     09-17-2011 10:21
SYSSTATS_INFO	     DSTOP			     09-17-2011 10:21
SYSSTATS_INFO	     FLAGS			   1
SYSSTATS_MAIN	     CPUSPEEDNW 	  1751.75879
SYSSTATS_MAIN	     IOSEEKTIM			  10
SYSSTATS_MAIN	     IOTFRSPEED 		4096
SYSSTATS_MAIN	     SREADTIM
SYSSTATS_MAIN	     MREADTIM
SYSSTATS_MAIN	     CPUSPEED
SYSSTATS_MAIN	     MBRC

SNAME		     PNAME		       PVAL1 PVAL2
-------------------- -------------------- ---------- ------------------------------
SYSSTATS_MAIN	     MAXTHR
SYSSTATS_MAIN	     SLAVETHR

已选择13行。
sname字段的取值有:SYSSTATS_INFO,SYSSTATS_MAIN,SYSSTATS_TEMP

SYSSTATS_INFO:系统统计信息的状态

SYSSTATS_MAIN:系统统计信息的内容

SYSSTATS_TEMP:在收集系统统计信息期间,用于临时存放中间数据

对于pname字段的含义,oracle官方文档给出了详细的解释:

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. CPU速率

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. CPU速率

None

Set gathering_mode = NOWORKLOAD, INTERVAL, orSTART|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, orSTART|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 ma