qileilove

          blog已經(jīng)轉(zhuǎn)移至github,大家請訪問 http://qaseven.github.io/

          腳本:監(jiān)控數(shù)據(jù)庫中的活躍用戶及其運行的SQL

          set linesize 120 pagesize 66
          col c1 for a9
          col c1 heading "OS User"
          col c2 for a9
          col c2 heading "Oracle User"
          col b1 for a9
          col b1 heading "Unix PID"
          col b2 for 9999 justify left
          col b2 heading "SID"
          col b3 for 99999 justify left
          col b3 heading "SERIAL#"
          col sql_text for a35
          col event  for a30
          break on b1 nodup on c1 nodup on c2 nodup on b2 nodup on b3 skip 3
          select c.spid     b1,
          b.osuser   c1,
          b.username c2,
          b.sid      b2,
          b.serial#  b3,
          b.event,
          a.sql_text
          from v$sqltext a, v$session b, v$process c
          where a.address = b.sql_address
          --   and b.status     = 'ACTIVE' /* YOU CAN CHOOSE THIS OPTION ONLY TO SEE
          --                                  ACTVE TRANSACTION ON THAT MOMENT */
          and b.paddr = c.addr
          and a.hash_value = b.sql_hash_value
          order by c.spid, a.hash_value, a.piece
          /
          REM TOP SESSION
          with sessions as
          (select /*+ materialize */
          sess.inst_id,
          sess.sid,
          sess.serial#,
          sess.username,
          sess.module,
          sess.program,
          stat.value cpu_used_by_this_session,
          i.physical_reads,
          i.block_gets,
          sess.command,
          sess.status,
          sess.lockwait,
          decode(sess.sql_hash_value, 0, sess.prev_hash_value, sess.sql_hash_value) sql_hash_value,
          decode(sess.sql_address, '00', sess.prev_sql_addr, sess.sql_address) sql_address
          from gv$sesstat stat, gv$session sess, gv$sess_io i
          where stat.statistic# =
          (select statistic#
          from v$statname
          where name = 'CPU used by this session')
          and stat.sid = sess.sid
          and stat.inst_id = sess.inst_id
          and (stat.value > 100 or i.physical_reads > 100 or i.block_gets > 100)
          and sess.username is not null
          and i.sid = sess.sid
          and i.inst_id = sess.inst_id),
          sqlarea as
          (select inst_id, sql_fulltext sql_text, hash_value, address from gv$sqlarea)
          select *
          from sessions, sqlarea
          where sessions.inst_id = sqlarea.inst_id and sessions.sql_hash_value = sqlarea.hash_value and sessions.sql_address = sqlarea.address
          order by cpu_used_by_this_session desc

          posted on 2014-01-13 10:55 順其自然EVO 閱讀(221) 評論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫

          <2014年1月>
          2930311234
          567891011
          12131415161718
          19202122232425
          2627282930311
          2345678

          導航

          統(tǒng)計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 阿瓦提县| 利津县| 常州市| 临朐县| 股票| 巴南区| 浦江县| 阆中市| 庆安县| 长寿区| 花莲市| 玛纳斯县| 葵青区| 寿阳县| 二手房| 顺平县| 安国市| 红河县| 清远市| 孝感市| 增城市| 六安市| 江华| 民丰县| 马山县| 屏南县| 察隅县| 永嘉县| 外汇| 定远县| 醴陵市| 图片| 永修县| 大渡口区| 上犹县| 县级市| 温泉县| 阿拉善盟| 大丰市| 峡江县| 进贤县|