Statspack 安装和使用

环境:Centos 6.2 + Oracle 11.2.0.3 
1.Statspack的安装
安装Statspack的过程就是创建一个用户perfstat,并且在这个用户下创建相应的对象,Oracle提供了现有的脚本来创建这些对象,我们只需要用SYSDBA用户来运行这个脚本就OK了,Statspack的创建脚本spcreate.sql位于$ORACLE_HOME/rdbms/admin的目录下。
下面是创建Statspack的过程:
 
SQL> @/u/oracle/product/11.2/rdbms/admin/spcreate.sql
Choose the PERFSTAT user's password
-----------------------------------
Not specifying a password will result in the installation FAILING
 
输入 perfstat_password 的值:  perfcreate
perfcreate
使用sys用户连接数据库,并运行spcreate.sql脚本,首先要先输入新建用户perfstat的密码,我们输入的密码是perfcreate。
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
------------------------------ --------- ----------------------------
CW                             PERMANENT
CW_MD                          PERMANENT
CW_PART                        PERMANENT
DBAPI                          PERMANENT
PETDOG                         PERMANENT
SEVEN                          PERMANENT
STRMADMIN                      PERMANENT
SYSAUX                         PERMANENT *
USERS                          PERMANENT
 
Pressing <return> will result in STATSPACK's recommended default
tablespace (identified by *) being used.
 
输入 default_tablespace 的值:  users
接下来Oracle列出了数据库中可以使用的表空间,要求我们为用户perfstat指定默认表空间,也就是之后储存Statspack信息的表空间,这里我们选择users表空间。
Using tablespace USERS as PERFSTAT default tablespace.
 

Choose the Temporary tablespace for the PERFSTAT user
-----------------------------------------------------
Below is the list of online tablespaces in this database which can
store temporary data (e.g. for sort workareas).  Specifying the SYSTEM
tablespace for the user's temporary tablespace will result in the
installation FAILING, as using SYSTEM for workareas is not supported.
 
Choose the PERFSTAT user's Temporary tablespace.
 
TABLESPACE_NAME                CONTENTS  DB DEFAULT TEMP TABLESPACE
------------------------------ --------- --------------------------
TEMP                           TEMPORARY *
 
Pressing <return> will result in the database's default Temporary
tablespace (identified by *) being used.
 
输入 temporary_tablespace 的值:  temp
接着,输入默认临时表空间,毫无疑问,我们选择temp表空间。
下面就是创建perfstat用户对象的操作:
If this script is automatically called from spcreate (which is
the supported method), all STATSPACK segments will be created in
the PERFSTAT user's default tablespace.
 
Using users tablespace to store Statspack objects
 
... Creating STATS$SNAPSHOT_ID Sequence
 
序列已创建。
同义词已创建。
... Creating STATS$... tables
表已创建。
同义词已创建。
表已创建。
已创建 1 行。
已创建 1 行。
 
......
 
同义词已创建。
同义词已创建。
NOTE:
SPCTAB complete. Please check spctab.lis for any errors.
 
......
 
Creating Package STATSPACK...
程序包已创建。
没有错误。
Creating Package Body STATSPACK...
程序包体已创建。
没有错误。
NOTE:
SPCPKG complete. Please check spcpkg.lis for any errors.
 
至此,Statspack安装完成,下面接着使用Statspack做性能采集和性能分析。
2.Statspack性能采集
    使用Statspack的性能采集是通过快照的方式实现的,即Statspack在某一个时间点对系统的性能数据做一个快照,并将快照保存在perfstat用户的表中,在另一个时间点再做一个系统的性能数据快照,也保存在perfstat用户的表中,这样通过对比这两个时间的性能数据变化,来分析系统性能的状况。
    Statspack的性能采集需要使用新创建的用户perfstat连接到数据库,并在不同时间点创建快照来完成,时间点是可控的,间隔可以是15分钟也可以是半小时。
 
SQL> conn perfstat/perfcreate
已连接。
SQL> exec statspack.snap
 
PL/SQL 过程已成功完成。
 
SQL> exec statspack.snap
 
PL/SQL 过程已成功完成。
然后分别在这两个时间点运行exec statspack.snap来获取系统性能数据的快照,这样就完成了一次Statspack的性能采集工作。
下面使用这两个快照来生成Statspack的性能报告:
SQL> @/u/oracle/product/11.2/rdbms/admin/spreport.sql
SQL> Rem
SQL> Rem $Header: spreport.sql 22-apr-2001.15:44:01 cdialeri Exp $
SQL> Rem
SQL> Rem spreport.sql
SQL> Rem
SQL> Rem  Copyright (c) Oracle Corporation 1999, 2000. All Rights Reserved.
SQL> Rem
SQL> Rem    NAME
SQL> Rem         spreport.sql
SQL> Rem
SQL> Rem    DESCRIPTION
SQL> Rem         This script defaults the dbid and instance number to that of the
SQL> Rem         current instance connected-to, then calls sprepins.sql to produce
SQL> Rem         the standard Statspack report.
SQL> Rem
SQL> Rem    NOTES
SQL> Rem         Usually run as the STATSPACK owner, PERFSTAT
SQL> Rem
SQL> Rem    MODIFIED   (MM/DD/YY)
SQL> Rem    cdialeri    03/20/01 - 1747076
SQL> Rem    cdialeri    03/12/01 - Created
SQL>
SQL> --
SQL> -- Get the current database/instance information - this will be used
SQL> -- later in the report along with bid, eid to lookup snapshots
SQL>
SQL> column inst_num  heading "Inst Num"  new_value inst_num  format 99999;
SQL> column inst_name heading "Instance"  new_value inst_name format a12;
SQL> column db_name      heading "DB Name"   new_value db_name   format a12;
SQL> column dbid         heading "DB Id"          new_value dbid      format 9999999999 just c;
SQL>
SQL> prompt
 
.......
 
Listing all Completed Snapshots
 
                                                       Snap
Instance     DB Name        Snap Id   Snap Started    Level Comment
------------ ------------ --------- ----------------- ----- --------------------
petdog       PETDOG               1 19 4月  2013 11:1     5
                                    7
                                  2 19 4月  2013 11:1     5
                                    7
 
Specify the Begin and End Snapshot Ids
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
输入 begin_snap 的值:  1
Begin Snapshot Id specified: 1
提示输入要生成性能报告的起始快照号,这里输入:1
输入 end_snap 的值:  2
End   Snapshot Id specified: 2
输入生成报告的结束快照号:2
Specify the Report Name
~~~~~~~~~~~~~~~~~~~~~~~
The default report file name is sp_1_2.  To use this name,
press <return> to continue, otherwise enter an alternative.
 
输入 report_name 的值:  sp_1_2.txt
 
Using the report name sp_1_2.txt
提示输入生成的性能报告的名称,如果不指定路径,Oracle将在当前目录下生成性能报告文件。
接着下面就全部是Oracle输出的性能报告。
STATSPACK report for
 
Database    DB Id    Instance     Inst Num  Startup Time   Release     RAC
~~~~~~~~ ----------- ------------ -------- --------------- ----------- ---
          2085451793 petdog              1 11-4月 -13 15:4 11.2.0.3.0  NO
                                           1
 
Host                             Name             Platform                CPUs
Cores Sockets   Memory (G)
~~~~ ---------------- ---------------------- ----- ----- ------- ------------
     dac-vm02         Linux x86 64-bit           4     4       2          3.9
 
Snapshot       Snap Id     Snap Time      Sessions Curs/Sess Comment
~~~~~~~~    ---------- ------------------ -------- --------- ------------------
Begin Snap:          1 19-4月 -13 11:17:26      33       1.5
  End Snap:          2 19-4月 -13 11:17:53      35       1.4
   Elapsed:       0.45 (mins) Av Act Sess:       0.1
   DB time:       0.03 (mins)      DB CPU:       0.03 (mins)
 
.......
参考来源:《让Oracle跑的更快.Oracle.10g 性能分析与优化思路》-------谭怀远






--------------------------------------------------------------------------------------------

版权所有,转载请注明作者及原文链接,否则追究法律责任!

QQ:      584307876

作者:    Seven

原文链接:  http://blog.csdn.net/sunjiapeng/article/details/8823154

邮箱:    seven_ginna@foxmail.com

posted @ 2013-04-19 11:28  Seven_sun  阅读(177)  评论(0编辑  收藏  举报