Oracle database tips logo
Article categories | Blog and News Page | SQL | SQL*Plus | DBA Scripts | Standby dbs | Database Links | Techno webcasts | Oracle Magazine | Free IT Magazines | Oracle Database Hosting Companies | Site Search |
RSS
XML RSS
What is this?
AddThis Feed Button

Social Bookmarking


-- FREE --
IT Magazine
Subscriptions

Oracle Magazine Oracle Magazine Contains technology strategy articles, sample code, tips, Oracle and partner news, how-to articles for developers and DBAs

WebSite Magazine WebSite Magazine Practical advice, helpful tools and insights for website owners

Dr Dobb's Journal Dr Dobb's Journal enables coders to write the most efficient programs and help in daily programming quandaries

DM Review DM Review is recognized as the premier business intelligence, analytics and data warehousing publication
Various other Free IT magazine subscriptions
NoAdware Free Trial

NoAdware Remove
harmful
adware,
spyware,
trojans,
dialers
and worms!
- Featured ebook -

Database Normalization
by Alf Pedersen

Database Normalization ebook Understand and master how to normalize a database using methods richly documented with graphical ERD and server diagram examples

AWR Reports


Always test these 'AWR Reports' commands on a test server
before implementing them on a production server.


Background

In Oracle 9 , we used the statspack reports to acquire statistics about the database performance between two timed snapshots.
In Oracle10, the same principle applies, but the script names have changed and have become slightly more complex.
You will find steps below which will help you set up a script system to generate Automatic Workload Repository reports based on snapshots taken at the same time daily, and then emailing them to yourself via the Linux Mutt tool.

First script: /home/oracle/bin/spreport.sh
(make sure the file permissions are at least 744 ).



#!/bin/ksh 
ORACLE_SID=dev1 ; export ORACLE_SID
export ORACLE_HOME=/home/oracle/product/10.2.0
export PATH=${PATH}:${ORACLE_HOME}/bin

sqlplus /nolog @/home/oracle/bin/sql/daily_spreport.sql > /dev/null 2>&1

# now you can mail the logs to yourself.

/usr/bin/mutt -s "AWR report 11h00 to 12h00" -a
/home/oracle/bin/log/spreport_11h00_to_12h00.html
yourname@yourISP.com < /home/oracle/bin/message1.txt

/usr/bin/mutt -s "AWR report 12h00 to 13h00 " -a
/home/oracle/bin/log/spreport_12h00_to_13h00.html
yourname@yourISP.com < /home/oracle/bin/message2.txt


Message1.txt and Message2.txt are just plain text files which contain what will be in the body of your email.

message1.txt


 Oracle stats report 11h00-12h00 attached


message2.txt

Oracle stats report 12h00-13h00 attached


daily_spreport.sql

Here you collect the snapid's which you will use to base the reports on.
I have predefined the snapshots taken at 11h00,12h00 and 13h00.
(Note that tuning experts advise that to tune optimally, your snapshots should be
no more than 15 minutes apart. )



connect sys/itspassword as sysdba
set termout off

variable snap1 number
variable snap2 number
variable snap3 number


begin

select
     s.snap_id
 into :snap1
  from dba_hist_snapshot s
 where  trunc(cast(s.end_interval_time as date),'MI') 
= trunc(trunc(sysdate)+11/24,'MI'); select s.snap_id into :snap2 from dba_hist_snapshot s where trunc(cast(s.end_interval_time as date),'MI')
= trunc(trunc(sysdate)+12/24,'MI'); select s.snap_id into :snap3 from dba_hist_snapshot s where trunc(cast(s.end_interval_time as date),'MI')
= trunc(trunc(sysdate)+13/24,'MI'); end; / @/home/oracle/bin/sql/run_spreport :snap1 :snap2 /home/oracle/bin/log/spreport_11h00_to_12h00.html
@/home/oracle/bin/sql/run_spreport :snap2 :snap3 /home/oracle/bin/log/spreport_12h00_to_13h00.html exit


And finally:

For the next sql script, I have hardcoded the instance number and name, db id and db name.
You can get these from the following queries:



SQL> select instance_number,instance_name 
from v$instance; INSTANCE_NUMBER INSTANCE_NAME --------------- ---------------- 1 dev1 SQL> select dbid, name from v$database; DBID NAME ---------- --------- 1234567890 DEV1




run_spreport.sql


set termout off
define begin_snap=&1
define end_snap=&2
define report_name=&3
define  report_type  = 'html';
define  inst_num     = 1;
define  num_days     = 3;
define  inst_name    = 'dev1';
define  db_name      = 'DEV1';
define  dbid         = 1234567890;
@@?/rdbms/admin/awrrpti


Now you can schedule this with a cronjob to run daily at 14h30.


$ crontab -l

30 14 * * * /home/oracle/bin/spreport.sh >/dev/null 2>&1




Return from AWR report back to oracle-script-tutorials.