--------------CPU Utlization------------
column cpu_time heading 'CPU|Time'
column elapsed_time heading 'Elapsed|Time'
column disk_reads heading 'Disk|Reads'
column buffer_gets heading 'Buffer|Gets'
column rows_processed heading 'Rows|Processed'
column sql_id for a20
set pages 55 lines 132
select * from (
select
SQL_ID,
sum(CPU_TIME_DELTA)/10000 cpu_time,
sum(elapsed_time_delta)/1000 elapsed_time,
sum(DISK_READS_DELTA) disk_reads,
sum(BUFFER_GETS_DELTA) buffer_gets,
sum(ROWS_PROCESSED_DELTA) rows_processed,
count(*)
from
DBA_HIST_SQLSTAT a, dba_hist_snapshot s
where
s.snap_id = a.snap_id
and s.begin_interval_time > sysdate -1
and EXTRACT(HOUR FROM S.END_INTERVAL_TIME) between '&BEGIN_HOUR' and '&END_HOUR'
group by
SQL_ID
order by
sum(CPU_TIME_DELTA) desc)
where rownum < 5;
---------------------HISTORY SQL TEXT---------------------
select SQL_ID, SQL_TEXT from dba_hist_sqltext where SQL_TEXT like '%&TEXT%';
---------------------no of executions of a sqlid---------------------
set lines 1000 pages 1000
select SNAP_ID, BEGIN_INTERVAL_TIME, END_INTERVAL_TIME from dba_hist_snapshot order
by SNAP_ID;
select sql_id, sum(executions_delta) from DBA_HIST_SQLSTAT where SNAP_ID between
'&BEGIN_SNAPID' and '&END_SNAPID' and sql_id= '&SQL_ID' group by sql_id;
select sql_id, sum(executions_delta) from DBA_HIST_SQLSTAT where sql_id= '&SQL_ID'
group by sql_id;
---------------ELAPSED TIME-------------------------
col BUFFER_GETS for 999999999999999999
col ELAPSED_TIME for 999999999999999999
col DISK_READS for 999999999999999999
col EXECUTIONS for 9999999999999
col ROWS_PROCESSED for 9999999999999
col CPU_TIME for 9999999999999.99
col sql_id for a20
set lines 1000 pages 10000
select
SQL_ID,
sum(CPU_TIME_DELTA)/10000 cpu_time,
sum(elapsed_time_delta)/1000 elapsed_time,
sum(DISK_READS_DELTA) disk_reads,
sum(BUFFER_GETS_DELTA) buffer_gets,
sum(executions_delta) executions,
sum(ROWS_PROCESSED_DELTA) rows_processed
from
DBA_HIST_SQLSTAT
where
sql_id='&SQL_ID'
group by
SQL_ID
order by
sum(elapsed_time_delta) desc;
--------------Top 5 Sqls in last one hour-------------
select * from (
select active_session_history.sql_id,
dba_users.username,
sqlarea.sql_text,
sum(active_session_history.wait_time +
active_session_history.time_waited) ttl_wait_time
from v$active_session_history active_session_history,
v$sqlarea sqlarea,
dba_users
where
active_session_history.sample_time between sysdate - 1/24 and sysdate
and active_session_history.sql_id = sqlarea.sql_id
and active_session_history.user_id = dba_users.user_id
group by active_session_history.sql_id,sqlarea.sql_text, dba_users.username
order by 4 desc )
where rownum < 5;
-----------HISTORICAL HIGH TEMP QUERY-----------
--List only queries whose TEMP is greater than 50G
select sql_id,max(TEMP_SPACE_ALLOCATED)/(1024*1024) MB
from DBA_HIST_ACTIVE_SESS_HISTORY
where
sample_time > sysdate-1 and
TEMP_SPACE_ALLOCATED > (50*1024*1024*1024)
group by sql_id order by 2;
--Specific to SQL_ID
select sql_id,max(TEMP_SPACE_ALLOCATED)/(1024*1024) MB, SAMPLE_TIME, SESSION_ID
from DBA_HIST_ACTIVE_SESS_HISTORY
where
sample_time > sysdate-1 and sql_id='&SQL_ID'
group by sql_id, SAMPLE_TIME, SESSION_ID order by 2;
-----------Load Profile-------------------
col short_name format a20 heading 'Load Profile'
col per_sec format 999,999,999.9 heading 'Per Second'
col per_tx format 999,999,999.9 heading 'Per Transaction'
set colsep ' '
select lpad(short_name, 20, ' ') short_name
, per_sec
, per_tx from
(select short_name
, max(decode(typ, 1, value)) per_sec
, max(decode(typ, 2, value)) per_tx
, max(m_rank) m_rank
from
(select /*+ use_hash(s) */
m.short_name
, [Link] * coeff value
, typ
, m_rank
from v$sysmetric s,
(select 'Database Time Per Sec' metric_name,
'DB Time' short_name, .01 coeff, 1 typ, 1 m_rank from dual union all
select 'CPU Usage Per Sec' metric_name,
'DB CPU' short_name, .01 coeff, 1 typ, 2 m_rank from dual union all
select 'Redo Generated Per Sec' metric_name,
'Redo size' short_name, 1 coeff, 1 typ, 3 m_rank from dual union all
select 'Logical Reads Per Sec' metric_name,
'Logical reads' short_name, 1 coeff, 1 typ, 4 m_rank from dual union all
select 'DB Block Changes Per Sec' metric_name,
'Block changes' short_name, 1 coeff, 1 typ, 5 m_rank from dual union all
select 'Physical Reads Per Sec' metric_name,
'Physical reads' short_name, 1 coeff, 1 typ, 6 m_rank from dual union all
select 'Physical Writes Per Sec' metric_name,
'Physical writes' short_name, 1 coeff, 1 typ, 7 m_rank from dual union all
select 'User Calls Per Sec' metric_name,
'User calls' short_name, 1 coeff, 1 typ, 8 m_rank from dual union all
select 'Total Parse Count Per Sec' metric_name,
'Parses' short_name, 1 coeff, 1 typ, 9 m_rank from dual union all
select 'Hard Parse Count Per Sec' metric_name,
'Hard Parses' short_name, 1 coeff, 1 typ, 10 m_rank from dual union all
select 'Logons Per Sec' metric_name,
'Logons' short_name, 1 coeff, 1 typ, 11 m_rank from dual union all
select 'Executions Per Sec' metric_name,
'Executes' short_name, 1 coeff, 1 typ, 12 m_rank from dual union all
select 'User Rollbacks Per Sec' metric_name,
'Rollbacks' short_name, 1 coeff, 1 typ, 13 m_rank from dual union all
select 'User Transaction Per Sec' metric_name,
'Transactions' short_name, 1 coeff, 1 typ, 14 m_rank from dual union all
select 'User Rollback UndoRec Applied Per Sec' metric_name,
'Applied urec' short_name, 1 coeff, 1 typ, 15 m_rank from dual union all
select 'Redo Generated Per Txn' metric_name,
'Redo size' short_name, 1 coeff, 2 typ, 3 m_rank from dual union all
select 'Logical Reads Per Txn' metric_name,
'Logical reads' short_name, 1 coeff, 2 typ, 4 m_rank from dual union all
select 'DB Block Changes Per Txn' metric_name,
'Block changes' short_name, 1 coeff, 2 typ, 5 m_rank from dual union all
select 'Physical Reads Per Txn' metric_name,
'Physical reads' short_name, 1 coeff, 2 typ, 6 m_rank from dual union all
select 'Physical Writes Per Txn' metric_name,
'Physical writes' short_name, 1 coeff, 2 typ, 7 m_rank from dual union all
select 'User Calls Per Txn' metric_name,
'User calls' short_name, 1 coeff, 2 typ, 8 m_rank from dual union all
select 'Total Parse Count Per Txn' metric_name,
'Parses' short_name, 1 coeff, 2 typ, 9 m_rank from dual union all
select 'Hard Parse Count Per Txn' metric_name,
'Hard Parses' short_name, 1 coeff, 2 typ, 10 m_rank from dual union all
select 'Logons Per Txn' metric_name,
'Logons' short_name, 1 coeff, 2 typ, 11 m_rank from dual union all
select 'Executions Per Txn' metric_name,
'Executes' short_name, 1 coeff, 2 typ, 12 m_rank from dual union all
select 'User Rollbacks Per Txn' metric_name,
'Rollbacks' short_name, 1 coeff, 2 typ, 13 m_rank from dual union all
select 'User Transaction Per Txn' metric_name,
'Transactions' short_name, 1 coeff, 2 typ, 14 m_rank from dual union all
select 'User Rollback Undo Records Applied Per Txn' metric_name,
'Applied urec' short_name, 1 coeff, 2 typ, 15 m_rank from dual) m
where m.metric_name = s.metric_name
and s.intsize_csec > 5000
and s.intsize_csec < 7000)
group by short_name)
order by m_rank;