Saturday, May 31, 2025
SET MARKUP HTML ON
SET ECHO OFF FEEDBACK OFF
SET LINESIZE 120 PAGESIZE 100
COLUMN begin_hour FORMAT A20 HEADING "Hour"
COLUMN instance_number FORMAT 99 HEADING "Inst#"
COLUMN average_active_sessions FORMAT 9999.99 HEADING "AAS"
COLUMN status FORMAT A10 HEADING "Status"
SPOOL hourly_instance_aas.html
PROMPT ',blocker_osid)||
' from Instance '||blocker_instance BLOCKER_PROC,'Number of waiters: '||num_waiters waiters,
'Wait Event: ' ||wait_event_text wait_event, 'P1: '||p1 p1, 'P2: '||p2 p2, 'P3: '||p3 p3,
'Seconds in Wait: '||in_wait_secs Seconds, 'Seconds Since Last Wait: '||time_since_last_wait_secs sincelw,
'Wait Chain: '||chain_id ||': '||chain_signature chain_signature,'Blocking Wait Chain: '||decode(blocker_chain_id,null,
'',blocker_chain_id) blocker_chain
FROM v$wait_chains wc,
v$instance i
WHERE wc.instance = i.instance_number (+)
AND ( num_waiters > 0
OR ( blocker_osid IS NOT NULL
AND in_wait_secs > 10 ) )
ORDER BY chain_id,
num_waiters DESC)
WHERE ROWNUM < 101;
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Latch statistics 1 |
PROMPT | This is RAC aware script |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------+
select inst_id, name latch_name,
round((gets-misses)/decode(gets,0,1,gets),3) hit_ratio,
round(sleeps/decode(misses,0,1,misses),3) "SLEEPS/MISS"
from gv$latch
where round((gets-misses)/decode(gets,0,1,gets),3) < .99
and gets != 0
order by round((gets-misses)/decode(gets,0,1,gets),3);
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Latch status |
PROMPT | This is RAC aware script |
PROMPT | Desc: Please look for cols WAIT_TIME_SECONDS and WAIT_TIME |
PROMPT | Critical if both of the numbers are high |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------+
col NAME for a50
select v.*
from
(select
name, inst_id,
gets,
misses,
round(misses*100/(gets+1), 3) misses_gets_pct,
spin_gets,
sleep1,
wait_time,
round(wait_time/1000000) wait_time_seconds,
rank () over
(order by wait_time desc) as misses_rank
from
gv$latch
where gets + misses + sleep1 + wait_time > 0
order by
wait_time desc
) v
where
misses_rank <= 10;
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : No Willing to wait mode latch stats |
PROMPT | This is RAC aware script |
PROMPT | Desc: This section is for those latches who requests in immediate_gets |
PROMPT | mode. Look for SLEEPSMISS column which is last one in results |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------+
select inst_id, name latch_name,
round((immediate_gets/(immediate_gets+immediate_misses)), 3) hit_ratio,
round(sleeps/decode(immediate_misses,0,1,immediate_misses),3) "SLEEPS/MISS"
from gv$latch
where round((immediate_gets/(immediate_gets+immediate_misses)), 3) < .99
and immediate_gets + immediate_misses > 0
order by round((immediate_gets/(immediate_gets+immediate_misses)), 3);
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : SQL with 100 or more unshared child cursors |
PROMPT | This is RAC aware script |
PROMPT | Desc: Results coming here with more than 500 childs can lead to high |
PROMPT | hard parsing situations which could lead to Library cache latching issu|
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------+
WITH
not_shared AS (
SELECT /*+ MATERIALIZE NO_MERGE */ /* 2a.135 */
sql_id, COUNT(*) child_cursors,
RANK() OVER (ORDER BY COUNT(*) DESC NULLS LAST) AS sql_rank
FROM gv$sql_shared_cursor
GROUP BY
sql_id
HAVING COUNT(*) > 99
)
SELECT /*+ NO_MERGE */ /* 2a.135 */
ns.sql_rank,
ns.child_cursors,
ns.sql_id,
(SELECT s.sql_text FROM gv$sql s WHERE s.sql_id = ns.sql_id AND ROWNUM = 1) sql_text
FROM not_shared ns
ORDER BY
ns.sql_rank,
ns.child_cursors DESC,
ns.sql_id;
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Sesions Waiting |
PROMPT | Desc: The entries that are shown at the top are the sessions that have |
PROMPT | waited the longest amount of time that are waiting for non-idle wait |
PROMPT | events (event column).
PROMPT | This is RAC aware script |
PROMPT +------------------------------------------------------------------------+
set numwidth 15
set heading on
column state format a7 tru
column event format a25 tru
column last_sql format a40 tru
select sw.inst_id, sa.sql_id,sw.sid, sw.state, sw.event, sw.seconds_in_wait seconds,
sw.p1, sw.p2, sw.p3, sa.sql_text last_sql
from gv$session_wait sw, gv$session s, gv$sqlarea sa
where sw.event not in
('rdbms ipc message','smon timer','pmon timer',
'SQL*Net message from client','lock manager wait for remote message',
'ges remote message', 'gcs remote message', 'gcs for action', 'client message',
'pipe get', 'null event', 'PX Idle Wait', 'single-task message',
'PX Deq: Execution Msg', 'KXFQ: kxfqdeq - normal deqeue',
'listen endpoint status','slave wait','wakeup time manager')
and sw.seconds_in_wait > 0
and (sw.inst_id = s.inst_id and sw.sid = s.sid)
and (s.inst_id = sa.inst_id and s.sql_address = sa.address)
order by seconds desc;
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Archive generation per hour basis |
PROMPT | This is RAC aware script |
PROMPT | Desc: This will give an idea about any spike in redo activity or DMLs |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------+
set linesize 140
set feedback off
set timing off
set pagesize 1000
col ARCHIVED format a8
col ins format 99 heading "DB"
col member format a80
col status format a12
col archive_date format a20
col member format a60
col type format a10
col group# format 99999999
col min_archive_interval format a20
col max_archive_interval format a20
col h00 heading "H00" format a3
col h01 heading "H01" format a3
col h02 heading "H02" format a3
col h03 heading "H03" format a3
col h04 heading "H04" format a3
col h05 heading "H05" format a3
col h06 heading "H06" format a3
col h07 heading "H07" format a3
col h08 heading "H08" format a3
col h09 heading "H09" format a3
col h10 heading "H10" format a3
col h11 heading "H11" format a3
col h12 heading "H12" format a3
col h13 heading "H13" format a3
col h14 heading "H14" format a3
col h15 heading "H15" format a3
col h16 heading "H16" format a3
col h17 heading "H17" format a3
col h18 heading "H18" format a3
col h19 heading "H19" format a3
col h20 heading "H20" format a3
col h21 heading "H21" format a3
col h22 heading "H22" format a3
col h23 heading "H23" format a3
col total format a6
col date format a10
select * from v$logfile order by group#;
select * from v$log order by SEQUENCE#;
select max( sequence#) last_sequence, max(completion_time) completion_time, max(block_size) block_size from v$archived_log ;
SELECT instance ins,
log_date "DATE" ,
lpad(to_char(NVL( COUNT( * ) , 0 )),6,' ') Total,
lpad(to_char(NVL( SUM( decode( log_hour , '00' , 1 ) ) , 0 )),3,' ') h00 ,
lpad(to_char(NVL( SUM( decode( log_hour , '01' , 1 ) ) , 0 )),3,' ') h01 ,
lpad(to_char(NVL( SUM( decode( log_hour , '02' , 1 ) ) , 0 )),3,' ') h02 ,
lpad(to_char(NVL( SUM( decode( log_hour , '03' , 1 ) ) , 0 )),3,' ') h03 ,
lpad(to_char(NVL( SUM( decode( log_hour , '04' , 1 ) ) , 0 )),3,' ') h04 ,
lpad(to_char(NVL( SUM( decode( log_hour , '05' , 1 ) ) , 0 )),3,' ') h05 ,
lpad(to_char(NVL( SUM( decode( log_hour , '06' , 1 ) ) , 0 )),3,' ') h06 ,
lpad(to_char(NVL( SUM( decode( log_hour , '07' , 1 ) ) , 0 )),3,' ') h07 ,
lpad(to_char(NVL( SUM( decode( log_hour , '08' , 1 ) ) , 0 )),3,' ') h08 ,
lpad(to_char(NVL( SUM( decode( log_hour , '09' , 1 ) ) , 0 )),3,' ') h09 ,
lpad(to_char(NVL( SUM( decode( log_hour , '10' , 1 ) ) , 0 )),3,' ') h10 ,
lpad(to_char(NVL( SUM( decode( log_hour , '11' , 1 ) ) , 0 )),3,' ') h11 ,
lpad(to_char(NVL( SUM( decode( log_hour , '12' , 1 ) ) , 0 )),3,' ') h12 ,
lpad(to_char(NVL( SUM( decode( log_hour , '13' , 1 ) ) , 0 )),3,' ') h13 ,
lpad(to_char(NVL( SUM( decode( log_hour , '14' , 1 ) ) , 0 )),3,' ') h14 ,
lpad(to_char(NVL( SUM( decode( log_hour , '15' , 1 ) ) , 0 )),3,' ') h15 ,
lpad(to_char(NVL( SUM( decode( log_hour , '16' , 1 ) ) , 0 )),3,' ') h16 ,
lpad(to_char(NVL( SUM( decode( log_hour , '17' , 1 ) ) , 0 )),3,' ') h17 ,
lpad(to_char(NVL( SUM( decode( log_hour , '18' , 1 ) ) , 0 )),3,' ') h18 ,
lpad(to_char(NVL( SUM( decode( log_hour , '19' , 1 ) ) , 0 )),3,' ') h19 ,
lpad(to_char(NVL( SUM( decode( log_hour , '20' , 1 ) ) , 0 )),3,' ') h20 ,
lpad(to_char(NVL( SUM( decode( log_hour , '21' , 1 ) ) , 0 )),3,' ') h21 ,
lpad(to_char(NVL( SUM( decode( log_hour , '22' , 1 ) ) , 0 )),3,' ') h22 ,
lpad(to_char(NVL( SUM( decode( log_hour , '23' , 1 ) ) , 0 )),3,' ') h23
FROM (
SELECT thread# INSTANCE ,
TO_CHAR( first_time , 'YYYY-MM-DD' ) log_date ,
TO_CHAR( first_time , 'hh24' ) log_hour
FROM v$log_history
)
GROUP BY
instance,log_date
ORDER BY
log_date ;
select trunc(min(completion_time - first_time))||' Day '||
to_char(trunc(sysdate,'dd') + min(completion_time - first_time),'hh24:mm:ss')||chr(10) min_archive_interval,
trunc(max(completion_time - first_time))||' Day '||
to_char(trunc(sysdate,'dd') + max(completion_time - first_time),'hh24:mm:ss')||chr(10) max_archive_interval
from gv$archived_log
where sequence# <> ( select max(sequence#) from gv$archived_log ) ;
set feedback on
set timing on
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : SESSION DETAILS |
PROMPT | This is RAC aware script |
PROMPT | Desc: Shows details about all sessions and their states active, inactiv|
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------+
set linesize 400 pagesize 400
select resource_name, current_utilization, max_utilization, limit_value, inst_id
from gv$resource_limit
where resource_name in ('sessions', 'processes');
select count(s.status) INACTIVE_SESSIONS
from gv$session s, gv$process p
where
p.addr=s.paddr and
s.status='INACTIVE';
select count(s.status) "INACTIVE SESSIONS > 3HOURS "
from gv$session s, gv$process p
where
p.addr=s.paddr and
s.last_call_et > 10800 and
s.status='INACTIVE';
select count(s.status) ACTIVE_SESSIONS
from gv$session s, gv$process p
where
p.addr=s.paddr and
s.status='ACTIVE';
select s.program,count(s.program) Inactive_Sessions_from_1Hour
from gv$session s,gv$process p
where p.addr=s.paddr AND
s.status='INACTIVE'
and s.last_call_et > (10800)
group by s.program
order by 2 desc;
set linesize 400 pagesize 400
col INST_ID for 99
col spid for a10
set linesize 150
col PROGRAM for a10
col action format a10
col logon_time format a16
col module format a13
col cli_process format a7
col cli_mach for a15
col status format a10
col username format a10
col last_call_et_Hrs for 9999.99
col sql_hash_value for 9999999999999
col username for a10
set linesize 152
set pagesize 80
col "Last SQL" for a60
col elapsed_time for 999999999999
select p.spid, s.sid,s.serial#,s.last_call_et/3600 last_call_et_3Hrs ,s.status,s.action,s.module,s.program,t.disk_reads,lpad(t.sql_text,30) "Last SQL"
from gv$session s, gv$sqlarea t,gv$process p
where s.sql_address =t.address and
s.sql_hash_value =t.hash_value and
p.addr=s.paddr and
s.status='INACTIVE'
and s.last_call_et > (10800)
order by last_call_et;
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Lists all locked objects for whole RAC. |
PROMPT | This is RAC aware script |
PROMPT | Desc: Remember to always look for X type locks, SS, SX, S, SSX are fine|
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------|
SET LINESIZE 500
SET PAGESIZE 1000
SET VERIFY OFF
COLUMN owner FORMAT A20
COLUMN username FORMAT A20
COLUMN object_owner FORMAT A20
COLUMN object_name FORMAT A30
COLUMN locked_mode FORMAT A15
SELECT b.inst_id,
b.session_id AS sid,
NVL(b.oracle_username, '(oracle)') AS username,
a.owner AS object_owner,
a.object_name,
Decode(b.locked_mode, 0, 'None',
1, 'Null (NULL)',
2, 'Row-S (SS)',
3, 'Row-X (SX)',
4, 'Share (S)',
5, 'S/Row-X (SSX)',
6, 'Exclusive (X)',
b.locked_mode) locked_mode,
b.os_user_name
FROM dba_objects a,
gv$locked_object b
WHERE a.object_id = b.object_id
ORDER BY 1, 2, 3, 4;
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Undo usage report |
PROMPT | This is RAC aware script |
PROMPT | Desc: This shows details about all undo rollback segments, best for 01555|
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------|
SET LINESIZE 200
COLUMN username FORMAT A15
SELECT s.inst_id,
s.username,
s.sid,
s.serial#,
t.used_ublk,
t.used_urec,
rs.segment_name,
r.rssize,
r.status
FROM gv$transaction t,
gv$session s,
gv$rollstat r,
dba_rollback_segs rs
WHERE s.saddr = t.ses_addr
AND s.inst_id = t.inst_id
AND t.xidusn = r.usn
AND t.inst_id = r.inst_id
AND rs.segment_id = t.xidusn
ORDER BY t.used_ublk DESC;
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Local Enqueues |
PROMPT | This is RAC aware script |
PROMPT | Desc: This section will show us if there are any local enqueues. |
PROMPT | The addr column will show the lock address. The type will show the type|
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------|
set numwidth 12
column event format a12 tru
select l.inst_id, l.sid, l.addr, l.type, l.id1, l.id2,
decode(l.block,0,'blocked',1,'blocking',2,'global') block,
sw.event, sw.seconds_in_wait sec
from gv$lock l, gv$session_wait sw
where (l.sid = sw.sid and l.inst_id = sw.inst_id)
and l.block in (0,1)
order by l.type, l.inst_id, l.sid;
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : ORA errors reported in alert log of databases, SYSDATE-1 |
PROMPT | This is RAC aware script |
PROMPT | Desc: Shows all alert log ora errors and log files with locations |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------|
select TO_CHAR(A.ORIGINATING_TIMESTAMP, 'dd.mm.yyyy hh24:mi:ss') MESSAGE_TIME
,inst_id, message_text
,host_id
,inst_id
,adr_home
from v$DIAG_ALERT_EXT A
where A.ORIGINATING_TIMESTAMP > sysdate-1
and component_id='rdbms'
and message_text like '%ORA-%'
order by 1 desc;
spool off
exit
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Top object waits in the database. |
PROMPT | This is RAC aware script |
PROMPT | Desc: Shows Object name along with count, sqlid, and total time waited |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------|
set lines 170 echo off
col event format a26 head 'Wait Event' trunc
col mod format a26 head 'Module' trunc
col sqlid format a13 head 'SQL Id'
col oname format a38 head 'Object Name'
col sname format a30 head 'SubObject Name'
col otyp format a10 head 'Object Typ' trunc
col cnt format 999999 head 'Wait Cnt'
col twait format 9999999999 head 'Tot Time|Waited'
select o.owner||'.'||o.object_name oname
,o.object_type otyp
,o.subobject_name sname
,h.event event
,h.wcount cnt
,h.twait twait
,h.sql_id sqlid
,h.module mod
from (select current_obj#,sql_id,module,event,count(*) wcount,sum(time_waited+wait_time) twait
from gv$active_session_history
where event not in (
'queue messages'
,'rdbms ipc message'
,'rdbms ipc reply'
,'pmon timer'
,'smon timer'
,'jobq slave wait'
,'wait for unread message on broadcast channel'
,'wakeup time manager')
and event not like 'SQL*Net%'
and event not like 'Backup%'
group by current_obj#,sql_id,module,event
order by twait desc) h
,dba_objects o
where h.current_obj# = o.object_id
and rownum < 31
;
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : list of all custom SQL Profiles in DB |
PROMPT | This is RAC aware script |
PROMPT | Desc: Shows details of all SQL profiles already there in the database |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------|
set linesize 400 pagesize 400
col name for a30
col created for a30
select name, created, status,sql_text as SQLTXT from dba_sql_profiles order by created desc;
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Show active sessions from latest ASH sample |
PROMPT | This is RAC aware script |
PROMPT | Desc: Shows Show active sessions from latest ASH sample |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------|
set linesi 290
col hostcpu format 999.9 head 'Host|Cpu%'
col module format a15 head 'Module' trunc
col sidser format a15 head 'Sid,Serial',module) module
from gv$active_session_history
where PGA_ALLOCATED > 2*1024*1024
and sample_time > sysdate-3/60/1440
order by sample_time, qc_session_id, SESSION_ID
/
PROMPT +------------------------------------------------------------------------+
PROMPT | Report : Top 10 objects in database.
PROMPT | This is RAC aware script |
PROMPT | Desc: Database Usage |
PROMPT | Instance : ¤t_instance |
PROMPT +------------------------------------------------------------------------|
col segment_name format a30
col owner format a20
col tablespace_name format a30
select * from (select owner,segment_name,SEGMENT_TYPE,TABLESPACE_NAME,round(sum(BYTES)/(1024*1024*1024)) size_in_GB
from dba_segments group by owner,segment_name,SEGMENT_TYPE,TABLESPACE_NAME order by 5 desc ) where rownum<=10;
Saturday, May 24, 2025
---------------------------------------------------------------------------------------
set lines 155
col dbtime for 999,999.99
col begin_timestamp for a40
select * from (
select begin_snap, end_snap, timestamp begin_timestamp, inst, a/1000000/60 DBtime from
(
select
e.snap_id end_snap,
lag(e.snap_id) over (order by e.snap_id) begin_snap,
lag(s.end_interval_time) over (order by e.snap_id) timestamp,
s.instance_number inst,
e.value,
nvl(value-lag(value) over (order by e.snap_id),0) a
from dba_hist_sys_time_model e, DBA_HIST_SNAPSHOT s
where s.snap_id = e.snap_id
and e.instance_number = s.instance_number
and to_char(e.instance_number) like nvl('&instance_number',to_char(e.instance_number))
and stat_name = 'DB time'
)
where begin_snap between nvl('&begin_snap_id',0) and nvl('&end_snap_id',99999999)
and begin_snap=end_snap-1
order by dbtime desc
)
where rownum < 31
/
--------------------------------------------------------------------------------------------------------------------
-- File name: prashantpoormanscript1.sql
-- Version: V1.1 (12-08-2021) Fancy Version
-- Purpose: This script can be used on any Oracle DB to know what all running and for how long and waiting
-- Also provides details on SQL and SESSION level.
-- Author: Prashant Dixit The Fatdba www.fatdba.com
--------------------------------------------------------------------------------------------------------------------
set linesize 400
set pagesize 400
col ACTION for a22
col USERNAME for a9
col SQL_ID for a16
col EVENT for a20
col OSUSER for a10
col PROCESS for a8
col MACHINE for a15
col OSUSER for a8
col PROGRAM for a15
col module for a20
col BLOCKING_INSTANCE for a20
select
'InstID .............................................: '||x.inst_id,
'SID ................................................: '||x.sid,
'Serial .............................................: '||x.serial#,
'Username ...........................................: '||x.username,
'SQLID ..............................................: '||x.sql_id,
'PHV ................................................: '||plan_hash_value,
'DISK_READS .........................................: '||sqlarea.DISK_READS,
'BUFFER_GETS ........................................: '||sqlarea.BUFFER_GETS,
'ROWS_PROCESSED ..... ...............................: '||sqlarea.ROWS_PROCESSED,
'Event .............................................: '||x.event,
'OSUser .............................................: '||x.osuser,
'Status .............................................: '||x.status,
'BLOCKING_SESSION_STATUS ............................: '||x.BLOCKING_SESSION_STATUS,
'BLOCKING_INSTANCE ..................................: '||x.BLOCKING_INSTANCE,
'BLOCKING_SESSION ...................................: '||x.BLOCKING_SESSION,
'PROCESS ............................................: '||x.process,
'MACHINE ............................................: '||x.machine,
'PROGRAM ............................................: '||x.program,
'MODULE .............................................: '||x.module,
'ACTION .............................................: '||x.action,
'LOGONTIME ..........................................: '||TO_CHAR(x.LOGON_TIME, 'MM-DD-YYYY HH24:MI:SS') logontime,
'LAST_CALL_ET .......................................: '||x.LAST_CALL_ET,
'SECONDS_IN_WAIT ....................................: '||x.SECONDS_IN_WAIT,
'STATE ..............................................: '||x.state,
'RUNNING_SINCE ......................................: '||ltrim(to_char(floor(x.LAST_CALL_ET/3600), '09')) || ':' || ltrim(to_char(floor(mod(x.LAST_CALL_ET, 3600)/60), '09')) || ':' || ltrim(to_char(mod(x.LAST_CALL_ET, 60), '09')) RUNNING_SINCE,
'SQLTEXT ............................................: '||sql_text
from gv$sqlarea sqlarea
,gv$session x
where x.sql_hash_value = sqlarea.hash_value
and x.sql_address = sqlarea.address
and sql_text not like '%select x.inst_id,x.sid ,x.serial# ,x.username ,x.sql_id ,plan_hash_value%'
and sql_text not like '%select :"SYS_B_00"||x.inst_id, :"SYS_B_01"||x.sid, :"SYS_B_02"||x.serial#,%'
and x.status='ACTIVE'
and x.USERNAME is not null
and x.SQL_ADDRESS = sqlarea.ADDRESS
and x.SQL_HASH_VALUE = sqlarea.HASH_VALUE
order by RUNNING_SINCE desc;
set lines 155
col dbtime for 999,999.99
col begin_timestamp for a40
select * from (
select begin_snap, end_snap, timestamp begin_timestamp, inst, a/1000000/60 DBtime from
(
select
e.snap_id end_snap,
lag(e.snap_id) over (order by e.snap_id) begin_snap,
lag(s.end_interval_time) over (order by e.snap_id) timestamp,
s.instance_number inst,
e.value,
nvl(value-lag(value) over (order by e.snap_id),0) a
from dba_hist_sys_time_model e, DBA_HIST_SNAPSHOT s
where s.snap_id = e.snap_id
and e.instance_number = s.instance_number
and to_char(e.instance_number) like nvl('&instance_number',to_char(e.instance_number))
and stat_name = 'DB time'
)
where begin_snap between nvl('&begin_snap_id',0) and nvl('&end_snap_id',99999999)
and begin_snap=end_snap-1
order by dbtime desc
)
where rownum < 31
/
SET MARKUP HTML ON
SET ECHO OFF
SET FEEDBACK OFF
SET PAGESIZE 100
SET LINESIZE 200
SPOOL 63_top_fullscan_high_io.html
PROMPT 1 THEN 'RAC' ELSE 'SINGLE' END
FROM gv\\$instance;
EXIT;
EOF
)
if [[ "$result" == "RAC" ]]; then
return 0 # true: RAC
else
return 1 # false: Single instance
fi
}
if is_rac "$DB_CONNECT_STRING"; then
echo "✅ RAC Database detected"
else
echo "ℹ️ Single Instance Database"
fi
COL wait_chain FOR A300 WORD_WRAP
COL "%This" FOR A6
PROMPT
PROMPT -- Display ASH Wait Chain Signatures script v0.8 by Tanel Poder ( https://tanelpoder.com )
WITH
bclass AS (SELECT /*+ INLINE */ class, ROWNUM r from v$waitstat),
ash AS (SELECT /*+ INLINE QB_NAME(ash) LEADING(a) USE_HASH(u) SWAP_JOIN_INPUTS(u) */
a.*
, CAST(a.sample_time AS DATE) sample_time_s -- round timestamp to 1 sec boundary for matching across RAC nodes
, o.*
, u.username
, CASE WHEN a.session_type = 'BACKGROUND' AND a.program LIKE '%(DBW%)' THEN
'(DBWn)'
WHEN a.session_type = 'BACKGROUND' OR REGEXP_LIKE(a.program, '.*\([PJ]\d+\)') THEN
REGEXP_REPLACE(SUBSTR(a.program,INSTR(a.program,'(')), '\d', 'n')
ELSE
'('||REGEXP_REPLACE(REGEXP_REPLACE(a.program, '(.*)@(.*)(\(.*\))', '\1'), '\d', 'n')||')'
END || ' ' program2
, NVL(a.event||CASE WHEN event like 'enq%' AND session_state = 'WAITING'
THEN ' [mode='||BITAND(p1, POWER(2,14)-1)||']'
WHEN a.event IN (SELECT name FROM v$event_name WHERE parameter3 = 'class#')
THEN ' ['||NVL((SELECT class FROM bclass WHERE r = a.p3),'undo @bclass '||a.p3)||']' ELSE null END,'ON CPU')
|| ' ' event2
, TO_CHAR(CASE WHEN session_state = 'WAITING' THEN p1 ELSE null END, '0XXXXXXXXXXXXXXX') p1hex
, TO_CHAR(CASE WHEN session_state = 'WAITING' THEN p2 ELSE null END, '0XXXXXXXXXXXXXXX') p2hex
, TO_CHAR(CASE WHEN session_state = 'WAITING' THEN p3 ELSE null END, '0XXXXXXXXXXXXXXX') p3hex
, CASE WHEN BITAND(time_model, POWER(2, 01)) = POWER(2, 01) THEN 'DBTIME ' END
||CASE WHEN BITAND(time_model, POWER(2, 02)) = POWER(2, 02) THEN 'BACKGROUND ' END
||CASE WHEN BITAND(time_model, POWER(2, 03)) = POWER(2, 03) THEN 'CONNECTION_MGMT ' END
||CASE WHEN BITAND(time_model, POWER(2, 04)) = POWER(2, 04) THEN 'PARSE ' END
||CASE WHEN BITAND(time_model, POWER(2, 05)) = POWER(2, 05) THEN 'FAILED_PARSE ' END
||CASE WHEN BITAND(time_model, POWER(2, 06)) = POWER(2, 06) THEN 'NOMEM_PARSE ' END
||CASE WHEN BITAND(time_model, POWER(2, 07)) = POWER(2, 07) THEN 'HARD_PARSE ' END
||CASE WHEN BITAND(time_model, POWER(2, 08)) = POWER(2, 08) THEN 'NO_SHARERS_PARSE ' END
||CASE WHEN BITAND(time_model, POWER(2, 09)) = POWER(2, 09) THEN 'BIND_MISMATCH_PARSE ' END
||CASE WHEN BITAND(time_model, POWER(2, 10)) = POWER(2, 10) THEN 'SQL_EXECUTION ' END
||CASE WHEN BITAND(time_model, POWER(2, 11)) = POWER(2, 11) THEN 'PLSQL_EXECUTION ' END
||CASE WHEN BITAND(time_model, POWER(2, 12)) = POWER(2, 12) THEN 'PLSQL_RPC ' END
||CASE WHEN BITAND(time_model, POWER(2, 13)) = POWER(2, 13) THEN 'PLSQL_COMPILATION ' END
||CASE WHEN BITAND(time_model, POWER(2, 14)) = POWER(2, 14) THEN 'JAVA_EXECUTION ' END
||CASE WHEN BITAND(time_model, POWER(2, 15)) = POWER(2, 15) THEN 'BIND ' END
||CASE WHEN BITAND(time_model, POWER(2, 16)) = POWER(2, 16) THEN 'CURSOR_CLOSE ' END
||CASE WHEN BITAND(time_model, POWER(2, 17)) = POWER(2, 17) THEN 'SEQUENCE_LOAD ' END
||CASE WHEN BITAND(time_model, POWER(2, 18)) = POWER(2, 18) THEN 'INMEMORY_QUERY ' END
||CASE WHEN BITAND(time_model, POWER(2, 19)) = POWER(2, 19) THEN 'INMEMORY_POPULATE ' END
||CASE WHEN BITAND(time_model, POWER(2, 20)) = POWER(2, 20) THEN 'INMEMORY_PREPOPULATE ' END
||CASE WHEN BITAND(time_model, POWER(2, 21)) = POWER(2, 21) THEN 'INMEMORY_REPOPULATE ' END
||CASE WHEN BITAND(time_model, POWER(2, 22)) = POWER(2, 22) THEN 'INMEMORY_TREPOPULATE ' END
||CASE WHEN BITAND(time_model, POWER(2, 23)) = POWER(2, 23) THEN 'TABLESPACE_ENCRYPTION ' END time_model_name
FROM
gv$active_session_history a
, dba_users u
, (SELECT
object_id,data_object_id,owner,object_name,subobject_name,object_type
, owner||'.'||object_name obj
, owner||'.'||object_name||' ['||object_type||']' objt
FROM dba_objects) o
WHERE
a.user_id = u.user_id (+)
AND a.current_obj# = o.object_id(+)
AND sample_time BETWEEN &3 AND &4
),
ash_samples AS (SELECT /*+ INLINE */ DISTINCT sample_time_s FROM ash),
ash_data AS (SELECT /*+ INLINE */ * FROM ash),
chains AS (
SELECT /*+ INLINE */
d.sample_time_s ts
, level lvl
, session_id sid
, REPLACE(SYS_CONNECT_BY_PATH(&1, '->'), '->', ' -> ')||CASE WHEN CONNECT_BY_ISLEAF = 1 AND d.blocking_session IS NOT NULL THEN ' -> [idle blocker '||d.blocking_inst_id||','||d.blocking_session||','||d.blocking_session_serial#||(SELECT ' ('||s.program||')' FROM gv$session s WHERE (s.inst_id, s.sid , s.serial#) = ((d.blocking_inst_id,d.blocking_session,d.blocking_session_serial#)))||']' ELSE NULL END path -- there's a reason why I'm doing this
--, SYS_CONNECT_BY_PATH(&1, ' -> ')||CASE WHEN CONNECT_BY_ISLEAF = 1 THEN '('||d.session_id||')' ELSE NULL END path
-- , REPLACE(SYS_CONNECT_BY_PATH(&1, '->'), '->', ' -> ')||CASE WHEN CONNECT_BY_ISLEAF = 1 AND LEVEL > 1 THEN ' [sid='||session_id||' seq#='||TO_CHAR(seq#)||']' ELSE NULL END path -- there's a reason why I'm doing this
--, REPLACE(SYS_CONNECT_BY_PATH(&1, '->'), '->', ' -> ') path -- there's a reason why I'm doing this (ORA-30004 :)
, CASE WHEN CONNECT_BY_ISLEAF = 1 THEN d.session_id ELSE NULL END sids
, CONNECT_BY_ISLEAF isleaf
, CONNECT_BY_ISCYCLE iscycle
, d.*
FROM
ash_samples s
, ash_data d
WHERE
s.sample_time_s = d.sample_time_s
AND d.sample_time BETWEEN &3 AND &4
CONNECT BY NOCYCLE
( PRIOR d.blocking_session = d.session_id
AND PRIOR d.blocking_inst_id = d.inst_id
AND PRIOR s.sample_time_s = d.sample_time_s -- Different RAC nodes have sample_id drift (assuming that clocks are synced enough)
)
START WITH &2
)
SELECT * FROM (
SELECT
LPAD(ROUND(RATIO_TO_REPORT(COUNT(*)) OVER () * 100)||'%',5,' ') "%This"
, COUNT(*) seconds
, ROUND(COUNT(*) / ((CAST(&4 AS DATE) - CAST(&3 AS DATE)) * 86400), 1) AAS
, path wait_chain
, TO_CHAR(MIN(sample_time), 'YYYY-MM-DD HH24:MI:SS') first_seen
, TO_CHAR(MAX(sample_time), 'YYYY-MM-DD HH24:MI:SS') last_seen
, COUNT(DISTINCT sids) num_sids
, MIN(sids)
, MAX(sids)
FROM
chains
WHERE
isleaf = 1
GROUP BY
&1
, path
ORDER BY
COUNT(*) DESC
)
WHERE
ROWNUM <= 30
/
Top 10 Full Table Scan SQLs (Non-SYS) with High Logical Reads
SELECT * FROM ( SELECT ss.sql_id, u.username, ROUND(ss.buffer_gets_total / DECODE(ss.executions_total, 0, 1, ss.executions_total)) AS avg_buffer_gets, ss.executions_total, ss.buffer_gets_total, CASE WHEN ROUND(ss.buffer_gets_total / DECODE(ss.executions_total, 0, 1, ss.executions_total)) > 100000 THEN 'CRITICAL' WHEN ROUND(ss.buffer_gets_total / DECODE(ss.executions_total, 0, 1, ss.executions_total)) > 50000 THEN 'WARNING' ELSE 'OK' END AS status, st.sql_text FROM dba_hist_sqlstat ss JOIN dba_hist_sqltext st ON ss.sql_id = st.sql_id JOIN dba_users u ON ss.parsing_schema_id = u.user_id WHERE ss.snap_id > ( SELECT MAX(snap_id) - 48 FROM dba_hist_snapshot ) AND u.username NOT IN ('SYS', 'SYSTEM') AND EXISTS ( SELECT 1 FROM dba_hist_sql_plan p WHERE p.sql_id = ss.sql_id AND p.operation = 'TABLE ACCESS' AND p.options = 'FULL' ) ORDER BY ss.buffer_gets_total DESC ) WHERE ROWNUM <= 10; SPOOL OFF; SPOOL OFF; SPOOL OFF; SPOOL OFF; --============================================================================== -- GPI - Gunther Pippèrr -- Desc: Informations about cursor usage in the database -- Date: 08.2013 --============================================================================== set linesize 130 pagesize 300 column user_name format a25 ttitle left "Open Cursor used summary" skip 2 select inst_id , user_name , count(*) from gv$open_cursor where user_name is not null -- and user_name not in ( 'SYS' ) group by rollup (inst_id,user_name) / ttitle left "Open Cursor used by session" skip 2 select inst_id , sid , user_name , count(*) from gv$open_cursor where user_name is not null -- and user_name not in ( 'SYS' ) group by inst_id,user_name,sid order by 4,1,3 / column name format a30 heading "Statistic|Name" column value format 999G999G999G999 heading "Statistic|value" ttitle left "Open Cursor used by session over the statistic" skip 2 select a.value , s.username , s.sid , s.serial# from v$sesstat a , v$statname b , v$session s where a.statistic# = b.statistic# and s.sid=a.sid and b.name = 'opened cursors current' and s.username is not null / ttitle left "Open Cursor Statistic " skip 2 column execute_count format 999G999G999G999G999 heading "SQL Execution" column parse_count format 999G999G999G999G999 heading "Parse Count" column cursor_hits format 999G999G999G999G999 heading "Cursor Hits" column hit_percentage_parse format 99D990 heading "Parse| % Total" column hit_percentage_cursor format 99D990 heading "Cursor Cache | % Total" select inst_id , execute_count , parse_count , round(parse_count/(execute_count/100),3) as hit_percentage_parse , cursor_hits , round(cursor_hits/(execute_count/100),3) as hit_percentage_cursor from ( select name , value , inst_id from gv$sysstat where name in ('session cursor cache hits','parse count (total)','execute count') ) pivot ( max (value) FOR name IN ( 'session cursor cache hits' AS cursor_hits , 'parse count (total)' as parse_count , 'execute count' as execute_count ) ) / prompt ... 11g Syntax if you hid an error on 10g! prompt ... if Cursor Cache % Total is a relatively low percentage prompt ... you should increate the DB Parameter session_cached_cursors ttitle left "Cursor Settings init.ora " skip 2 show parameter cursor ttitle left "Session cached Cursor Usage " skip 2 -- -- see also -- SCRIPT - to Set the 'SESSION_CACHED_CURSORS' and 'OPEN_CURSORS' Parameters Based on Usage (Doc ID 208857.1) -- select a.inst_id , 'session_cached_cursors' parameter , lpad(value, 5) value , decode(value, 0, ' n/a', to_char(100 * used / value, '990') || '%') usage from ( select max(s.value) used , inst_id from v$statname n , gv$sesstat s where n.name = 'session cursor cache count' and s.statistic# = n.statistic# group by inst_id ) a, ( select value,inst_id from gv$parameter where name = 'session_cached_cursors' ) b where a.inst_id=b.inst_id union all select c.inst_id , 'open_cursors' , lpad(value, 5) , to_char(100 * used / value, '990') || '%' from ( select s.inst_id , max((s.value)) used from v$statname n , gv$sesstat s where n.name in ('opened cursors current') and s.statistic# = n.statistic# group by s.inst_id ) c, ( select value,inst_id from gv$parameter where name = 'open_cursors' ) d where c.inst_id=d.inst_id order by 1,2 / ttitle off prompt ... if usage percentage is a near 100% prompt ... you should increate the DB Parameter session_cached_cursors ### 63_top_fullscan_high_io.sql SET MARKUP HTML ON SET ECHO OFF SET FEEDBACK OFF SET PAGESIZE 100 SET LINESIZE 200 SPOOL 63_top_fullscan_high_io.html PROMPTTop 10 Full Table Scan SQLs (Non-SYS) with High I/O Waits
SELECT * FROM ( SELECT s.sql_id, u.username, ROUND(ss.disk_reads / DECODE(ss.executions, 0, 1, ss.executions)) AS avg_disk_reads, ss.executions, ss.buffer_gets, CASE WHEN ROUND(ss.disk_reads / DECODE(ss.executions, 0, 1, ss.executions)) > 10000 THEN 'CRITICAL' WHEN ROUND(ss.disk_reads / DECODE(ss.executions, 0, 1, ss.executions)) > 5000 THEN 'WARNING' ELSE 'OK' END AS status, st.sql_text FROM dba_hist_sqlstat ss JOIN dba_hist_sqltext st ON ss.sql_id = st.sql_id JOIN dba_users u ON ss.parsing_schema_id = u.user_id WHERE ss.snap_id > ( SELECT MAX(snap_id) - 48 FROM dba_hist_snapshot ) AND u.username NOT IN ('SYS', 'SYSTEM') AND EXISTS ( SELECT 1 FROM dba_hist_sql_plan p WHERE p.sql_id = ss.sql_id AND p.operation = 'TABLE ACCESS' AND p.options = 'FULL' ) ORDER BY ss.disk_reads DESC ) WHERE ROWNUM <= 10; SPOOL OFF; SET LINESIZE 200 SET PAGESIZE 100 COLUMN inst_id FORMAT 99 COLUMN name FORMAT A60 COLUMN value_mb FORMAT 999999999.99 SELECT inst_id, name, ROUND(value / 1024 / 1024, 2) AS value_mb FROM gv$cell_global_statistics WHERE name IN ( 'CLO read retries due to stalling', 'IO bytes sent via Smart Interconnect to cells', 'IO bytes sent via non-Smart Interconnect to cells' ) ORDER BY inst_id, name; SET LINESIZE 200 SET PAGESIZE 100 COLUMN inst_id FORMAT 99 COLUMN event FORMAT A50 COLUMN wait_time_milli FORMAT 999 COLUMN wait_count FORMAT 999999 SELECT inst_id, event, wait_time_milli, wait_count FROM gv$event_histogram WHERE event IN ( 'gc buffer busy acquire', 'gc buffer busy release', 'gc cr block busy' ) AND wait_count > 0 ORDER BY inst_id, event, wait_time_milli; SET ECHO OFF FEEDBACK OFF PAGES 50 LINES 167 TRIMSPOOL ON SET MARKUP HTML ON SPOOL 59_gc_contention_19c.html SELECT inst_id AS "Inst#", event AS "Event", total_waits AS "# Waits", ROUND(time_waited*10) AS "Time (ms)", ROUND((time_waited*10)/DECODE(total_waits, 0, 1, total_waits), 1) AS "Avg Wait (ms)", CASE WHEN ROUND((time_waited*10)/DECODE(total_waits, 0, 1, total_waits), 1) > 5 THEN 'CRITICAL' WHEN ROUND((time_waited*10)/DECODE(total_waits, 0, 1, total_waits), 1) > 2 THEN 'WARNING' ELSE 'OK' END AS "Status" FROM gv$system_event WHERE event IN ('gc buffer busy acquire','gc buffer busy release','gc cr block busy') ORDER BY inst_id, time_waited DESC; SPOOL OFF; 60_interconnect_19c.sql -- 60_interconnect_19c.sql - Monitor RAC interconnect usage and latency SET ECHO OFF FEEDBACK OFF PAGES 100 LINES 200 TRIMSPOOL ON SET MARKUP HTML ON SET ECHO OFF FEEDBACK OFF PAGES 100 LINES 200 TRIMSPOOL ON SET MARKUP HTML ON SPOOL 60_interconnect_19c.html SELECT inst_id AS "Inst#", ROUND( MAX(CASE WHEN name='gc cr block receive time' THEN value END) / GREATEST(MAX(CASE WHEN name='gc cr blocks received' THEN value END), 1) * 10, 2) AS "Avg CR (ms)", ROUND( MAX(CASE WHEN name='gc current block receive time' THEN value END) / GREATEST(MAX(CASE WHEN name='gc current blocks received' THEN value END), 1) * 10, 2) AS "Avg CUR (ms)", CASE WHEN ROUND( MAX(CASE WHEN name='gc cr block receive time' THEN value END) / GREATEST(MAX(CASE WHEN name='gc cr blocks received' THEN value END), 1) * 10, 2) > 5 THEN 'CRITICAL' WHEN ROUND( MAX(CASE WHEN name='gc cr block receive time' THEN value END) / GREATEST(MAX(CASE WHEN name='gc cr blocks received' THEN value END), 1) * 10, 2) > 2 THEN 'WARNING' ELSE 'OK' END AS "Status" FROM gv$sysstat WHERE name IN ( 'gc cr block receive time','gc cr blocks received', 'gc current block receive time','gc current blocks received' ) GROUP BY inst_id ORDER BY inst_id; SPOOL OFF; 61_iops_trend_19c.sql SET ECHO OFF FEEDBACK OFF PAGES 200 LINES 200 TRIMSPOOL ON SET MARKUP HTML ON SPOOL 61_iops_trend_19c.html SELECT TO_CHAR(begin_interval_time, 'YYYY-MM-DD HH24:MI') AS "Snap Time", instance_number, ROUND(SUM(iops), 2) AS "IOPS", CASE WHEN ROUND(SUM(iops), 2) > 10000 THEN 'CRITICAL' WHEN ROUND(SUM(iops), 2) > 5000 THEN 'WARNING' ELSE 'OK' END AS "Status" FROM ( SELECT s.begin_interval_time, t.instance_number, CASE WHEN t.metric_name = 'Physical Read Total IO Requests Per Sec' THEN t.average WHEN t.metric_name = 'Physical Write Total IO Requests Per Sec' THEN t.average WHEN t.metric_name = 'Redo Writes Per Sec' THEN t.average END AS iops FROM dba_hist_sysmetric_summary t JOIN dba_hist_snapshot s ON t.snap_id = s.snap_id AND t.dbid = s.dbid AND t.instance_number = s.instance_number WHERE t.metric_name IN ( 'Physical Read Total IO Requests Per Sec', 'Physical Write Total IO Requests Per Sec', 'Redo Writes Per Sec' ) AND s.begin_interval_time >= SYSDATE - 1 ) GROUP BY TO_CHAR(begin_interval_time, 'YYYY-MM-DD HH24:MI'), instance_number ORDER BY "Snap Time", instance_number; SPOOL OFF; SPOOL OFF; SET ECHO OFF FEEDBACK OFF PAGES 100 LINES 180 TRIMSPOOL ON SET MARKUP HTML ON SPOOL 62_top_waits_19c.html SELECT inst_id AS "Inst#", event AS "Wait Event", ROUND(time_waited/100, 2) AS "Time (s)", total_waits AS "# Waits", ROUND((time_waited*10)/DECODE(total_waits, 0, 1, total_waits), 2) AS "Avg Wait (ms)", CASE WHEN ROUND((time_waited*10)/DECODE(total_waits, 0, 1, total_waits), 2) > 50 THEN 'CRITICAL' WHEN ROUND((time_waited*10)/DECODE(total_waits, 0, 1, total_waits), 2) > 20 THEN 'WARNING' ELSE 'OK' END AS "Status" FROM ( SELECT e.inst_id, e.event, e.time_waited, e.total_waits, RANK() OVER (PARTITION BY e.inst_id ORDER BY e.time_waited DESC) AS rk FROM gv$system_event e WHERE e.event NOT IN ( SELECT name FROM v$event_name WHERE wait_class = 'Idle' ) ) WHERE rk <= 5 ORDER BY inst_id, "Time (s)" DESC; SPOOL OFF; SET LINESIZE 200 SET PAGESIZE 100 COLUMN inst_id FORMAT 99 COLUMN event FORMAT A50 COLUMN wait_count FORMAT 9999999 SELECT inst_id, event, COUNT(*) AS wait_count FROM gv$active_session_history WHERE sample_time > SYSDATE - 5/1440 AND session_state = 'WAITING' GROUP BY inst_id, event ORDER BY inst_id, wait_count DESC; SET LINESIZE 200 SET PAGESIZE 100 COLUMN snap_time FORMAT A20 COLUMN instance_number FORMAT 99 COLUMN iops FORMAT 999999.99 WITH io_stats AS ( SELECT s.snap_id, s.instance_number, TO_CHAR(s.begin_interval_time, 'YYYY-MM-DD HH24:MI') AS snap_time, MAX(CASE WHEN ss.stat_name = 'physical read IO requests' THEN ss.value END) AS read_io, MAX(CASE WHEN ss.stat_name = 'physical write IO requests' THEN ss.value END) AS write_io, s.begin_interval_time, s.end_interval_time FROM dba_hist_sysstat ss JOIN dba_hist_snapshot s ON ss.snap_id = s.snap_id AND ss.instance_number = s.instance_number WHERE ss.stat_name IN ('physical read IO requests', 'physical write IO requests') AND s.begin_interval_time > SYSDATE - 1 GROUP BY s.snap_id, s.instance_number, s.begin_interval_time, s.end_interval_time ), deltas AS ( SELECT snap_time, instance_number, (read_io + write_io) - LAG(read_io + write_io) OVER (PARTITION BY instance_number ORDER BY begin_interval_time) AS total_io, (CAST(end_interval_time AS DATE) - CAST(begin_interval_time AS DATE)) * 24 * 60 * 60 AS elapsed_seconds FROM io_stats ) SELECT snap_time, instance_number, ROUND(total_io / NULLIF(elapsed_seconds, 0), 2) AS iops FROM deltas WHERE total_io IS NOT NULL ORDER BY snap_time DESC, instance_number; SET LINESIZE 200 SET PAGESIZE 100 COLUMN begin_time FORMAT A20 COLUMN instance_number FORMAT 99 COLUMN db_time_mins FORMAT 999999.99 WITH dbtime_deltas AS ( SELECT s.snap_id, s.instance_number, s.begin_interval_time, s.end_interval_time, tm.value - LAG(tm.value) OVER (PARTITION BY s.instance_number ORDER BY s.snap_id) AS db_time FROM dba_hist_snapshot s JOIN dba_hist_sys_time_model tm ON s.snap_id = tm.snap_id AND s.instance_number = tm.instance_number WHERE tm.stat_name = 'DB time' AND s.begin_interval_time > SYSDATE - 1 ), load_data AS ( SELECT begin_interval_time, instance_number, ROUND(db_time / 1e6, 2) AS db_time_mins FROM dbtime_deltas WHERE db_time IS NOT NULL ) SELECT TO_CHAR(begin_interval_time, 'YYYY-MM-DD HH24:MI') AS begin_time, instance_number, db_time_mins FROM load_data ORDER BY db_time_mins DESC FETCH FIRST 30 ROWS ONLY; SET LINESIZE 200 SET PAGESIZE 100 COLUMN begin_time FORMAT A20 COLUMN instance_number FORMAT 99 COLUMN db_time_mins FORMAT 999999.99 WITH dbtime_deltas AS ( SELECT s.snap_id, s.instance_number, s.begin_interval_time, s.end_interval_time, tm.value - LAG(tm.value) OVER (PARTITION BY s.instance_number ORDER BY s.snap_id) AS db_time FROM dba_hist_snapshot s JOIN dba_hist_sys_time_model tm ON s.snap_id = tm.snap_id AND s.instance_number = tm.instance_number WHERE tm.stat_name = 'DB time' AND s.begin_interval_time > SYSDATE - 1 ), load_data AS ( SELECT begin_interval_time, instance_number, ROUND(db_time / 1e6, 2) AS db_time_mins FROM dbtime_deltas WHERE db_time IS NOT NULL ) SELECT TO_CHAR(begin_interval_time, 'YYYY-MM-DD HH24:MI') AS begin_time, instance_number, db_time_mins FROM load_data ORDER BY db_time_mins DESC FETCH FIRST 30 ROWS ONLY; SET LINESIZE 155 COL dbtime FOR 999,999.99 COL begin_timestamp FOR A40 SELECT * FROM ( SELECT begin_snap, end_snap, begin_timestamp, inst, ROUND(dbtime_microsecs / 1e6 / 60, 2) AS dbtime FROM ( SELECT e.snap_id AS end_snap, LAG(e.snap_id) OVER (PARTITION BY e.instance_number ORDER BY e.snap_id) AS begin_snap, LAG(s.end_interval_time) OVER (PARTITION BY e.instance_number ORDER BY e.snap_id) AS begin_timestamp, s.instance_number AS inst, NVL(e.value - LAG(e.value) OVER (PARTITION BY e.instance_number ORDER BY e.snap_id), 0) AS dbtime_microsecs FROM dba_hist_sys_time_model e JOIN dba_hist_snapshot s ON e.snap_id = s.snap_id AND e.instance_number = s.instance_number WHERE e.stat_name = 'DB time' AND TO_CHAR(e.instance_number) LIKE NVL('&instance_number', TO_CHAR(e.instance_number)) ) WHERE begin_snap BETWEEN NVL('&begin_snap_id', 0) AND NVL('&end_snap_id', 99999999) AND begin_snap = end_snap - 1 ORDER BY dbtime DESC ) WHERE ROWNUM < 31; is_rac() { local db_connect="$1" local result result=$(sqlplus -s "$db_connect" <
Subscribe to:
Posts (Atom)