Oracle Performance – Statspack

I mention before in my blog how to Generate AWR Reports But now How to Generate Statpack and how to use it !!!!


enable Statpack :

By default Statpack is disable to enable it do the following

1- Create tablespace with size at least 200MB
2-@?/rdbms/admin/spcreate

Disable it 

@?/rdbms/admin/spdrop
 
Statpack works on snapshot you can do the following with oracle snap shot :
 
Generate Snapshot : 

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

Levels Description :


Level 0 - This level captures general statistics, 
including rollback segment, row cache, SGA, system events, background
events, session events, system statistics, wait statistics, lock
statistics, and Latch information.

Level 5 - This level includes capturing high resource usage SQL Statements, along with all data captured by lower levels.

Level 6 - This level includes capturing SQL plan and SQL plan usage
information for high resource usage SQL Statements, along with all data
captured by lower levels.

Level 7 - This level captures segment level statistics, including
logical and physical reads, row lock, itl and buffer busy waits, along
with all data captured by lower levels.
 
Level 10 - This level includes capturing Child Latch statistics, along with all data captured by lower levels. 
 
Delete SnapShot 


@?/rdbms/admin/sppurge;
 
Check SnapShot on Database Level : 

col "Date/Time" format a30
select snap_id
, snap_level
, to_char(snap_time,'HH24:MI:SS DD-MM-YYYY') "Date/Time"
from stats$snapshot
, v$database
order by snap_id
/

 To Scheducle One Hour Generate Snapshot :

@?/rdbms/admin/spauto.sql
 
This script use DBMS_JOB to create new job . you can check them from view dba_jobs
 and to delete job "exec dbms_job.remove();"
 
 

Finally Generate statpack Reports :

 
 @?/rdbms/admin/spreport.sql

AWR Reports Vs ASH Reports

Sometimes when you face performance issue On your database, Usually first thing you are doing is Generate One of the above reports . But What is the benefits of these reports ? What is the difference ? When Can i use them ?

Let Start

I share in my blog earlier how to generate AWR reports . But Today we are talking About another topic .

Automatic Workload Repository Reports/(AWR):

this report appear in 10g Database, I heard that some people said “AWR used Instead Of Statpack” !! NO AWR is higher Version of statpack , statpack still exists but you have to enable it.

The AWR takes a snap shot of the database in specified intervals (default is one hour) and stores in Sysaux tablespace. and you can change this interval using the following :

BEGIN
DBMS_WORKLOAD_REPOSITORY.modify_snapshot_settings(
retention => 43200, -- Minutes (= 30 Days). Current value retained if NULL.
interval => 30); -- Minutes. Current value retained if NULL.
END;
/

The snap shots are taken automatically if the statistics_level parameter is set to typical/all. If it set to basic then statistics details are not gathered,The AWR contains the performance statistics and workload information on the database.

and you can take extra snapshot by :

EXEC DBMS_WORKLOAD_REPOSITORY.create_snapshot;

BEGIN
DBMS_WORKLOAD_REPOSITORY.drop_snapshot_range (
low_snap_id => 22,
high_snap_id => 32);
END;
/

As i mention above you can enable it , disable by the following command :

Enable AWR :

alter system set  statistic_level = {typical | all} scope=spfile ;

Disable AWR :

alter system set   set statistic_level = {basic} scope=spfile

 Check Statistic if its been Gathered By Fire :

Select * from V$statistics_level;

The statistics are collected and stored in memory in SGA. The in memory statistics collection area is a circular buffer, where the old data is overwritten after flushing to disk.

he AWR statistics snap shot are owned by Sys schema. ,The AWR is used to collect performance statistics including:

  • Wait events used to identify performance problems.
  • Time model statistics indicating the amount of DB time associated with a process from the V$SESS_TIME_MODEL and V$SYS_TIME_MODEL views.
  • Active Session History (ASH) statistics from the V$ACTIVE_SESSION_HISTORY view.
  • Some system and session statistics from the V$SYSSTAT and V$SESSTAT views.
  • Object usage statistics.
  • Resource intensive SQL statements.

 

     Active Session History (ASH) :


     The Name of this reports describe what is the major difference between it and AWR , The ASH contains recent information on active sessions sampled every second. The AWR are taken every one hour and its one hour old will not help in diagnosing issues that are current on the database. Typically to resolve issues urgenly on the database, details information pertaining o last 5 to 10 mins is critical. Because recording session activity is expensive, ASH samples V$SESSION every second and records the event for which he session are waiting.

    ASH information through V$active_session_history , you can can check this table from Oracle Documentation .

    As appear in the Documentation the View contain :
    It include

    * sql identifier of sql statement.
    * object no., file no., and block no.
    * wait event identifier & parameters.
    * user identifier, Session identifier and Serial number.
    * client identifier and name of the operating system program.

    Conclusion :

    ASH can help you when there’s a sudden performance degradation of the database felt.
    AWR – historic past snapshot intervals.

    AWR, stores the session performance statistics for analysis later.
    ASH – the storage is not persistent and as time progresses, the old entries are removed to accommodate new ones. They can be viewed using V$ACTIVE_SESSION_HISTORY.

    For More Information also about Baseline in AWR.
    Thank You
    Osama Mustafa 

    Patchest Number For Database

    This is Some useful number for Database patches , you can download them from http://support.oracle.com

    9.2.0.4 = 3095277
    9.2.0.5 = 3501955
    9.2.0.6 = 3948480
    9.2.0.7 = 4163445
    9.2.0.8 = 4547809(9i Final)
    10.1.0.3 = 3761843
    10.1.0.4 = 4163362
    10.1.0.5 = 4505133
    10.2.0.2 = 4547817
    10.2.0.3 = 5337014
    10.2.0.4 = 6810189

    Thank you
    Osama Mustafa

    Moving Schema to another Tablespace using "move" command.

    Step One: Create New  tablespace

    SQL>Create tablespace datafile ‘\osama.dbf’ size 1G;

    Step Two : Check User On which Tablespace


    SQL> select owner, tablespace_name from dba_tables where owner=”
     
    Step three:Create Script 

    sqlplus / as sysdba
    spool osama.log

    SQL> select ‘alter table ‘ || table_name || ‘ move tablespace mytab ;’ from dba_tables where owner=” ;
     
    Spool off ;
     
    Step Four : Move Index
    SQL> select ‘Alter index ‘ || index_name || ‘ rebuild tablespace mytab ;’ from dba_indexes where owner=” ;
     
    Step Five : Check Again

    SQL> select owner, tablespace_name from dba_tables where owner=”;

     
     
    Thank you 
    Osama mustafa

    DBID without Select OR RMAN

    You can retive database id without Using v$view this way is useful when you losing your control file or data file and you need to know your DBID :

    connect / as sysdba
    SQL> startup nomount;
     
     
    SQL> alter system dump datafile '/home/oracle/app/oracle/oradata/orcl/system01.dbf' block min 1 block max 2;
     
    System altered.
     
    tail -f /home/oracle/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_10680.trc
    ...
    Start dump data block from file /home/oracle/app/oracle/oradata/orcl/system01.dbf minblk 1 maxblk 2
    V10 STYLE FILE HEADER:
    Compatibility Vsn = 186646528=0xb200000
    Db ID=1229390655=0x4947033f, Db Name='ORCL'
    ...
    SQL>  alter system dump datafile '/home/oracle/app/oracle/oradata/orcl/undotbs01.dbf'  block min 1 block max 2;
     
    System altered.
     
    tail -f /home/oracle/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_10680.trc
    ...
    Start dump data block from file /home/oracle/app/oracle/oradata/orcl/undotbs01.dbf minblk 1 maxblk 2
    V10 STYLE FILE HEADER:
    Compatibility Vsn = 186646528=0xb200000
    Db ID=1229390655=0x4947033f, Db Name='ORCL'

    Thank you
    Osama Mustafa

    DDL With the WAIT Option

    The DDL_LOCK_TIMEOUT parameter indicates the number of seconds a DDL command should wait for the locks to become available before throwing the resource busy error message

    For Example :

    CREATE TABLE lock_tab (id  NUMBER);
    INSERT INTO lock_tab VALUES (1);
     
    ALTER SESSION SET ddl_lock_timeout=30;
     
    ALTER TABLE lock_tab ADD (description  VARCHAR2(50)); 

    ALTER TABLE lock_tab ADD (
    *
    ERROR at line 1:
    ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired

     Ref :
    Oracle_base

    Thank you
    Osama mustafa

    Create Backup to another Location

    run {
    ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT ‘/u01/Rman/%U’;
    ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT ‘/u02/Rman/%U’;
    CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ‘u02/rman/%F’;
    backup incremental level 0 database;
    release channel disk1;
    release channel disk2;

    sql ‘alter system archive log current’;
    ALLOCATE CHANNEL disk1 DEVICE TYPE DISK FORMAT ‘/u01/Rman/LOG_%t_%s_%p_%U’;
    ALLOCATE CHANNEL disk2 DEVICE TYPE DISK FORMAT ‘/u02/Rman/LOG_%t_%s_%p_%U’;
    backup archivelog all DELETE INPUT;
    release channel disk1;
    release channel disk2;

    CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK CLEAR;
    }

    Thank you
    Osama mustafa

    manual record to the Alert.log

    Oracle Give us an Option to record our own error in alertlog.log But How can we Do that :

    The procedure kdswrt in dbms_system package allows us to write own messages in the alert log / trace files or both.It receives two parameters:

    1. –   A number that indicates where do we want to write our message:

    •      Writing to a TRACE file.
    •      Writing to the Alert.log file.
    •      Writing to both of them.

           2.   A text string (the message itself).

    How to Use it  :

    exec dbms_system.ksdwrt(2, ‘ORA-10200: Error in Database.);

     Sun Sep 29 10:00:57 2010
    Thread 1 advanced to log sequence 7615 (LGWR switch)
    Current log# 1 seq# 7615 mem# 0: u01/app/oracle/product/11.2.0/dbhome_1/REDO01.LOG
    Sun Sep 29 11:10:15 2010
    ORA-10200: Error in Database.
    Sun Sep 29 11:10:15 2010
    Thread 1 advanced to log sequence 7616 (LGWR switch)
    Current log# 2 seq# 7616 mem# 0: u01/app/oracle/product/11.2.0/dbhome_1/REDO02.LOG
    Sun Sep 29 10:00:57 2010
    Thread 1 advanced to log sequence 7615 (LGWR switch)
    Current log# 1 seq# 7615 mem# 0: u01/app/oracle/product/11.2.0/dbhome_1/REDO01.LOG

     It is a very useful feature, as we can use it in our PL/SQL procedures inside the exception handling section or to indicate the procedure’s progression.

    As i mention before my blog you can use X$DBGALERTEXT to check alert log via sqlplus (11g).

    Thank you
    Osama Mustafa

    Check Rman Backup/Validate

    There’s More than One Way to Do it :

    Check One :

    To check Datavase Backup

    RMAN > Restore Validate Database ;

    Check Two : 

    Check Spfile

    RMAN > restore validate spfile to ‘c:\temp\spfile.ora’;

    Check Three :

    Test Control File

    RMAN> restore validate controlfile to ‘c:\temp\control01.ctl’;

    Check Four :

    Test Archive log

    RMAN> list backup of archivelog all;

     or

    RMAN> list backup of archivelog all completed after ‘sysdate -1’;

    Then

    RMAN> restore validate archivelog from sequence XXX until sequence XXX; 

    Thank you
    Osama Mustafa