Genawr
Genawr
################################################
#############################
--#
--#
--#
--# @genawr.sql
--#
--#
--
################################################
#############################
-- The following list of SQL*Plus bind variables will be defined and assigned a
value
repfooter off;
ttitle off;
btitle off;
set timing off veri off space 1 flush on pause off termout on numwidth 10;
set echo off feedback off pagesize 60 linesize 80 newpage 1 recsep off;
column dbid heading "DB Id" new_value dbid format 9999999999 just c;
prompt
prompt ~~~~~~~~~~~~~~~~
, d.name db_name
, i.instance_number inst_num
, i.instance_name inst_name
from v$database d,
v$instance i;
prompt
prompt
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
select distinct
ci.instance_name = wr.instance_name
, wr.instance_number instt_num
, wr.db_name dbb_name
, wr.instance_name instt_name
, wr.host_name host
prompt
prompt Using &&dbid for database Id
--
begin
:dbid := &dbid;
:inst_num := &inst_num;
end;
--
-- Error reporting
declare
cursor cidnum is
select 'X'
from dba_hist_database_instance
select to_char(max(end_interval_time),'dd/mm/yyyy')
from dba_hist_snapshot
vx char(1);
begin
open cidnum;
if cidnum%notfound then
raise_application_error(-20200,
end if;
close cidnum;
open csnapid;
if csnapid%notfound then
raise_application_error(-20200,
end if;
close csnapid;
end;
--
prompt
prompt
prompt
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~
prompt Entering the number of days (n) will result in the most recent
prompt
prompt
set heading off;
,0 , 'no snapshots'
from sys.dual;
--
ttitle off;
, di.instance_name inst_name
, di.db_name db_name
, s.snap_id snap_id
, s.snap_level lvl
from dba_hist_snapshot s
, dba_hist_database_instance di
, 0 , to_date('31-JAN-9999','DD-MON-YYYY')
, 3.14, s.end_interval_time
, to_date(:max_snap_time,'dd/mm/yyyy') - (&&num_days-
1))
clear break;
ttitle off;
--
prompt
prompt
prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prompt
--
begin
:bid := &&begin_snap;
:eid := &&end_snap;
:name := '&&db_name';
end;
prompt
--
-- Error reporting
declare
select end_interval_time
, startup_time
from dba_hist_snapshot
bsnapt dba_hist_snapshot.end_interval_time%type;
bstart dba_hist_snapshot.startup_time%type;
esnapt dba_hist_snapshot.end_interval_time%type;
estart dba_hist_snapshot.startup_time%type;
begin
open cspid(:bid);
if cspid%notfound then
raise_application_error(-20200,
end if;
close cspid;
-- Check End Snapshot id is valid and get corresponding instance startup time
open cspid(:eid);
if cspid%notfound then
raise_application_error(-20200,
raise_application_error(-20200,
end if;
close cspid;
-- Check startup time is same for begin and end snapshot ids
raise_application_error(-20200,
end if;
end;
repfooter off;
ttitle off;
btitle off;
prompt
prompt
prompt Create new OS-level AWR directory to store reports (NULL value not
allowed!)
prompt
prompt
host ls -rlt
prompt
prompt
prompt
prompt
declare
v_file UTL_FILE.file_type;
begin
for i in &&begin_snap...&&end_snap-1
loop
begin
v_file := UTL_FILE.fopen('AWR_DIR', 'awr_'||:name||'_'||:inst_num||'_'|| i || '_' ||
(i+1) || '.html', 'w', 32767);
) loop
utl_file.put_line(v_file, c_awrrpt.output);
end loop;
utl_file.fclose(v_file);
end;
end loop;
end;
prompt
prompt
declare
v_file UTL_FILE.file_type;
begin
for i in 0..1
loop
begin
v_file := UTL_FILE.fopen('AWR_DIR',
'awr_'||:name||'_'||:inst_num||'_OVERALL_'||:bid||'_'||:eid||'.html', 'w', 32767);
) loop
utl_file.put_line(v_file, c_awrrpt.output);
end loop;
utl_file.fclose(v_file);
end;
end loop;
end;
-- PL/SQL code block to recursively create AWR snapshots for hourly intervals
prompt
prompt
declare
v_interval number;
v_file UTL_FILE.file_type;
begin
open c_interval;
close c_interval;
case true
then
v_interval :=round(3600/v_interval);
loop
begin
) loop
utl_file.put_line(v_file, c_awrrpt.output);
end loop;
utl_file.fclose(v_file);
end;
end loop;
else
v_interval :=2;
end case;
end;
-- Once PL/SQL completes successfully, drop the created directory from earlier
prompt
prompt