Verificar espaço Livre Tablespace

set colsep   " | "
set linesize 100
set pagesize 500
select          
                a.tablespace_name,
                round(SUM(a.bytes)/(1024*1024*1024)) CURRENT_GB,
                round(SUM(decode(b.maxextend, null, A.BYTES/(1024*1024*1024), 
                b.maxextend*8192/(1024*1024*1024)))) MAX_GB,
                (SUM(a.bytes)/(1024*1024*1024) - round(c.Free/1024/1024/1024)) USED_GB,
                round((SUM(decode(b.maxextend, null, A.BYTES/(1024*1024*1024), 
                b.maxextend*8192/(1024*1024*1024))) - (SUM(a.bytes)/(1024*1024*1024) - 
                round(c.Free/1024/1024/1024))),2) FREE_GB,
                round(100*(SUM(a.bytes)/(1024*1024*1024) - 
                round(c.Free/1024/1024/1024))/(SUM(decode(b.maxextend, null, A.BYTES/(1024*1024*1024), 
                b.maxextend*8192/(1024*1024*1024))))) USED_PCT
from
                dba_data_files a,
                sys.filext$ b,
                (SELECT
                               d.tablespace_name ,sum(nvl(c.bytes,0)) Free
                FROM
                               dba_tablespaces d,
                               DBA_FREE_SPACE c
                WHERE
                               d.tablespace_name = c.tablespace_name(+)
                               group by d.tablespace_name) c
WHERE
                a.file_id = b.file#(+)
                and a.tablespace_name = c.tablespace_name
GROUP BY a.tablespace_name, c.Free/1024
ORDER BY tablespace_name;
/

-- OR 
set colsep   " | "
set linesize 100
set pagesize 500
SELECT      
                A.TABLESPACE_NAME,
                CAST(ROUND(SUM(A.BYTES)/(1024*1024*1024)) AS NUMBER(6,2)) CURRENT_GB,
                CAST(ROUND(SUM(DECODE(B.MAXEXTEND, NULL, A.BYTES/(1024*1024*1024), 
                B.MAXEXTEND*8192/(1024*1024*1024)))) AS NUMBER(6,2)) MAX_GB,
                CAST((SUM(A.BYTES)/(1024*1024*1024) - ROUND(C.FREE/1024/1024/1024)) AS NUMBER(6,2)) USED_GB,
                CAST(ROUND((SUM(DECODE(B.MAXEXTEND, NULL, A.BYTES/(1024*1024*1024), 
                B.MAXEXTEND*8192/(1024*1024*1024))) - (SUM(A.BYTES)/(1024*1024*1024) - 
                ROUND(C.FREE/1024/1024/1024))),2) AS NUMBER(6,2)) FREE_GB,
                round(100*(SUM(a.bytes)/(1024*1024*1024) - 
                round(c.Free/1024/1024/1024))/(SUM(decode(b.maxextend, null, A.BYTES/(1024*1024*1024), 
                b.maxextend*8192/(1024*1024*1024))))) USED_PCT
FROM
                DBA_DATA_FILES A,
                SYS.FILEXT$ B,
                (SELECT
                               D.TABLESPACE_NAME ,SUM(NVL(C.BYTES,0)) FREE
                FROM
                               DBA_TABLESPACES D,
                               DBA_FREE_SPACE C
                WHERE
                               D.TABLESPACE_NAME = C.TABLESPACE_NAME(+)
                               GROUP BY D.TABLESPACE_NAME) C,
                DBA_TABLESPACE_USAGE_METRICS USG
WHERE
                A.FILE_ID = B.FILE#(+)
                AND A.TABLESPACE_NAME = C.TABLESPACE_NAME
                AND USG.TABLESPACE_NAME = C.TABLESPACE_NAME
GROUP BY A.TABLESPACE_NAME, C.FREE/1024, USG.USED_PERCENT
UNION ALL
SELECT SP.TABLESPACE_NAME,  
CAST(SP.TABLESPACE_SIZE/1024/1024/1024 AS NUMBER(6,2)) CURRENT_GB , 
CAST(SP.ALLOCATED_SPACE/1024/1024/1024 AS NUMBER(6,2)) MAX_GB,
CAST((SP.ALLOCATED_SPACE/1024/1024/1024)- SP.TABLESPACE_SIZE/1024/1024/1024 AS NUMBER(6,2)) USED_GB,
CAST(SP.FREE_SPACE/1024/1024/1024 AS NUMBER(6,2)) FREE_GB,
CAST(MT.USED_PERCENT AS NUMBER(6,2)) USED_PCT
FROM DBA_TEMP_FREE_SPACE SP
INNER JOIN DBA_TABLESPACE_USAGE_METRICS MT
ON MT.TABLESPACE_NAME = SP.TABLESPACE_NAME
ORDER BY USED_PCT DESC;
SQL

Leave a Reply

Your email address will not be published. Required fields are marked *

search previous next tag category expand menu location phone mail time cart zoom edit close