Coskan’s Approach to Oracle

November 18, 2011

On demand AWR Report Generator, for Many Node Cluster

Filed under: Basics, Performance, RAC — coskan @ 11:34 am

Since I got turbo boost (over 1000 hits a day-wooow) from Tanel Poder the Great, better I write something to deserve the fame. This one is a real quick one which made my life easier.

On my second week at current company, I had to cover Exadata for 2 weeks which were completely nightmare due to some problems. I had to work with Oracle Support too much and most of the time they ask AWR reports from 8 nodes for x hour duration. First day I was not armed with anything automatic, so tried to do it manually but it was proper nightmare for 8 nodes. Then I said this is complete rubbish way of wasting my time and I need to automate the process otherwise my life will be miserable. Finally I came up with something after couple of attempts

The script below is the result of this automation attempts.

define _interval=1   --1 for half hour 2 for 1 hour 
define _database_name='DBNAME'
define _begin_interval_date='141111 23:00:00'
define _end_interval_date='151111 05:00:00'
define _folder='C:\PERSONAL\awr\instance\EXADATA\141111'


SET termout OFF 
host mkdir &_folder
SET termout ON
host dir &_folder

SET heading off

spool gen_awr.sql
SELECT 'set veri off;' FROM dual;
SELECT 'set feedback off;' FROM dual;
SELECT 'set linesize 1500;' FROM dual;
SELECT 'set termout on;'||CHR(10) FROM dual;
SELECT  'spool &_folder\awrrptto_&_database_name'||CHR(95)||TO_CHAR(instance_number)||'_'||TO_CHAR(previous_snap_id)||'_'||TO_CHAR(snap_id)||'.html'||CHR(10)|| CHR(10)|| 
'SELECT * FROM TABLE(dbms_workload_repository.awr_report_html('||TO_CHAR(dbid)||','||TO_CHAR(instance_number)||','||TO_CHAR(previous_snap_id)||','||TO_CHAR(snap_id)||',8));'||CHR(10)
||CHR(10)||'spool off' 
FROM (
select instance_number,dbid,snap_id,
LEAD(snap_id, &_interval, 0) OVER (PARTITION BY instance_number ORDER BY snap_id DESC NULLS LAST) previous_snap_id,
LAG(snap_id, &_interval, 0) OVER (PARTITION BY instance_number ORDER BY snap_id DESC NULLS LAST) next_snap_id,
begin_interval_time 
from dba_hist_snapshot 
where dbid=(select dbid from v$database where name='&_database_name')
AND instance_number in (select DISTINCT inst_id from gv$database  )
AND begin_interval_time>=TO_DATE('&_begin_interval_date','DDMMYY HH24:MI:SS')-1/24
AND begin_interval_time<TO_DATE('&_end_interval_date','DDMMYY HH24:MI:SS')+1/24
) WHERE next_snap_id<>0 AND previous_snap_id<>0
order by instance_number,begin_interval_time asc;

spool off;


!!!To save it click on the view source link on the sourcode upright corner

Nothing rocket science, just using dbms_workload_repository.awr_report_html with some junior level analytic.

All you have to do is give the date, interval (only tested for half hour or one hour intervals)and folder to be saved then rest will be done by the script.

It will create a gen_awr.sql script which you will run and go have a coffee then when you come back your awr reports are ready to be sent.

so the sequence is

@gen_snap  ---assume you save it with this name
@gen_awr
--coffee break
--zip+upload

I would like to automate it further by doing the same for rac comparison or group of instance but I think I am too lazy or maybe busy with some other non-automatable rubbish :( (I also had some issues with rac comparison report formatting with the DBMS_WORKLOAD_REPOSITORY package so I gave up on that one)

Hope this tiny script save your time as much as it saves mine.

Advertisement

6 Comments »

  1. Hi-

    Good approach, I have also stuck in similar situation to generate awr reports for exadata (multi-nodes) and had to come with similar approach. Do you also not like of using DBMS_WORKLOAD_REPOSITORY.AWR_GLOBAL_REPORT_HTML ? personally I found myself comfortable with individual instance report but time consuming sometime.

    Comment by Jagjeet Singh — November 18, 2011 @ 12:07 pm

    • Thanks for your comment Jagjeet. I think idea of global report is really good, but somehow formatting of DBMS_WORKLOAD_REPOSITORY.AWR_GLOBAL_REPORT_HTML never worked for me :(

      Comment by coskan — November 18, 2011 @ 12:23 pm

  2. Hi Coskan,

    Great script !!!

    There is also 2 other scripts to get the AWR Workload RAC (Global) report script to get RAC-wide differences between values recorded in 2 snapshots =>

    $ORACLE_HOME/rdbms/admin/awrgrpt.sql (calls ” awrgrpti.sql “)

    Thanks for the script

    Regards,
    Divakar

    Comment by Divakar Mehta — December 15, 2011 @ 4:50 pm

    • Thank you very much mate I know the other two but as I said at the last paragraph I could not manage to get the right formatting for them :)

      Comment by coskan — December 17, 2011 @ 2:20 pm

  3. Coskan,
    Have you seen mine solution.
    http://damir-vadas.blogspot.com/2009/11/automated-awr-reports-in-oracle-10g11g.html
    Rg,
    Damir

    Comment by Damir Vadas — December 17, 2011 @ 2:09 pm

    • Thanks for stopping by Damir, I knew your solution which is neat but my problem is being a bit more flexible about the time interval and also interval between two snapshots that why I needed to use analytic and also I can’t add anything to databases without convincing change management :)

      Comment by coskan — December 17, 2011 @ 2:19 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 422 other followers