• oracle 查看表空间使用率


    2017-06-14

    Oracle 表空间使用率

    -- 表空间使用率1:DBA_DATA_FILES、DBA_SEGMENTS
    SELECT tablespace_name,
           ROUND(a.total_bytes / 1024 / 1024 / 1024, 0) || 'G' as TOTAL,
           ROUND((a.total_bytes - DECODE(b.used_bytes, null, 0, b.used_bytes)) / 1024 / 1024 / 1024,
                 0) || 'G' as FREE,
           ROUND(DECODE(b.used_bytes, null, 0, b.used_bytes) / 1024 / 1024 / 1024,
                 0) || 'G' as USED,
           ROUND(DECODE(b.used_bytes, null, 0, b.used_bytes) / a.total_bytes, 4) * 100 as "USED_RATIO(%)"
      FROM (SELECT tablespace_name,
                   sum(DECODE(autoextensible, 'YES', maxbytes, 'NO', bytes)) as total_bytes
              FROM DBA_DATA_FILES
             GROUP BY tablespace_name) a
      LEFT JOIN (SELECT tablespace_name, sum(bytes) as used_bytes
                   FROM DBA_SEGMENTS
                  GROUP BY tablespace_name) b
     USING (tablespace_name)
     ORDER BY 5 DESC;

    -- 表空间使用率2:DBA_DATA_FILES、DBA_EXTENTS
    SELECT tablespace_name,
           ROUND(a.total_bytes / 1024 / 1024 / 1024, 0) || 'G' as total,
           ROUND((a.total_bytes - DECODE(b.used_bytes, null, 0, b.used_bytes)) / 1024 / 1024 / 1024,
                 0) || 'G' as free,
           ROUND(DECODE(b.used_bytes, null, 0, b.used_bytes) / 1024 / 1024 / 1024,
                 0) || 'G' as used,
           ROUND(DECODE(b.used_bytes, null, 0, b.used_bytes) / a.total_bytes, 4) * 100 as "USED_RATIO(%)"
      FROM (SELECT tablespace_name,
                   sum(DECODE(autoextensible, 'YES', maxbytes, 'NO', bytes)) as total_bytes
              FROM DBA_DATA_FILES
             GROUP BY tablespace_name) a
      LEFT JOIN (SELECT tablespace_name, sum(bytes) as used_bytes
                   FROM DBA_EXTENTS
                  GROUP BY tablespace_name) b
     USING (tablespace_name)
     ORDER BY 5 DESC;

    -- 表空间使用率3:DBA_DATA_FILES、DBA_FREE_SPACE
    SELECT tablespace_name,
           ROUND(a.total_bytes / 1024 / 1024 / 1024, 0) || 'G' as total,
           ROUND(DECODE(b.free_bytes, null, 0, b.free_bytes) / 1024 / 1024 / 1024,
                 0) || 'G' as free,
           ROUND((a.total_bytes - DECODE(b.free_bytes, null, 0, b.free_bytes)) / 1024 / 1024 / 1024,
                 0) || 'G' as used,
           ROUND((a.total_bytes - DECODE(b.free_bytes, null, 0, b.free_bytes)) /
                 a.total_bytes,
                 4) * 100 as "USED_RATIO(%)"
      FROM (SELECT tablespace_name,
                   sum(DECODE(autoextensible, 'YES', maxbytes, 'NO', bytes)) as total_bytes
              FROM DBA_DATA_FILES
             GROUP BY tablespace_name) a
      LEFT JOIN (SELECT tablespace_name, sum(bytes) as free_bytes
                   FROM DBA_FREE_SPACE
                  GROUP BY tablespace_name) b
     USING (tablespace_name)
     ORDER BY 5 DESC;

    参考资料

    [1] Oracle查询表空间使用情况

    [2] Oracle 查看表空间的大小及使用情况sql语句

  • 相关阅读:
    正则表达式的先行断言(lookahead)和后行断言(lookbehind)
    正则表达式里的捕获组
    JavaScript高级程序设计8.pdf
    JavaScript高级程序设计7.pdf
    JavaScript高级程序设计6.pdf
    JavaScript高级程序设计5.pdf
    JavaScript高级程序设计4.pdf
    产品思维|腾讯工作心得:原型该画到什么程度?
    提名推荐!15个2019年最佳CSS框架
    腾讯工作心得:原型该画到什么程度?
  • 原文地址:https://www.cnblogs.com/cenliang/p/4952410.html
Copyright © 2020-2023  润新知