Often I need to be able to quickly make a judgment on how my databases perform historically. A bog standard AWR report does not give me the information that I need straight away, and sometimes I do feel overloaded with information that I do not need until I need to drill down to a specific problem.
So here are a few queries which I hope you would find useful too
– historical DB usage day by day by instance
with a
as (select trunc(begin_interval_time) cob, min(snap_id) start_snap_id, max(snap_id) end_snap_id
from dba_hist_snapshot group by trunc(begin_interval_time))
select (select distinct name from gv$database) as db, (select distinct name from gv$database)||case when s.instance_number=1 then ‘A’ else ‘B’ end as instance,
s.cob, to_char(s.cob,’Day’) as day_of_week, s.instance_number, round((end_value-start_value)/1000000/3600) db_time_hours from (
select a.cob, s.instance_number, s.value start_value from dba_hist_sys_time_model s, a where s.snap_id=a.start_snap_id and s.stat_name=’DB time’) s,
(select a.cob, e.instance_number, e.value end_value from dba_hist_sys_time_model e, a where e.snap_id=a.end_snap_id and e.stat_name=’DB time’) e
where s.cob=e.cob and s.instance_number=e.instance_number order by s.cob desc ,2
– historical DB usage day by day cummulative both nodes
with a
as (select trunc(begin_interval_time) cob, min(snap_id) start_snap_id, max(snap_id) end_snap_id
from dba_hist_snapshot group by trunc(begin_interval_time))
select (select distinct name from gv$database) as db, s.cob, to_char(s.cob,’Day’) as day_of_week, round((end_value-start_value)/1000000/3600) db_time_hours from (
select a.cob, sum(s.value) start_value from dba_hist_sys_time_model s, a where s.snap_id=a.start_snap_id and s.stat_name=’DB time’ group by a.cob) s,
(select a.cob,sum(e.value) end_value from dba_hist_sys_time_model e, a where e.snap_id=a.end_snap_id and e.stat_name=’DB time’ group by a.cob) e
where s.cob=e.cob order by s.cob desc ,2
– historical Physical IO usage day by day by instance
with a
as (select trunc(begin_interval_time) cob, min(snap_id) start_snap_id, max(snap_id) end_snap_id
from dba_hist_snapshot group by trunc(begin_interval_time))
select (select distinct name from gv$database) as db, (select distinct name from gv$database)||case when s.instance_number=1 then ‘A’ else ‘B’ end as instance,
s.cob, to_char(s.cob,’Day’) as day_of_week, s.instance_number, round((end_value-start_value)*8192/1024/1024/1024,2) physical_read_write_gb from (
select a.cob, s.instance_number, sum(s.value) start_value from DBA_HIST_SERVICE_STAT s, a
where s.snap_id=a.start_snap_id and s.stat_name like ‘physical%’ group by a.cob, s.instance_number) s,
(select a.cob, e.instance_number, sum(e.value) end_value from DBA_HIST_SERVICE_STAT e, a
where e.snap_id=a.end_snap_id and e.stat_name like ‘physical%’ group by a.cob, e.instance_number) e
where s.cob=e.cob and s.instance_number=e.instance_number order by s.cob desc ,2
– historical Physical IO usage day by day cummulative both nodes
with a
as (select trunc(begin_interval_time) cob, min(snap_id) start_snap_id, max(snap_id) end_snap_id
from dba_hist_snapshot group by trunc(begin_interval_time))
select (select distinct name from gv$database) as db, s.cob, to_char(s.cob,’Day’) as day_of_week, round((end_value-start_value)*8192/1024/1024/1024,2) physical_read_write_gb from (
select a.cob, sum(s.value) start_value from DBA_HIST_SERVICE_STAT s, a
where s.snap_id=a.start_snap_id and s.stat_name like ‘physical%’ group by a.cob) s,
(select a.cob, sum(e.value) end_value from DBA_HIST_SERVICE_STAT e, a
where e.snap_id=a.end_snap_id and e.stat_name like ‘physical%’ group by a.cob) e
where s.cob=e.cob order by s.cob desc ,2
– historical DB usage day by day by service_name cummulative both nodes
with a
as (select trunc(begin_interval_time) cob, min(snap_id) start_snap_id, max(snap_id) end_snap_id
from dba_hist_snapshot group by trunc(begin_interval_time))
select (select distinct name from gv$database) as db, s.cob, to_char(s.cob,’Day’) as day_of_week, s.service_name, round((end_value-start_value)/1000000/3600,2) db_time_hours from (
select a.cob, s.service_name, sum(s.value) start_value from DBA_HIST_SERVICE_STAT s, a
where s.snap_id=a.start_snap_id and s.stat_name = ‘DB time’ group by a.cob, s.service_name) s,
(select a.cob, e.service_name, sum(e.value) end_value from DBA_HIST_SERVICE_STAT e, a
where e.snap_id=a.end_snap_id and e.stat_name = ‘DB time’ group by a.cob, e.service_name) e
where s.cob=e.cob and s.service_name=e.service_name order by s.cob desc ,db_time_hours desc
– Drill down DB time hour by hour by instance
select * from (
select (select distinct name from gv$database) as db, (select distinct name from gv$database)||case when instance_number=1 then ‘A’ else ‘B’ end as instance, instance_number,
begin_interval_time, end_interval_time, stat_name, db_time_in_hr_by_period, rank() over (partition by instance_number, trunc(begin_interval_time) order by db_time_in_hr_by_period desc) heaviest_period_first
from (
select begin_interval_time, end_interval_time, instance_number, stat_name, round((value-prev_value)/1000000/3600,2) db_time_in_hr_by_period from (
select b.begin_interval_time, b.end_interval_time, a.instance_number, a.stat_name, a.value, lag(a.value,1,0) over (order by a.snap_id) as prev_value
from dba_hist_sys_time_model a,dba_hist_snapshot b
where a.snap_id=b.snap_id and a.stat_name=’DB time’
and a.instance_number=b.instance_number
and a.instance_number=1
order by a.snap_id) where prev_value <> 0 )
union all
select (select distinct name from gv$database) as db, (select distinct name from gv$database)||case when instance_number=1 then ‘A’ else ‘B’ end as instance, instance_number,
begin_interval_time, end_interval_time, stat_name, db_time_in_hr_by_period, rank() over (partition by instance_number, trunc(begin_interval_time) order by db_time_in_hr_by_period desc) heaviest_period_first
from (
select begin_interval_time, end_interval_time, instance_number, stat_name, round((value-prev_value)/1000000/3600,2) db_time_in_hr_by_period from (
select b.begin_interval_time, b.end_interval_time, a.instance_number, a.stat_name, a.value, lag(a.value,1,0) over (order by a.snap_id) as prev_value
from dba_hist_sys_time_model a,dba_hist_snapshot b
where a.snap_id=b.snap_id and a.stat_name=’DB time’
and a.instance_number=b.instance_number
and a.instance_number=2
order by a.snap_id) where prev_value <> 0 )
)
order by instance_number desc, trunc(begin_interval_time) desc, heaviest_period_first