This article is about Oracle Statspack. We are going to learn How We can Install and what is Oracle Statspack?

Statspack is a performance tuning tool provided by Oracle with the Oracle9i database distribution. With minimal effort, it can be installed on any Oracle9i database to rapidly gather detailed analysis of the performance of that database instance.

So What is Oracle Statspack?

The Statspack package is a set of SQL, PL/SQL, and SQL*Plus scripts that allow the collection, automation, storage, and viewing of performance data. Statspack stores the performance statistics perennially in Oracle tables, which can later be used for reporting and analysis. The data collected can be analyzed using Statspack reports, which includes an instance health and load summary page, high resource SQL statements, and the traditional wait events and initialization parameters.

How does Oracle Statspack work?

When we run the Statspack installation script, the PERFSTAT user is created automatically. PERFSTAT have all objects needed by the Statspack package and is granted limited query-only privileges on the V$ views mandatory for performance tuning.Statspack users become accustomed to the concept of a snapshot, a single collection of performance data. Each snapshot taken is recognized by a snapshot ID, which is a unique number generated at the time the snapshot is taken. Each time a new collection is taken, a new SNAP_ID is generated. The SNAP_ID, along with the database identifier (DBID) and instance number (INSTANCE_NUMBER), comprise the unique key for a snapshot. Use of this unique merger allows storage of multiple instances of an Oracle Real Application Clusters database in the same tables.

After snapshots are taken, We can run the performance report. The report bring us data about out database for specific time period.

How We can install Oracle Statspack ?

Here is the steps:

  1.  Create a unique tablespace for Statspack. So get datafile path first

SQL> select tablespace_name, substr(file_name,1,70) from dba_data_files;

than create tablespace :

SQL> create tablespace PERFSTAT datafile ‘/u01/app/oracle/oradata/TEST/PERFSTAT_01.dbf’ size 500M autoextend on next 50M maxsize 30G;

2. Connect as sysdba and run spcreate.sql

SQL>@?/rdbms/admin/spcreate.sql

This scripts will ask some information such as

SQL> @spcreate.sql

Choose the PERFSTAT user’s password

Not specifying a password will result in the installation FAILING

Enter value for perfstat_password: Welcome1
Welcome1

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

PERFSTAT PERMANENT
SYSAUX PERMANENT *
USERS PERMANENT

Pressing will result in STATSPACK’s recommended default
tablespace (identified by *) being used.

Enter value for default_tablespace: PERFSTAT

Using tablespace PERFSTAT 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 will result in the database’s default Temporary
tablespace (identified by *) being used.

Enter value for temporary_tablespace: TEMP

Using tablespace TEMP as PERFSTAT temporary tablespace.

… Creating PERFSTAT user

… Installing required packages

… Creating views

… Granting privileges

NOTE:
SPCUSR complete. Please check spcusr.lis for any errors.

SQL>
SQL> —
SQL> — Build the tables and synonyms
SQL> connect perfstat/&&perfstat_password
Connected.
SQL> @@spctab
.

.

SQL> set echo off;
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.

Make sure there were no errors in the process by accessing the spcpkg.lis, spctab.lis and spcusr.lis files.

3. Its good way to take statistic for PERFSTAT schema:

SQL> exec dbms_stats.gather_schema_stats(‘PERFSTAT’);

PL/SQL procedure successfully completed.

4. Connect as PERFSTAT user to database:

[oracle@veridata admin]$ sqlplus perfstat/Welcome1

5. Run below commands

SQL> exec statspack.snap;

PL/SQL procedure successfully completed.

SQL> @spauto.sql

PL/SQL procedure successfully completed.

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

JOBNO
     3

Job queue process

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

NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
job_queue_processes                  integer     1000


Next scheduled run

~
The next scheduled run for this job is:

   JOB NEXT_DATE NEXT_SEC
     3 16-SEP-20 12:00:00

6. Now We are going to take second snapshot for can generate report.

SQL> exec statspack.snap;

PL/SQL procedure successfully completed.

7. We can list our snaps by using below syntax

SQL> select name, snap_id, to_char(snap_time, ‘DD/MM/YYYY HH24:MI:SS’) “Snapshot Time” from stats$snapshot,v$database;

NAME SNAP_ID Snapshot Time

TEST 1 16/09/2020 11:10:45
TEST 2 16/09/2020 11:13:00

8. Now We can generate report by using below syntax:

SQL> @?/rdbms/admin/spreport.sql