查看Oracle的表空间使用率

select *
  from (SELECT a.tablespace_name tableSpaceName,
               NVL(a.BYTES / 1024 / 1024,0) totalSize,
               NVL(b.largest / 1024 / 1024,0) freeSize,
               NVL((a.BYTES - b.BYTES) / 1024 / 1024,0) usedSize,
               round(NVL((a.BYTES - b.BYTES) / a.BYTES * 100, 0), 2) usedPercent
          from (SELECT tablespace_name, sum(BYTES) bytes
                  FROM dba_data_files
                 GROUP BY tablespace_name) a,
               (SELECT tablespace_name, sum(BYTES) bytes, max(BYTES) largest
                  FROM dba_free_space
                 GROUP BY tablespace_name) b
         WHERE a.tablespace_name = b.tablespace_name
         ORDER BY a.tablespace_name)

UNION

SELECT d.tablespace_name tableSpaceName,
       NVL(a.BYTES / 1024 / 1024, 0) totalSize,
       NVL(a.BYTES / 1024 / 1024, 0) - NVL(t.BYTES, 0) / 1024 / 1024 freeSize,
       NVL(t.BYTES, 0) / 1024 / 1024 usedSize,
       round(NVL(t.BYTES / a.BYTES * 100, 0), 2) usedPercent
  FROM SYS.dba_tablespaces d,
       (SELECT tablespace_name, SUM(BYTES) BYTES
          FROM dba_temp_files
         GROUP BY tablespace_name) a,
       (SELECT tablespace_name, SUM(bytes_cached) BYTES
          FROM v$temp_extent_pool
         GROUP BY tablespace_name) t
WHERE d.tablespace_name = a.tablespace_name(+)
   AND d.tablespace_name = t.tablespace_name(+)
   AND d.extent_management LIKE 'LOCAL'
   AND d.CONTENTS LIKE 'USERS'


http://zhutong7758.blogbus.com/logs/35080521.html

你可能感兴趣的:(oracle)