ArticlesBase.com - Free Articles Directory
Free Online Articles Directory
10.10.2008 Sign In Register Hello Guest
Email:
Password:
Remember Me 
forgot your password?


Getting Most Out of Oracle 8i/9i Statspack

Author: Sagar Patil Author Ranking Blue | Posted: 06-05-2008 | Comments: 0 | Views: 70 | Rating:  (66) Article Popularity - Blue (?) Got a Question? Ask.
Sign Up Now!

Statspack is a set of performance monitoring and reporting utilities provided by Oracle for Oracle8i and above. A user is automatically created by the installation script - this user, PERFSTAT, owns all objects needed by this package. For more information about Statspack, read the documentation in file $ORACLE_HOME/rdbms/admin/spdoc.txt.

Install Statspack
To install the package, either change to the ORACLE_HOME rdbms/admin directory, or fully specify the ORACLE_HOME/rdbms/admin directory when calling the installation script, SPCREATE.

To run the installation script, you must use SQL*Plus and connect as a user with SYSDBA privilege. For example, start SQL*Plus, then:

On UNIX : SunOS/HP UX/Linux

SQL> CONNECT / AS SYSDBA
SQL> @?/rdbms/admin/spcreate

On Windows: XP/NT/2000/2003

SQL> CONNECT / AS SYSDBA
SQL> @%ORACLE_HOME%rdbmsadminspcreate

The SPCREATE install script runs three other scripts. These scripts are called automatically, so you do not need to run them:

* SPCUSR: Creates the user and grants privileges
* SPCTAB: Creates the tables
* SPCPKG: Creates the package

Configuring Statspack

How to locate the current Ststapack level?
- Look at table PERFSTST.STATS$SNAPSHOT
or
- Run spreport.sql and you will notice it alongwith the snapids listed

STATS$SNAPSHOT will show level for each Snapshot recorded

Change Level
execute statspack.snap (i_snap_level=> 7, i_modify_parameter=>'true');

Levels >= 0 General Performance Statistics
Levels >= 5 Additional Data: SQL Statements
Levels >= 6 Additional Data: SQL Plans and SQL Plan Usage
Levels >= 10 Additional Statistics: Parent and Child Latches

Using Statspack (gathering data)

sqlplus perfstat
--
-- Take a performance snapshot
--
execute statspack.snap;
--
-- Get a list of snapshots
--
column snap_time format a21
select snap_id,to_char(snap_time,'MON dd, yyyy hh24:mm:ss') snap_time
from sp$snapshot;
--

Running a Performance report
--
-- Run the Statspack report:
--
@?/rdbms/admin/spreport.sql

Locate Hard hitting SQL from Statpack Reposistory
1. Login as PERFSTAT user on database.
It won't work unless U login as PERFSTAT user.

2. Find DBID using
"select dbid from stats$sql_summary"

3. Locate MIN(SNAP_ID) pBgnSnap & MAX(SNAP_ID) pEndSnap from

select min(snap_id),max(snap_id),min(snap_time),max(snap_time) from stats$snapshot
where to_number(to_char(snap_time,'HH24')) > 10 and to_number(to_char(snap_time,'HH24')) < 13 and trunc(snap_time)=trunc(sysdate)

Show All SQL Stmts ordered by Logical Reads

select
e.hash_value "E.HASH_VALUE"
, e.module "Module"
, e.buffer_gets - nvl(b.buffer_gets,0) "Buffer Gets"
, e.executions - nvl(b.executions,0) "Executions"
, Round( decode ((e.executions - nvl(b.executions, 0)), 0, to_number(NULL)
, (e.buffer_gets - nvl(b.buffer_gets,0)) /
(e.executions - nvl(b.executions,0))) ,3) "Gets / Execution"
, Round(100*(e.buffer_gets - nvl(b.buffer_gets,0))/sp920.getGets(:pDbID,:pInstNum,:pBgnSnap,:pEndSnap,'NO'),3) "Percent of Total"
, Round((e.cpu_time - nvl(b.cpu_time,0))/1000000,3) "CPU (s)"
, Round((e.elapsed_time - nvl(b.elapsed_time,0))/1000000,3) "Elapsed (s)"
, Round(e.fetches - nvl(b.fetches,0)) "Fetches"
, sp920.getSQLText ( e.hash_value , 400) "SQL Statement"
from stats$sql_summary e
, stats$sql_summary b
where b.snap_id(+) = :pBgnSnap
and b.dbid(+) = e.dbid
and b.instance_number(+) = e.instance_number
and b.hash_value(+) = e.hash_value
and b.address(+) = e.address
and b.text_subset(+) = e.text_subset
and e.snap_id = :pEndSnap
and e.dbid = :pDbId
and e.instance_number = :pInstNum
order by 3 desc

Show SQL Stmts where SQL_TEXT like '%'
select
e.hash_value "E.HASH_VALUE"
, e.module "Module"
, e.buffer_gets - nvl(b.buffer_gets,0) "Buffer Gets"
, e.executions - nvl(b.executions,0) "Executions"
, Round( decode ((e.executions - nvl(b.executions, 0)), 0, to_number(NULL)
, (e.buffer_gets - nvl(b.buffer_gets,0)) /
(e.executions - nvl(b.executions,0))) ,3) "Gets / Execution"
, Round(100*(e.buffer_gets - nvl(b.buffer_gets,0))/sp920.getGets(:pDbID,:pInstNum,:pBgnSnap,:pEndSnap,'NO'),3) "Percent of Total"
, Round((e.cpu_time - nvl(b.cpu_time,0))/1000000,3) "CPU (s)"
, Round((e.elapsed_time - nvl(b.elapsed_time,0))/1000000,3) "Elapsed (s)"
, Round(e.fetches - nvl(b.fetches,0)) "Fetches"
, sp920.getSQLText ( e.hash_value , 400) "SQL Statement"
from stats$sql_summary e
, stats$sql_summary b
where b.snap_id(+) = :pBgnSnap
and b.dbid(+) = e.dbid
and b.instance_number(+) = e.instance_number
and b.hash_value(+) = e.hash_value
and b.address(+) = e.address
and b.text_subset(+) = e.text_subset
and e.snap_id = :pEndSnap
and e.dbid = 2863128100
and e.instance_number = :pInstNum
and sp920.getSQLText ( e.hash_value , 400) like '%ZPV_DATA%'
order by 3 desc

How to retrieve entire SQL + Execution PLAN from Statspack for a table

To retrieve SQL plan you need to have statspack working on level 7

1. sprepsql.sql
The SQL report (sprepsql.sql) is a report for a specific SQL statement. The SQL report is usually run after examining the high-load SQL sections of the instance health report.The SQL report provides detailed statistics and data for a single SQL statement (as identified by the Hash Value in Statspack report).

2. Hash Value is known
- Select * from STATS$SQLTEXT where hash_value='%from stats pack%' order by piece;

- For an Object first locate the OBJECT_ID

select * from sys.obj$ where name='TRANSACTION'

select snap_time
snap_id,
plan_hash_value,
OBJECT# ,
OBJECT_NAME ,
OPERATION ,
OPTIONS ,
COST ,
IO_COST ,
CARDINALITY ,
POSITION ,
CPU_COST ,
OPTIMIZER ,
SEARCH_COLUMNS ,
BYTES ,
DISTRIBUTION ,
TEMP_SPACE ,
ACCESS_PREDICATES ,
FILTER_PREDICATES
from stats$SQL_PLAN a , STATS$SNAPSHOT b where object#='&&OBJECT_ID' and a.snap_id=b.snap_id;

http://OracleDbaSupport.co.uk is a blog site of Sagar Patil, an independent oracle consultant with a great understanding of how the Oracle database engine & Oracle Applications work together.

I am an Oracle Certified RAC DBA with over ten years experience supporting Production and Development instances of Oracle databases.
- Expert in building 10g RAC systems as well as rman, data guard backup and recovery strategies for production, test and development systems.
- Instructor for developers on Oracle architecture, Oracle9i /10g features, tuning methodologies, database replication, PL/SQL and Oracle Http Server.
- User of Statspack, SQL Trace, OEM Performance Manager, Quest Central, Quest Foglight, Quest SQL impact, Bennchamark factory, Quest SQL optimizer, TOAD and custom scripts.
- Writer of detailed standards & practices for Oracle installs, upgrades, tuning & backups on Oracle Databases and PL/SQL.Developer, designer and implementer of Disaster recovery backup Procedures
- Leader on major projects through all phases of development, testing and Support

I can be hired on a short term notice, to handle strategy, design, implementation, trouble-shooting, DBA cover, remote monitoring, and training.
Please visit www.oracledbasupport.co.uk for your oracle DBA needs.

Rate this Article: Current: 0 / 5 stars - 0 vote(s).

Article Source: http://www.articlesbase.com/databases-articles/getting-most-out-of-oracle-8i9i-statspack-405021.html

Print this Article Print article   Email to a Friend Send to friend   Publish this Article on your Website Publish this Article   Send Author Feedback Author feedback  
Sagar PatilAbout the Author:
Submitting articles has become one of the most popular means of generating quality backlinks and targeted traffic to your website. Join us today - It's Free!

Article Comments

Comment on this article Comment on this article
Your Name
Your Email:
Comment Body
Enter Validation Code: Captcha


Got a Question? Ask.

Ask the community a question about this article:

Q&A Powered by:
Powered by Yedda 

Latest Databases Articles

Ms Access Databases Don't Have to Look Unprofessional by Nicholas Brown
By: Nicholas Brown | 30/09/2008
Tips and tricks to help maximize the usability of your database by improving the user interface.

Get Rid of Porn-how to Get Rid of Porn From Your Computer
By: Valeri Tkatchenko | 29/09/2008
Get rid of porn today! This is important to get rid of porn from your hard drive or it can lend you in some serious trouble! Sometimes while you browse the internet porn fragments and popups install themselves into your registry and it is almost impossible to get rid of this stuff. They always popup on your screen and do generally have viruses and spy ware attached to them! Whether you downloaded the porn yourself or it entered the computer by itself you need to get rid of porn fast!!!

Using Your it to Excel in Tough Times
By: Robin George | 24/09/2008
Find out how to beat the current difficult financial climate, using the software on your computer.

Using Linq to Objects in C#
By: LinqHelp | 24/09/2008
In this tutorial, we will be looking at using LINQ to Objects. We will be creating a Windows Forms Application that will first define an array of numbers, and then we will use LINQ to Objects to interact with this collection of numbers.

Pulling Data From Multiple Tables Into a Single Query in Ms Access by Nicholas Brown
By: Nicholas Brown | 17/09/2008
A brief how-to on linking multiple tables within a single query. With this tool, users can develop more complex queries, reducing the need for several queries. This will also reduce the size of the database making it more efficient and easier to navigate.

Creating Linq to Sql Entities in Vb.net
By: LinqHelp | 15/09/2008
This tutorial will show how we can bypass the Designer and write the class ourselves, so that we get a better understanding of what's going on. For this example, we will be using a SQL database with one table and three columns - id, name, and city.

Creating Linq to Sql Entities in C#
By: LinqHelp | 15/09/2008
This tutorial will show how we can bypass the Designer and write the class ourselves, so that we get a better understanding of what's going on. For this example, we will be using a SQL database with one table and three columns - id, name, and city.

Querying Table Data Using Visual Basic Code in Ms Access
By: Nicholas Brown | 11/09/2008
A brief how-to on creating temporary recordsets using Visual Basic (VB) and Standard Query Language (SQL). With this tool, users can create faster, more efficient databases that take up less room on the computer.

More from Sagar Patil

Oracle Cost Based Optimizer & Effect of Optimizer_index_cost_adj Parameter
By: Sagar Patil | 07/05/2008 | Databases
In this article I will explain you a real life situation where adjutsing Optimizer_index_cost_adj had a knock on effect on database performance.

Article Categories






Give Feedback

Sign up for our email newsletter

Receive updates, enter your email below