Oracle 运维常用SQL

1.查询表空间增长率  

SELECT A.NAME, B.TABLESPACE_ID,B.DATETIME,B.USED_SIZE_MB,B.INC_MB,  
         CASE WHEN SUBSTR(INC_RATE,1,1)='.' THEN '0'||INC_RATE  
              WHEN SUBSTR(INC_RATE,1,2)='-.' THEN '-0'||SUBSTR(INC_RATE,2,LENGTH(INC_RATE))    
              ELSE INC_RATE  
         END AS INC_RATEX  
    FROM V$TABLESPACE A,   
         (  
             SELECT TABLESPACE_ID,DATETIME,  
                    USED_SIZE_MB,    
                   (DECODE(PREV_USE_MB,0,0,USED_SIZE_MB)-PREV_USE_MB) AS  INC_MB,   
                   TO_CHAR(ROUND((DECODE(PREV_USE_MB,0,0,USED_SIZE_MB)-PREV_USE_MB)/DECODE(PREV_USE_MB,0,1,PREV_USE_MB)*100,2))||'%' AS INC_RATE  
         FROM  
          (  
            SELECT TABLESPACE_ID,   
                   TRUNC(TO_DATE(RTIME, 'mm/dd/yyyy hh24:mi:ss')) DATETIME,   
                   MAX(TABLESPACE_USEDSIZE * 8 / 1024) USED_SIZE_MB,  
                   LAG(MAX(TABLESPACE_USEDSIZE * 8 / 1024),1,0) OVER(PARTITION BY TABLESPACE_ID ORDER BY TRUNC(TO_DATE(RTIME, 'mm/dd/yyyy hh24:mi:ss')) ) AS PREV_USE_MB  
              FROM DBA_HIST_TBSPC_SPACE_USAGE  
             WHERE TRUNC(TO_DATE(RTIME, 'mm/dd/yyyy hh24:mi:ss')) > TRUNC(SYSDATE - 30)  
             GROUP BY TABLESPACE_ID, T

你可能感兴趣的:(Oracle日常管理)