0% found this document useful (0 votes)
2K views

Windows Batch Script To Generate AWR Report

This document outlines the steps to generate an AWR report using a Windows batch script. It describes choosing between different script types for hourly, daily, or weekly reports. It provides the text snippets to paste into the batch script file for the SQL queries needed to get snapshot IDs and generate the HTML formatted AWR report. The full batch script is also shown, which executes the SQL queries, gets the database ID and snapshot IDs, generates the AWR report, and cleans up temporary files.

Uploaded by

Pravin Srinivas
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Windows Batch Script To Generate AWR Report

This document outlines the steps to generate an AWR report using a Windows batch script. It describes choosing between different script types for hourly, daily, or weekly reports. It provides the text snippets to paste into the batch script file for the SQL queries needed to get snapshot IDs and generate the HTML formatted AWR report. The full batch script is also shown, which executes the SQL queries, gets the database ID and snapshot IDs, generates the AWR report, and cleans up temporary files.

Uploaded by

Pravin Srinivas
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Windows Batch Script To Generate AWR Report

Step 1: Choose Type


Step 2: Copy Text 1 and Text 2 from selected Type
Step 3: Paste Text 1 and Text 2 in File_Name.bat
( i) Make Sure that copied text should be paste in straight line.
Step 4: Double click File_Name.bat to execute .bat file
Type 1: Script to generate Hourly report
Text 1:
echo SELECT max((SNAP_ID)-1)FROM DBA_HIST_SNAPSHOT where
begin_interval_time ^> trunc(sysdate); >> first_query.sql
Text 2:
echo SELECT max(SNAP_ID) FROM DBA_HIST_SNAPSHOT where
begin_interval_time ^> trunc(sysdate); >> first_query.sql
Type 2: Script to generate Daily report
Text 1:
echo SELECT min(SNAP_ID) FROM DBA_HIST_SNAPSHOT where
begin_interval_time ^> trunc(sysdate); >> first_query.sql
Text 2:
echo SELECT max(SNAP_ID) FROM DBA_HIST_SNAPSHOT where
begin_interval_time ^> trunc(sysdate); >> first_query.sql
Type 3: Script to generate Weekly report
Text 1:
echo SELECT min(SNAP_ID) FROM DBA_HIST_SNAPSHOT where
begin_interval_time ^> trunc(sysdate -7); >> first_query.sql
Text 2:
echo SELECT max(SNAP_ID) FROM DBA_HIST_SNAPSHOT where
begin_interval_time ^> trunc(sysdate -7); >> first_query.sql

File_Name.bat
@echo off
echo SET LINES 400 > first_query.sql
echo SET PAGES 400 >> first_query.sql
echo set head off >> first_query.sql
echo COL BEGIN_INTERVAL_TIME FOR A40 >> first_query.sql
echo COL END_INTERVAL_TIME FOR A40 >> first_query.sql
echo Spool min_snap_id.log >> first_query.sql

Paste Here (Text 1)


echo Spool off; >> first_query.sql
echo Spool max_snap_id.log >> first_query.sql

Paste Here (Text 2)


echo Spool off; >> first_query.sql
echo spool db_id.log >> first_query.sql
echo SELECT DBID FROM V$DATABASE; >> first_query.sql
echo Spool off; >> first_query.sql
echo exit >> first_query.sql
sqlplus / as sysdba @ first_query.sql
for /f "tokens=* delims=" %%A in (db_id.log) do set
databaseid=%%A
for /f "tokens=* delims=" %%A in (min_snap_id.log) do set
minsnap=%%A
for /f "tokens=* delims=" %%A in (max_snap_id.log) do set
maxsnap=%%A
echo SET HEADING OFF; > gen_awrrpt.sql
echoSET FEEDBACK OFF; >> gen_awrrpt.sql
echo SET LINESIZE 1500; >> gen_awrrpt.sql
echo PROMPT GETTING HTML FORMAT REPORT: >> gen_awrrpt.sql

echo SPOOL AWR_REPORT_HTML.HTML; >> gen_awrrpt.sql


echo SELECT OUTPUT FROM TABLE
(DBMS_WORKLOAD_REPOSITORY.AWR_REPORT_HTML >> gen_awrrpt.sql
echo (%databaseid%, >> gen_awrrpt.sql
echo 1,%minsnap% >> gen_awrrpt.sql
echo ,%maxsnap% >> gen_awrrpt.sql
echo ,8 >> gen_awrrpt.sql
echo ) >> gen_awrrpt.sql
echo ); >> gen_awrrpt.sql
echo SPOOL OFF; >> gen_awrrpt.sql
echo exit >> gen_awrrpt.sql
sqlplus / as sysdba @ gen_awrrpt.sql
end
del db_id.log
del min_snap_id.log
del max_snap_id.log
del gen_awrrpt.sql
del first_query.sql

You might also like