`
peijunlin2008
  • 浏览: 170760 次
  • 性别: Icon_minigender_1
  • 来自: 河北省
社区版块
存档分类
最新评论

有用的数据分析SQL

阅读更多
--耗资源的进程(top session)
select   s.schemaname schema_name,decode(sign(48 - command), 1, 
       to_char(command), 'Action Code #' || to_char(command) ) action,  
        status session_status,  s.osuser os_user_name,  s.sid,    
         p.spid ,s.serial# serial_num, nvl(s.username, '[Oracle process]') user_name, 
     s.terminal terminal,s.program program,  st.value criteria_value 
from    v$sesstat st,  v$session s , v$process p  
   where st.sid = s.sid and  st.statistic# = to_number('38')
           and  ('ALL' = 'ALL' or s.status = 'ALL')
           and p.addr = s.paddr order by st.value desc, 
           p.spid asc, s.username asc, s.osuser asc ;
--查看有哪些用户连接
  select s.osuser os_user_name,  decode(sign(48 - command), 1,
           to_char(command),  'Action Code #' || to_char(command) ) action,
         p.program oracle_process,status session_status,  
          s.terminal terminal,  s.program program,
          s.username user_name,  s.fixed_table_sequence activity_meter, 
          s.sid,  s.serial# serial_num  
  from   v$session s,  v$process p 
    where
         s.paddr=p.addr and  s.type = 'USER' 
  order by s.username, s.osuser;

--根据v.sid查看对应连接的资源占用等情况
select n.name, 
  v.value, 
  n.class,
  n.statistic# 
  from v$statname n, 
  v$sesstat v 
  where v.sid = 207 and 
  v.statistic# = n.statistic# 
  order by n.class, n.statistic#;
--根据sid查看对应连接正在运行的sql
select /*+ PUSH_SUBQ */
  command_type, 
  sql_text, 
  sharable_mem, 
  persistent_mem, 
  runtime_mem, 
  sorts, 
  version_count, 
  loaded_versions, 
  open_versions, 
  users_opening, 
  executions, 
  users_executing, 
  loads, 
  first_load_time, 
  invalidations, 
  parse_calls, 
  disk_reads, 
  buffer_gets, 
  rows_processed,
  sysdate start_time,
  sysdate finish_time,
  '>' || address sql_address,
  'N' status 
 from v$sqlarea
  where address = (select sql_address from v$session where sid = 207) ;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics