1. 创建一个表空间
create tablespace perfstat datafile '/oracle/oradata/dbaix/perfstat01.dbf' size 200M autoextend off;
2. 执行脚本
SQL> @/oracle/product/10.2.0/db_1/rdbms/admin/spcreate
Choose the PERFSTAT user's password
-----------------------------------
Not specifying a password will result in the installation FAILING
Enter value for perfstat_password:perfstat
perfstat
Choose the Default tablespace for the PERFSTAT user
---------------------------------------------------
Below is the list of online tablespaces in this database which can
store user data. Specifying the SYSTEM tablespace for the user's
default tablespace will result in the installation FAILING, as
using SYSTEM for performance data is not supported.
Choose the PERFSTAT users's default tablespace. This is the tablespace
in which the STATSPACK tables and indexes will be created.
TABLESPACE_NAME CONTENTS STATSPACK DEFAULT TABLESPACE
------------------------------ --------- ----------------------------
APP1 PERMANENT
BKT PERMANENT
EXAMPLE PERMANENT
KKK PERMANENT
PERFSTAT PERMANENT
SUN PERMANENT
SYSAUX PERMANENT *
TEST PERMANENT
USERS PERMANENT
Pressing <return> will result in STATSPACK's recommended default
tablespace (identified by *) being used.
Enter value for default_tablespace:perfstat
……..
……….
Creating Package STATSPACK...
Package created.
No errors.
Creating Package Body STATSPACK...
Package body created.
No errors.
NOTE:
SPCPKG complete. Please check spcpkg.lis for any errors.
执行完毕!
如果发生错误,请执行脚本清除,重新执行:
脚本:/oracle/product/10.2.0/db_1/rdbms/admin/spdrop.sql
3. 捕获实例快照
3.1 手工捕获快照(snap_id)
SQL> conn perfstat/perfstat
Connected.
执行execute statspack.snap手工采集snap
查看采集视图:select * from stats$snapshot
3.2 自动捕获实例快照
使用一个脚本来创建自动收集
脚本:/oracle/product/10.2.0/db_1/rdbms/admin/spauto.sql
variable jobno number;
variable instno number;
begin
select instance_number into :instno from v$instance;
dbms_job.submit(:jobno, 'statspack.snap;', trunc(sysdate+1/24,'HH'), 'trunc(SYSDATE+1/24,''HH'')', TRUE, :instno);
commit;
end;
/
(可修改这个脚本,以改变采集数据的时间间隔,默认是每小时采集一次。)
可修改:
dbms_job.submit(:jobno, 'statspack.snap;', trunc(sysdate+1/24,'HH'), 'trunc(SYSDATE+1/24,''HH'')', TRUE, :instno);
来改写采集数据的间隔。一天24小时,24*60=144分钟,那么:
1/24HH-----------每一小时采集一次
1/48HH-----------------每30分钟采集一次
1/144MI---------------每10分钟采集一次
1/288MI---------------每5分钟采集一次
注:1/*,那个1表示一天时间
修改之后,执行脚本,生效:
使用下面介绍的两个视图查看即可:
执行这段脚本
该段脚本是一个小时执行一次snap
移除定时jobs:
Execute dbms_job.remove(‘job’);
3.3 report
生成报表的控制文件脚本:
/oracle/product/10.2.0/db_1/rdbms/admin/sprepcon.sql
生成报表之前采集snap
execute statspack.snap生成snap_id,执行一次,生一个snap_id。
生成报表的脚本:
/oracle/product/10.2.0/db_1/rdbms/admin/spreport.sql
采集数据成功!
两个必看视图:
select * from user_jobs 查看定时任务执行情况
select * from stats$snapshot 查看生成snap_id数量
3.4
脚本:/oracle/product/10.2.0/db_1/rdbms/admin/sprepins.sql
这个脚本是在多实例时候使用
3.5 采集SQL数据
/oracle/product/10.2.0/db_1/rdbms/admin/sprepsql.sql
通过该脚本,找出问题SQL,进行优化.
SQL 'Thresholds'
The SQL statements gathered by Statspack are those which exceed one of
six predefined threshold parameters:
- 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)
- size of sharable memory used by the SQL statement (default 1m)
- version count for the SQL statement (default 20)
超过以上默认的阀值,该SQL将被记录.
4. 配置,一些参数的配置
database parameters
------------------------------------ ----------- ------------------------------
statistics_level string TYPICAL
timed_statistics boolean TRUE
snapshot parameters
使用$ORACLE_HOME/rdbms/admin/spdoc.txt该文件,来修改相应参数.
默认的等级收集为level 5
视图显示默认的参数:
stats$statspack_parameter
execute statspack.snap(i_snap_level=>7);------不保存
execute statspack.snap(i_snap_level=>7,i_modify_parameter=>'true');保存
instance report parameters
/oracle/product/10.2.0/db_1/rdbms/admin/sprepcon.sql
sql report parameters
/oracle/product/10.2.0/db_1/rdbms/admin/sprepcon.sql
5. 创建baseline
使用$ORACLE_HOME/rdbms/admin/spdoc.txt,来查看如何创建baseline
保存相关的snap_id,消除相关的snap_id。
参考该文件来操作.