You are on page 1of 7

StatsPack Package

Description
On earlier version of Oracle, previous to Oracle 8i, one very useful way to analyze
performance of an instance was to use utlbestat and utlestat. From Oracle 8i and upper
versions, Oracle enables another way to generate reports with a profile of the database
during a specific period of time and it is called StatsPack. This document is specially
described for Oracle 8.1.6 version and upper.
Statspack fundamentally differs from the well known UTLBSTAT/UTLESTAT tuning
scripts by collecting more information, and also by storing the performance statistics data
permanently in Oracle tables, which can later be used for reporting and analysis. The
data collected can be analyzed using the report provided, which includes an "instance
health and load" summary page, high resource SQL statements, as well as the traditional
wait events and initialization parameters.

Installation
The StatsPack package shouldn’t be installed on the SYSTEM tablespace. Use a separate
tablespace for it using the default initial and next extent size of 1 Mbytes. The minimum
default space requirement is approximately 60 Mbytes, however the amount of space
required is difficult to estimate because it is based on the amount of data collected, the
size of the database and also the instance. You should create the temporary and
permanent tablespace to install the StatsPack before because if you install it on
interactive mode, you will be prompted to input those tablespaces (the tablespaces that
will be used by PERFSTAT user).
The installation of StatsPack can only be done with SQL*Plus because of special
commands used on the scripts. To install StatsPack, a script should be run:
Oracle 8.1.6

Connect / as sysdba
Unix

@?/rdbms/admin/statscre

Connect / as sysdba
NT

@%ORACLE_HOME%\rdbms\admin\statscre
Unix
Oracle 8.1.7 and 9i

Connect / as sysdba

@?/rdbms/admin/spcreate

Connect / as sysdba
NT

@%ORACLE_HOME%\rdbms\admin\spcreate
The StatsPack package script installation runs other 3 scripts and their log is spooled
during the installation with the extension .lis. The status of each of this scripts should be
checked:

Oracle 8i – 8.1.6 Oracle 8i 8.1.7 and 9i


Statscusr Spcusr
Statsctab Spctab
Statspack Spcpkg

If there is a problem during the installation, you can remove the StatsPack and try to
reinstall. In order to do so, run the script:
Oracle 8.1.6

Connect / as sysdba
Unix

@?/rdbms/admin/statsdrp

Connect / as sysdba
NT

@%ORACLE_HOME%\rdbms\admin\statsdrp
Oracle 8.1.7 and 9i

Unix

Connect / as sysdba

@?/rdbms/admin/spdrop

Connect / as sysdba
NT

@%ORACLE_HOME%\rdbms\admin\spdrop

You can also install StatsPack in batch mode by defining the tablespaces (permanent and
temporary) that will be used for PERFSTAT user. For example:
Connect / as sysdba
Define default_tablespace = ‘tools’
Define temporary_tablespace = ‘temp’

How do use StatsPack


1.1 Taking a snapshot
In order to generate a report, a snapshot must be taken throught the StatsPack package.
The simplest way to take a snapshot is connecting as PERFSTAT user on SQL*Plus and
executes the statspack.snap routine:
SQL> connect perfstat/perfstat
SQL> execute statspack.snap;
This will save performance statistics on StatsPack tables and those statistics will be
further compared to future snapshots. The parameter timed_statistics must be set to true.

Parameters Valid values Default Description


value
i_snap_level From 0 - 4 5 General performance statistics
From 5 - 9 Additional data: SQL
statements (high resource
usage SQL statements); the
SQL statements that will be
captured are the ones that
exceed the thresholds. These
thresholds are saved in the
stats$statspack_parameter
table and can be changed.
>= 10 High child latch information
i_ucomment Text Blank
i_executions_th Integer >= 0 100
i_disk_reads_th Integer >= 0 1,000
i_parse_calls_th Integer >= 0 1,000
i_buffer_gets_th Integer >= 0 10,000
i_session_id Valid sid from 0 (no Session id of the session from
v$session session) which statistics will be
specially taken
i_modify_parameter True, False false

For changing the threshold values, two actions can be taken. The first one is through the
statspack.snap procedure, like below:

execute statspack.snap (i_snap_level=>10, i_modify_parameter=>'true');

The i_snap_level was changed but just for this snapshot taken. The next snapshot that
will be taken will have the default values.
The other action for changing the threshold values is through the
statspack.modify_statspack_parameter routine, like below:

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

1.2 Automatic snapshotting


Oracle provides a package for scheduling procedures called DBMS_JOB. In order to
schedule snapshots, the parameters job_queue_processes must be set to a value higher
than 0.
There is a sample script for scheduling with DBMS_JOB called spauto.sql. It is shown
below:

spool spauto.lis
-- Schedule a snapshot to be run on this instance every
-- hour, on the hour

variable jobno number;


variable instno number;
begin
select instance_number into :instno from v$instance;
DBMS_JOB.submit(:jobno,
'statspack.snap;',
sysdate+1/24/3,
'SYSDATE+1/24/3', TRUE,
:instno);
commit;
end;
/

prompt
prompt Job number for automated statistics collection for
prompt this instance
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt Note that this job number is needed when modifying
prompt or removing prompt the job:
print jobno

prompt
prompt Job queue process
prompt ~~~~~~~~~~~~~~~~~
prompt Below is the current setting of the
prompt job_queue_processes init.ora prompt parameter
prompt - the value for this parameter must be greater
prompt than 0 to use automatic statistics gathering:
show parameter job_queue_processes
prompt

prompt
prompt Next scheduled run
prompt ~~~~~~~~~~~~~~~~~~
prompt The next scheduled run for this job is:
select job, next_date, next_sec
from user_jobs
where job = :jobno;

spool off;

Using this script on an OPS environment, it should be run on both instances.


The definition of DBMS_JOB.submit procedure is:
DBMS_JOB.SUBMIT (
job OUT BINARY_INTEGER,
what IN VARCHAR2,
next_date IN DATE DEFAULT sysdate,
interval IN VARCHAR2 DEFAULT 'null',
no_parse IN BOOLEAN DEFAULT FALSE,
instance IN BINARY_INTEGER DEFAULT any_instance,
force IN BOOLEAN DEFAULT FALSE);
In order to change the interval of snapshot, use the command below:
execute DBMS_JOB.interval(1,'SYSDATE+(1/48)');
Outros valores para a coluna interval são:
Interval Description
'sysdate + 7' Run once a week.
'next_day(sysdate,''TUESDAY'')' Run once every Tuesday
'null' Run only once

The definition of DBMS_JOB.interval is:


DBMS_JOB.INTERVAL (
job IN BINARY_INTEGER,
interval IN VARCHAR2);

Other important procedures from DBMS_JOB are:

DBMS_JOB.REMOVE (
job IN BINARY_INTEGER );

to remove an existing job from the job queue, and


DBMS_JOB.RUN (
job IN BINARY_INTEGER,
force IN BOOLEAN DEFAULT FALSE);
to run a specific job.

1.3 Generating reports


As with utlbstat/utlestat, it is not valid to take one snapshot before and one after a
shutdown/startup command and use both to gather a report.
The script spreport.sql is the one used to get a report. You should be connected as
PERSTAT user in order to run this script. It will prompt you for:
- the first snapshot id
- the last snapshot id
- the name of the report that will be generated
Oracle 8.1.6

Connect / as sysdba
Unix

@?/rdbms/admin/statsrep

Connect / as sysdba
NT

@%ORACLE_HOME%\rdbms\admin\statsrep
Unix
Oracle 8.1.7 and 9i
Connect / as sysdba
@?/rdbms/admin/spreport

Connect / as sysdba

NT @%ORACLE_HOME%\rdbms\admin\spreport

1.4 Maintenance
In order to remove snapshots from the schema, there is a script called sppurge, available
in Oracle version 8.1.7 and upper that is located on $ORACLE_HOME/rdbms/admin.

1.5 Views
Perfstat user has the following tables that can be queried in order to get information about
snapshots:
STATS$BG_EVENT_SUMMARY
STATS$BUFFER_POOL_STATISTICS
STATS$DATABASE_INSTANCE
STATS$ENQUEUESTAT
STATS$FILESTATXS
STATS$IDLE_EVENT
STATS$LATCH
STATS$LATCH_CHILDREN
STATS$LATCH_MISSES_SUMMARY
STATS$LATCH_PARENT
STATS$LEVEL_DESCRIPTION
STATS$LIBRARYCACHE
STATS$PARAMETER
STATS$ROLLSTAT
STATS$ROWCACHE_SUMMARY
STATS$SESSION_EVENT
STATS$SESSTAT
STATS$SGA
STATS$SGASTAT
STATS$SNAPSHOT
STATS$SQLTEXT
STATS$SQL_STATISTICS
STATS$SQL_SUMMARY
STATS$STATSPACK_PARAMETER
STATS$SYSSTAT
STATS$SYSTEM_EVENT
STATS$TEMPSTATXS
STATS$WAITSTAT

You might also like