General Queries
Tablespace growth Size
SELECT tbm.TABLESPACE_NAME, round(tbm.USED_SPACE * tb.BLOCK_SIZE /(1024*1024*1024),2) as USED_SPACE_GB, round(tbm.TABLESPACE_SIZE * tb.BLOCK_SIZE /(1024*1024*1024),2) as TBS_SIZE_GB, round((tbm.TABLESPACE_SIZE - tbm.USED_SPACE) * tb.BLOCK_SIZE /(1024*1024*1024),2) as TBS_FREE_SIZE_GB, round(tbm.USED_PERCENT) as PERCENT_USEDFROM dba_tablespace_usage_metrics tbm join dba_tablespaces tb on tb.TABLESPACE_NAME = tbm.TABLESPACE_NAME where round(tbm.USED_PERCENT) > 80;";
SQL monitoring
select inst_id,status,round(elapsed_time/1000000,2) as duration_secs,sql_id,sql_plan_hash_value,username,
px_maxdop as degree_of_parallelism, px_maxdop_instances as instances_used,
px_is_cross_instance as cross_instance,user_io_wait_time,cluster_wait_time,
concurrency_wait_time,round(cpu_time/1000000,2),queuing_time,PHYSICAL_READ_REQUESTS,
PHYSICAL_READ_BYTES,PHYSICAL_WRITE_REQUESTS,PHYSICAL_WRITE_BYTES,
to_char(SQL_EXEC_START,'HH24:MI:SS'),to_char(LAST_REFRESH_TIME,'HH24:MI:SS'),sql_text from gv$sql_monitor where status='EXECUTING';
select inst_id,status,round(elapsed_time/1000000,2) as duration_secs,sql_id,sql_plan_hash_value,username,
px_maxdop as degree_of_parallelism, px_maxdop_instances as instances_used,
px_is_cross_instance as cross_instance,user_io_wait_time,cluster_wait_time,
concurrency_wait_time,round(cpu_time/1000000,2),queuing_time,PHYSICAL_READ_REQUESTS,
PHYSICAL_READ_BYTES,PHYSICAL_WRITE_REQUESTS,PHYSICAL_WRITE_BYTES,
to_char(SQL_EXEC_START,'HH24:MI:SS'),to_char(LAST_REFRESH_TIME,'HH24:MI:SS'),sql_text from gv$sql_monitor where status='EXECUTING';
SQL_ID from sqltext
select sql_id,sql_text from DBA_HIST_SQLTEXT where sql_text like '<query partial string>';
Datapump Jobs
select owner_name,job_name,operation,job_mode,state,degree,attached_sessions, datapump_sessions from dba_datapump_jobs where state like '%RUNNING%';
DB Scheduler Jobs Status
select log_id, owner,job_name, status,run_duration, additional_info,log_date from dba_scheduler_job_run_details where status != 'SUCCEEDED' and log_date >= sysdate-1;
Standby Lag Status
SELECT SUM(DECODE(name, 'apply finish time', value, 0)) as Apply_Time, SUM(DECODE(name, 'apply lag', value, 0)) as Apply_LAG, SUM(DECODE(name, 'transport lag', value, 0)) as Transport_LAG from (SELECT name, extract(day from p.val) *86400 + extract(hour from p.val) *3600 + extract(minute from p.val) *60 + extract(second from p.val) value from (SELECT name,to_dsinterval(value) val from v$dataguard_stats) p );
RMAN Backup Status
select to_char(start_time,'dd-mm-yyyy hh24:mi:ss') as start_time, to_char(end_time,'dd-mm-yyyy_hh24:mi:ss') as end_time, status, round(mbytes_processed/1024, 2) as GB_processed,object_type,operation,row_type,sid from v$rman_status where start_time >= sysdate-1 order by start_time desc;
Blocking Sessions
SELECT inst_id, blocking_session, sid, serial#, seconds_in_wait FROM gv$session WHERE blocking_session IS NOT NULL and seconds_in_wait > 60 ;
NON-RAC / Cloud RDS:
SELECT blocking_session, sid, serial#, seconds_in_wait FROM v$session WHERE blocking_session IS NOT NULL and seconds_in_wait > 60 ;
Long Running Queries
FROM gV$SESSION_LONGOPS sl, gv$session s, gv$sql sq
WHERE sl.sid=s.sid and s.sql_id=sq.sql_id and
TOTALWORK != 0
AND SOFAR != TOTALWORK
order by 1;
FROM V$SESSION_LONGOPS sl, v$session s, v$sql sq
WHERE sl.sid=s.sid and s.sql_id=sq.sql_id and
TOTALWORK != 0
AND SOFAR != TOTALWORK
order by 1;
Long Running Sessions
select * from (select inst_id,sid,serial#,username,trunc(last_call_et/3600,2)||' hr' as last_call_et,sql_id,status,machine,osuser,logon_time from gv$session where last_call_et > 900 and username not like '%SYS%' and sql_id is not null) ;
NON-RAC / Cloud RDS: sessions running more than 15 minutes.
select * from (select sid,serial#,username,trunc(last_call_et/3600,2)||' hr' as last_call_et,sql_id,status,machine,osuser,logon_time from v$session where last_call_et > 900 and username not like '%SYS%' and sql_id is not null) ;
Locked Tables
SELECT s.inst_id,d.OBJECT_ID, object_name, l.SESSION_ID,s.last_call_et, l.ORACLE_USERNAME, l.LOCKED_MODE from gv$locked_object l, dba_objects d, gv$session s where d.OBJECT_ID=l.OBJECT_ID and s.sid=l.SESSION_ID and s.last_call_et > 300 ;
SELECT d.OBJECT_ID, object_name, l.SESSION_ID,s.last_call_et, l.ORACLE_USERNAME, l.LOCKED_MODE from v$locked_object l, dba_objects d, v$session s where d.OBJECT_ID=l.OBJECT_ID and s.sid=l.SESSION_ID and s.last_call_et > 300 ;
Live Transactions
SELECT s.inst_id,l.ORACLE_USERNAME,object_name, l.SESSION_ID,s.last_call_et, l.LOCKED_MODE,t.xidusn, t.used_urec, t.used_ublk,s.saddr, t.ses_addr from gv$locked_object l, dba_objects d, gv$session s, gv$transaction t where d.OBJECT_ID=l.OBJECT_ID and s.sid=l.SESSION_ID and s.last_call_et > 300 and s.saddr = t.ses_addr;
SELECT l.ORACLE_USERNAME,object_name, l.SESSION_ID,s.last_call_et, l.LOCKED_MODE,t.xidusn, t.used_urec, t.used_ublk,s.saddr, t.ses_addr from v$locked_object l, dba_objects d, v$session s, v$transaction t where d.OBJECT_ID=l.OBJECT_ID and s.sid=l.SESSION_ID and s.last_call_et > 300 and s.saddr = t.ses_addr;
Temp Usage
select inst_id, tablespace_name, total_blocks, used_blocks, free_blocks from gv$sort_segment where free_blocks <=0;
NON-RAC / Cloud RDS:
select inst_id, tablespace_name, total_blocks, used_blocks, free_blocks from v$sort_segment where free_blocks <=0;
CPU Sessions usage
select * from (select * from
(
select username,sid,
round((cpu_usage/(
select sum(value) total_cpu_usage
from gv$sesstat t
inner join gv$session s on ( t.sid = s.sid )
inner join gv$statname n on ( t.statistic# = n.statistic# )
where n.name like '%CPU used by this session%'
and nvl(s.sql_exec_start, s.prev_exec_start) >= sysdate-1/24
))*100/16,2) cpu_usage_per_cent,
module_info,client_info,sql_id
from
(
select nvl(s.username,'Oracle Internal Proc.') username,s.sid,s.sql_id,t.value cpu_usage, nvl(s.module, s.program) module_info, decode(s.osuser,'oracle', s.client_info, s.osuser) client_info
from gv$sesstat t
inner join gv$session s on ( t.sid = s.sid )
inner join gv$statname n on ( t.statistic# = n.statistic# )
where n.name like '%CPU used by this session%'
and nvl(s.sql_exec_start, s.prev_exec_start) >= sysdate-1/24
) s1
)
order by cpu_usage_per_cent desc) where rownum < 10;
NON-RAC / Cloud RDS: Top 10 sessions from last 1 hour cpu usage
select * from (select * from
(
select username,sid,
round((cpu_usage/(
select sum(value) total_cpu_usage
from v$sesstat t
inner join v$session s on ( t.sid = s.sid )
inner join v$statname n on ( t.statistic# = n.statistic# )
where n.name like '%CPU used by this session%'
and nvl(s.sql_exec_start, s.prev_exec_start) >= sysdate-1/24
))*100/16,2) cpu_usage_per_cent,
module_info,client_info,sql_id
from
(
select nvl(s.username,'Oracle Internal Proc.') username,s.sid,s.sql_id,t.value cpu_usage, nvl(s.module, s.program) module_info, decode(s.osuser,'oracle', s.client_info, s.osuser) client_info
from v$sesstat t
inner join v$session s on ( t.sid = s.sid )
inner join v$statname n on ( t.statistic# = n.statistic# )
where n.name like '%CPU used by this session%'
and nvl(s.sql_exec_start, s.prev_exec_start) >= sysdate-1/24
) s1
)
order by cpu_usage_per_cent desc) where rownum < 10;
Alert Log view
FROM TABLE (
gv$ (
CURSOR (
SELECT inst_id, originating_timestamp, message_text
FROM v$diag_alert_ext
WHERE originating_timestamp > (sysdate- 1)
AND message_text like '%ORA-%')))
ORDER BY inst_id, originating_timestamp;
select inst_id,to_char(originating_timestamp) as originating_timestamp,message_text,host_address,to_char(normalized_timestamp) as normalized_timestamp from v$diag_alert_ext where message_text like '%ORA-%' and originating_timestamp > sysdate-1/24 order by originating_timestamp desc;
Comments
Post a Comment