隨筆 - 0, 文章 - 264, 評(píng)論 - 170, 引用 - 0
          數(shù)據(jù)加載中……

          oracle下監(jiān)控session、表空間性能數(shù)據(jù)

          ORACLE下監(jiān)控SESSION、表空間性能數(shù)據(jù),需要以DBA身份,取得一些系統(tǒng)視圖的信息。
          建立兩個(gè)表,
          viva_session表,包含字段id(序列遞增),createdate(默認(rèn)系統(tǒng)時(shí)間sysdate),inactiveCount(不活躍會(huì)話數(shù)),activeCount(活躍會(huì)話數(shù))。
          viva_tablespace表,包含字段字段id(序列遞增),createdatet(默認(rèn)系統(tǒng)時(shí)間sysdate),tablespace_name(表空間名稱),total_mb(總大小),used_mb(已使用的大小),used_pct(已使用的比例)。
          1、SESSON數(shù)據(jù)的取得,代碼:
          create or replace procedure viva_session_proc is
          begin
          DECLARE
            inactiveCount NUMBER;
            activeCount NUMBER;
          begin
            select count(
          *) into inactiveCount from v$session where status='INACTIVE';
            select count(
          *) into activeCount from v$session where status='ACTIVE';
            insert into pmsuser.viva_session(inactive,active)
            values(inactiveCount,activeCount);
          end;
          end viva_session_proc;
          2、表空間數(shù)據(jù)的取得,代碼:
          create or replace procedure viva_tablespace_proc is
          begin
            insert into pmsuser.viva_tablespace(tablespace_name,total_mb,used_mb,used_pct)
            select 
            total.tablespace_name,
            round(total.MB, 
          2) as Total_MB,round(total.MB - free.MB, 2) as Used_MB,
          round((
          1 - free.MB / total.MB) * 1002|| '%' as Used_Pct
          from (select tablespace_name, sum(bytes) 
          / 1024 / 1024 as MB
          from dba_free_space
          group by tablespace_name) free,
          (select tablespace_name, sum(bytes) 
          / 1024 / 1024 as MB
          from dba_data_files
          group by tablespace_name) total
          where free.tablespace_name 
          = total.tablespace_name;

          end viva_tablespace_proc;


          posted on 2010-11-05 15:22 小一敗涂地 閱讀(1013) 評(píng)論(0)  編輯  收藏 所屬分類: 數(shù)據(jù)庫(kù)(oracle、mysql、sql server等)相關(guān)

          主站蜘蛛池模板: 田阳县| 唐海县| 台东县| 屏东县| 益阳市| 拉萨市| 南通市| 娄底市| 株洲市| 红原县| 定陶县| 九江县| 林州市| 黄石市| 长汀县| 闵行区| 昭通市| 安龙县| 博客| 江津市| 延寿县| 凤山市| 永嘉县| 十堰市| 克拉玛依市| 合作市| 拉孜县| 肥城市| 墨脱县| 和林格尔县| 长宁县| 延边| 邹城市| 罗山县| 莱芜市| 德州市| 合肥市| 濮阳市| 托克托县| 汪清县| 海淀区|