隨筆 - 0, 文章 - 264, 評論 - 170, 引用 - 0
          數據加載中……

          oracle下監控session、表空間性能數據

          ORACLE下監控SESSION、表空間性能數據,需要以DBA身份,取得一些系統視圖的信息。
          建立兩個表,
          viva_session表,包含字段id(序列遞增),createdate(默認系統時間sysdate),inactiveCount(不活躍會話數),activeCount(活躍會話數)。
          viva_tablespace表,包含字段字段id(序列遞增),createdatet(默認系統時間sysdate),tablespace_name(表空間名稱),total_mb(總大小),used_mb(已使用的大小),used_pct(已使用的比例)。
          1、SESSON數據的取得,代碼:
          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、表空間數據的取得,代碼:
          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) 評論(0)  編輯  收藏 所屬分類: 數據庫(oracle、mysql、sql server等)相關

          主站蜘蛛池模板: 天峻县| 行唐县| 台州市| 姚安县| 高邮市| 青河县| 清河县| 黑龙江省| 大田县| 从江县| 宁明县| 潼关县| 漾濞| 洛川县| 靖西县| 洪江市| 台安县| 博客| 海口市| 江阴市| 宁武县| 北川| 东丰县| 灵台县| 周宁县| 崇州市| 葫芦岛市| 旬邑县| 闸北区| 肇庆市| 小金县| 香港| 邯郸市| 荆门市| 绵竹市| 忻城县| 利辛县| 安吉县| 义乌市| 广宗县| 江华|