60、StatsPack 使用初解

来源:互联网 发布:淘宝深夜食堂视频全集 编辑:程序博客网 时间:2024/05/01 08:21
 

3 StatsPack的管理和调整
Oracle还提供了系统脚本用于Truncate这些统计信息表,这个脚本名字是: sptrunc.sql (8i、9i都相同)
execute statspack.modify_statspack_parameter -
(i_snap_level => 10, -
i_buffer_gets_th => 10000, -
i_disk_reads_th => 1000);

sppurge.sql - Purge a range of Snapshot Id’s between the specified begin and end Snap Id’s
sptrunc.sql - Truncates all data in Statspack tables

删除其他用户的job,不一定非要这个用户登陆,可以使用dbms_ijob包。

配置StatsPack参数

- 快照级别

StatsPack可以通过设置level级别来改变收集统计信息的多少。 以下是各个级别收集信息的内容:

Levels = 0 一般性能统计
统计内容:
这个级别及更高会收集一般的性能统计,例如:等待,系统事件,系统统计,回滚段数据,SGA,后台事件,会话事件,锁,buffer pool 统计,parent latch统计。

Levels = 5 增加:SQL 语句
包含了所有低级别的统计信息,还增加了使用资源较高的SQL 语句信息。

SQL ‘Thresholds’
The SQL 语句按照以下预定义的阀值进行统计:
- number of executions of the SQL statement (default 100)
- number of disk reads performed by the SQL statement (default 1,000)
- number of parse calls performed by the SQL statement (default 1,000)
- number of buffer gets performed by the SQL statement (default 10,000)

当 SQL 语句使用的资源超过了以上任何一个阀值,就会被统计到快照中。
SQL语句阀值使用 stats$statspack_parameter 表中的记录或者执行快照时输入的参数。

Levels = 6
比上一级别增加了,Top SQL 的执行计划及使用率的信息。适用于执行计划变化的场合。如果要收集shared pool 中所有的SQL语句,需要把上面的阀值设置为0。

Level = 7
Levels >= 7 增加: Segment 级别统计
有了segment的统计信息,可以知道哪些segment使用频率高,调整segment的物理布局,优化I/O负载。对于RAC环境,可以发现实例争用的热点对象。
Level 7 包含以下 segment 统计:

Logical reads
Db block changes
Physical reads
Physical writes
Physical reads direct
Physical writes direct
Global cache consistent read blocks served (RAC specific)
Global cache current blocks served (RAC specific)
Buffer busy waits
ITL waits
Row lock waits

Levels = 10 增加:Child latches
这个级别收集的信息最全,也最耗时,除非需要child latch的信息,一般不建议使用。

- Snapshot SQL thresholds

There are other parameters which can be configured in addition to the level.
These parameters are used as thresholds when collecting SQL statements;
if any SQL statements breach the threshold, these are the statements which
are captured during the snapshot.

Snapshot level and threshold information used by the package is stored
in the stats$statspack_parameter table.

- Changing the default values for Snapshot Level and SQL Thresholds

The default parameters used for taking snapshots can be adjusted/modified so
that they better capture data about an instance’s workload.

This can be done either by:

o Taking a snapshot, and specifying the new defaults to be saved to the
database (using statspack.snap, and using the i_modify_parameter
input variable).

SQL> execute statspack.snap -
(i_snap_level=>10, i_modify_parameter=>’true’);

Setting the i_modify_parameter value to true will save the new
thresholds in the stats$statspack_parameter table; these thresholds
will be used for all subsequent snapshots.

If the i_modify_parameter was false or omitted, the snapshot taken at
that point will use the specified values, any subsequent snapshots
use the preexisting values in the stats$statspack_parameter table.

o Changing the defaults immediately without taking a snapshot, using the
statspack.modify_statspack_parameter procedure. For example to change
the snapshot level to 10, and the SQL thresholds for buffer_gets and
disk_reads, the following statement can be issued:

SQL> execute statspack.modify_statspack_parameter -
(i_snap_level=>10, i_buffer_gets_th=>10000, i_disk_reads_th=>1000);

This procedure changes the values permananently, but does not
take a snapshot.

The full list of parameters which can be passed into the
modify_statspack_parameter procedure are the same as those for
the snap procedure.

- Specifying a Session Id

If session statistics are needed for a particular session, it is possible to
specify the session id in the call to StatsPack. The statistics gathered for
the session will include session statistics, session events and lock activity.
The default behavior is to not to gather session level statistics.

SQL> execute statspack.snap(i_session_id=>3);

How to automatically gather StatsPack snapshots:
————————————————

To be able to make comparisons of performance from one day, week or year to
the next, there must be multiple snapshots taken over a period of time. A
minimum of two snapshots are required before any performance characteristics of
the application and database can be made.

The best method to gather snapshots is to automate the collection on a
regular time interval. It is possible to do this:

- Within the database, using the Oracle dbms_job procedure to schedule the
snapshots

- Using Operating System utilities (such as ‘cron’ on Unix or ‘at’ on NT) to
schedule the snapshot. Please contact the System Administrator for more
information about using the OS utilities for automating this data collection.

- Scheduling StatsPack snapshots using DBMS_JOB package

To use an Oracle-automated method for collecting statistics, you can use
dbms_job. A sample script on how to do this is supplied in spauto.sql,
which schedules a snapshot every hour, on the hour.

In order to use dbms_job to schedule snapshots, the job_queue_processes
initialization parameter must be set to greater than 0 in the configuration
file used to start the instance for the job to be run automatically.

Example of an init.ora entry:
# Set to enable the job queue process to start. This allows dbms_job
# to schedule automatic statistics collection using STATSPACK
job_queue_processes=1

If using statsauto.sql in OPS environment, the statsauto.sql script must be
run once on each instance in the cluster. Similarly, the job_queue_processes
parameter must also be set for each instance.

Changing the interval of statistics collection
———————————————–
To change the interval of statistics collection use the dbms_job.interval
procedure

e.g.
execute dbms_job.interval(,’SYSDATE+(1/48)’);

Where ‘SYSDATE+(1/48)’ will result in the statistics being gathered each 1/48
hours (i.e. every half hour).

To force the job to run immediately,
execute dbms_job.run();

To remove the autocollect job,
execute dbms_job.remove();

For more information on dbms_job, see the Supplied Packages Reference Manual.

To gather a STATSPACK report :
==============================

SQL> connect perfstat/perfstat
SQL> @?/rdbms/admin/spreport

You will be prompted for:
1. The beginning snapshot Id
2. The ending snapshot Id
3. The name of the report text file to be created

 
原创粉丝点击