1. Anar Godajev
http://anargodjaev.wordpress.com/
Statspack Reports
/*
When installing the Statspack package, you can either change to
theORACLE_HOME/rdbms/admin directory, or fully specify
theORACLE_HOME/rdbms/admin DIRECTORY WHEN calling the installation script,
SPCREATE.SQL.
*/
-- install statspack
@?/rdbms/ADMIN/spcreate
/*
Enter appropriate information when prompted for the PERFSTAT user's
password, default tablespace, and temporary tablespace.
The SPCREATE.SQL install script runs the following scripts automatically:
*/
/*
SPCUSR.SQL: Creates the user and grants privileges
SPCTAB.SQL: Creates the tables
SPCPKG.SQL: Creates the package
*/
-- To install without prompting
SQL> CONNECT / AS SYSDBA
SQL> define default_tablespace='TOOLS'
SQL> define temporary_tablespace='TEMP'
SQL> define perfstat_password='my_perfstat_password'
SQL>@?/rdbms/ADMIN/spcreate
/*
-- automatic collection of statistics
oracle_home/rdbms/admin/spauto.sql
*/
-- executing statspack
SQL> CONNECT perfstat/my_perfstat_password
SQL> EXECUTE statspack.snap;
-- For better performance analysis, set the initialization parameter
TIMED_STATISTICS to TRUE.
-- Statspack will then include important timing information in the data it
collects.
-- create statspack report
SQL> CONNECT perfstat/my_perfstat_password
SQL>@?/rdbms/ADMIN/spreport
-- statspack in a pl/sql block
DECLARE
variablesnap NUMBER;
BEGIN
snap:= statspack.snap;
dbms_output.put_line(snap);
END;
2. Anar Godajev
http://anargodjaev.wordpress.com/
-- automaticstatspac
-- A sample script on how to do this is supplied in SPAUTO.SQL
-- create statspack report without prompt
SQL> CONNECT perfstat/my_perfstat_password
SQL> define begin_snap=1
SQL> define end_snap=2
SQL> define report_name=batch_run
SQL>@?/rdbms/ADMIN/spreport
/*
When you examine the instance report, you often find high-load SQL
statements that you want to examine more closely. The SQL report,
SPREPSQL.SQL, displays statistics, the complete SQL text, and (if a level
six snapshot has been taken), information on any SQL plan(s) associated
with that statement.
*/
SQL> CONNECT perfstat/my_perfstat_password
Connected.
SQL>@?/rdbms/ADMIN/sprepsql
-- truncate all statspack data
SQL> CONNECT perfstat/my_perfstat_password
SQL>@?/rdbms/ADMIN/sptrunc
-- remove statspack
SQL> CONNECT / AS SYSDBA
SQL>@?/rdbms/ADMIN/spdrop
/*
SPDTAB.SQL - drops tables and public synonyms
SPDUSR.SQL - drops the user
*/
-- Purge unnecessary data by using the SPPURGE.SQL script
SQL> CONNECT perfstat/my_perfstat_password
SQL> SET TRANSACTION USE ROLLBACK SEGMENT rbig;
SQL>@?/rdbms/admin/spurge
SQL> CONNECT perfstat/my_perfstat_password
SQL> DEFINE losnapid=1
SQL> DEFINE hisnapid=2
SQL>@?/rdbms/admin/spurge
-- snap parameters
EXECUTE STATSPACK.SNAP(i_ucomment=>'this is a temporary commment');
EXECUTE STATSPACK.MODIFY_STATSPACK_PARAMETER(i_ucomment=>'this is a
commment that is saved');
EXECUTE STATSPACK.SNAP(i_snap_level=>10, i_modify_parameter=>'true');
EXECUTE STATSPACK.SNAP(i_snap_level=>6);
Levels
Levels
Levels
Levels
>=
>=
>=
>=
0
5
6
7
General Performance STATISTICS
Additional Data: SQL Statements
Additional Data: SQL Plans AND SQL PLAN Usage
Additional data: SEGMENT LEVEL STATISTICS