Find PGA Used Between Past Time - Interval

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#### Find PGA used and time duration of an SQL - input sql_id

set lines 1111


column END_TIME format a30

alter session set nls_date_format='YYYY/MM/DD HH24:MI:SS';


alter session set nls_timestamp_format='YYYY/MM/DD HH24:MI:SS';

select sql_id,
starting_time,
end_time,
(EXTRACT(HOUR FROM run_time) * 3600
+ EXTRACT(MINUTE FROM run_time) * 60
+ EXTRACT(SECOND FROM run_time)) run_time_sec,
READ_IO_BYTES,
PGA_ALLOCATED PGA_ALLOCATED_BYTES,
TEMP_ALLOCATED TEMP_ALLOCATED_BYTES
from (
select
sql_id,
max(sample_time - sql_exec_start) run_time,
max(sample_time) end_time,
sql_exec_start starting_time,
sum(DELTA_READ_IO_BYTES) READ_IO_BYTES,
sum(DELTA_PGA) PGA_ALLOCATED,
sum(DELTA_TEMP) TEMP_ALLOCATED
from
(
select sql_id,
sample_time,
sql_exec_start,
DELTA_READ_IO_BYTES,
sql_exec_id,
greatest(PGA_ALLOCATED - first_value(PGA_ALLOCATED) over (partition by
sql_id,sql_exec_id order by sample_time rows 1 preceding),0) DELTA_PGA,
greatest(TEMP_SPACE_ALLOCATED - first_value(TEMP_SPACE_ALLOCATED) over
(partition by sql_id,sql_exec_id order by sample_time rows 1 preceding),0)
DELTA_TEMP
from
dba_hist_active_sess_history
where
sample_time >= to_date ('2014/11/07 08:00:00','YYYY/MM/DD HH24:MI:SS')
and sample_time < to_date ('2014/11/07 15:30:00','YYYY/MM/DD HH24:MI:SS')
and sql_exec_start is not null
and IS_SQLID_CURRENT='Y'
)
group by sql_id,SQL_EXEC_ID,sql_exec_start
order by sql_id
)
where sql_id = '8c3cj05xy81zz'
order by sql_id, run_time_sec desc;

##### PGA consumption by SQLs (ref: http://bdrouvot.wordpress.com/2013/03/19/link-


huge-pga-temp/)

col percent head '%' for 99990.99


col star for A10 head ''

select SQL_ID,round(PGA_MB,1) PGA_MB,percent,rpad('*',percent*10/100,'*') star


from
(
select SQL_ID,sum(DELTA_PGA_MB) PGA_MB ,(ratio_to_report(sum(DELTA_PGA_MB)) over
())*100 percent,rank() over(order by sum(DELTA_PGA_MB) desc) rank
from
(
select
SESSION_ID,SESSION_SERIAL#,sample_id,SQL_ID,SAMPLE_TIME,IS_SQLID_CURRENT,SQL_CHILD_
NUMBER,PGA_ALLOCATED,
greatest(PGA_ALLOCATED - first_value(PGA_ALLOCATED) over (partition by
SESSION_ID,SESSION_SERIAL# order by sample_time rows 1 preceding),0)/power(1024,2)
"DELTA_PGA_MB"
from
v$active_session_history
where
IS_SQLID_CURRENT='Y'
and sample_time > sysdate-3600/86400
order by 1,2,3,4
)
group by sql_id
having sum(DELTA_PGA_MB) > 0
)
where rank < (10+1)
order by rank
/

Note:
sample time currently is 3600 = 1 hr
Rank currently is 10 = top 10 SQLs

You might also like