oracle monitoring commonly used sql

select * from V$process;

SELECT osuser, username, sql_text
  from v$session a, v$sqltext b
 where a.sql_address = b.address
 order by address, piece;
 
 SELECT (SUM(PINS - RELOADS)) / SUM(PINS) "LIB CACHE" FROM V$LIBRARYCACHE;
 --Detect events and waits in the database
 SELECT event, total_waits, total_timeouts,time_waited, average_wait FROM v$system_event;
 --Query the events and wait times in the session
 select sid, event, total_waits,average_wait from v$session_event;     
 --Query waiting process
 SELECT sid, seq#, event, wait_time, state FROM v$session_wait;
--current sql statement
select sql_text, users_executing, executions, loads from v$sqlarea;
-- view table lock
select * from sys.v_$sqlarea where disk_reads>100


--View the SQL statement being issued in the foreground
select user_name, sql_text   
  from v$open_cursor   
 where sid in (select sid
                 from (select sid, serial#, username, program   
                         from v$session   
                        where status = 'ACTIVE'))
                        
                        
--The size of the space occupied by the data table
select segment_name, tablespace_name, bytes, blocks
  from user_segments
 where segment_type = 'TABLE'
 ORDER BY bytes DESC, blocks DESC
--View tablespace fragment size
select tablespace_name,
       round(sqrt(max(blocks) / sum(blocks)) *
             (100 / sqrt(sqrt(count(blocks)))),
             2) FSFI
  from dba_free_space
 group by tablespace_name
 order by 1


--View session using rollback segment
SELECT r.name rollback segment name,
        s.sid,
        s.serial#,
        s.username username,
        t.status,
        t.cr_get,
        t.phy_io,
        t.used_ublk,
        t.noundo,
        substr(s.program, 1, 78) operation program
FROM   sys.v_$session s,sys.v_$transaction t,sys.v_$rollname r
WHERE  t.addr = s.taddr and t.xidusn = r.usn
ORDER  BY t.cr_get,t.phy_io


--View the remaining available memory in the SGA area
select name,
      sgasize/1024/1024        "Allocated(M)",
      bytes/1024 "**Space(K)",
      round(bytes/sgasize*100, 2) "**Space percentage(%)"
   from   (select sum(bytes) sgasize from sys.v_$sgastat) s, sys.v_$sgastat f
   where  f.name = 'free memory'    


-- worst performing SQL

SELECT * FROM ( SELECT PARSING_USER_ID EXECUTIONS,SORTS,COMMAND_TYPE,DISK_READS,sql_text
                FROM v$sqlarea
                ORDER BY disk_reads DESC)
WHERE ROWNUM<100

-- sql with more than 100 disk reads

select * from sys.v_$sqlarea where disk_reads>100

--The most frequently executed sql

select * from sys.v_$sqlarea where executions>100


--Query user sessions that use more CPU

select a.sid,spid,status,substr(a.program,1,40) prog,a.terminal,osuser,value/60/100 value
from v$session a,v$process b,v$sesstat c
where c.statistic#=12 and
      c.sid=a.sid and
      a.paddr=b.addr
order by value desc


-- Current number of objects used per session
SELECT a.sid,s.terminal,s.program,count(a.sid)
FROM V$ACCESS a,V$SESSION s
WHERE a.owner <> 'SYS'AND s.sid = a.sid
GROUP BY a.sid,s.terminal,s.program
ORDER BY count(a.sid)


select sid,v$session.username username,last_call_et duration,status status,LOCKWAIT waiting for lock,machine user computer name,logon_time start login time,sql_text from v$session ,v$process ,v$sqlarea
  where paddr=addr and sql_hash_value=hash_value  
  and status='ACTIVE' and v$session.username is not null
  order by last_call_et desc;
  
  
  
  SELECT 'alter system kill session ''' || sid || ',' || serial# || ''';' "Deadlock"
  FROM v$session
 WHERE sid IN (SELECT sid FROM v$lock WHERE block = 1);
 
 
 SELECT LPAD(' ', DECODE(l.xidusn, 0, 3, 0)) || l.oracle_username User_name,
       o.owner,
       o.object_name,
       o.object_type,
       s.sid,
       s.serial#
  FROM v$locked_object l, dba_objects o, v$session s
 WHERE l.object_id = o.object_id
   AND l.session_id = s.sid
 ORDER BY o.object_id, xidusn DESC;
 
 
select object_name as object name,s.sid,s.serial#,p.spid as system process number
from v$locked_object l , dba_objects o , v$session s , v$process p
where l.object_id=o.object_id and l.session_id=s.sid and s.paddr=p.addr;

select name, waits, gets, waits / gets "Ratio"
  from v$rollstat a, v$rollname b
 where a.usn = b.usn;
 
--View tablespace usage
SELECT SUM(bytes) / (1024 * 1024) AS free_space, tablespace_name
FROM dba_free_space
GROUP BY tablespace_name;
SELECT a.tablespace_name,
a.bytes total,
b.bytes used,
c.bytes free,
(b.bytes * 100) / a.bytes "% USED ",
(c.bytes * 100) / a.bytes "% FREE "
FROM sys.sm$ts_avail a, sys.sm$ts_used b, sys.sm$ts_free c
WHERE a.tablespace_name = b.tablespace_name
AND a.tablespace_name = c.tablespace_name;

--Query log status
SELECT created, log_mode, log_mode FROM v$database;


SELECT owner, object_type, status, COUNT(*) count#
FROM all_objects
GROUP BY owner, object_type, status;
--View tablespace usage
SELECT a.tablespace_name "tablespace name",
total "tablespace size",
free "table space remaining size",
(total - free) "Tablespace usage size",
total / (1024 * 1024 * 1024) "Table space size (G)",
free / (1024 * 1024 * 1024) "Remaining size of table space (G)",
(total - free) / (1024 * 1024 * 1024) "Table space usage size (G)",
round((total - free) / total, 4) * 100 "Usage %"
FROM (SELECT tablespace_name, SUM(bytes) free
FROM dba_free_space
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) total
FROM dba_data_files
GROUP BY tablespace_name) b
WHERE a.tablespace_name = b.tablespace_name


select event,
       sum(decode(wait_Time, 0, 0, 1)) "Prev",
       sum(decode(wait_Time, 0, 1, 0)) "Curr",
       count(*) "Tot"
  from v$session_Wait
 group by event
 order by 4;      
 
 
 
 select a.hladdr, a.file#, a.dbablk, a.tch, a.obj, b.object_name
from x$bh a, dba_objects b
where (a.obj = b.object_id or a.obj = b.data_object_id)
and a.hladdr = &2
union
select hladdr, file#, dbablk, tch, obj, null
from x$bh
where obj in
(select obj from x$bh
where hladdr = &2
minus
select object_id from dba_objects
minus
select data_object_id from dba_objects)
and hladdr = &2
order by 4;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326282639&siteId=291194637