ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 脚本一 表空间利用率

脚本一 表空间利用率

原创 Linux操作系统 作者:treesofthehill 时间:2013-01-11 17:11:00 0 删除 编辑
SELECT d.status "Status",
d.tablespace_name "Name",
d.contents "Type",
d.extent_management "Extent Management",
to_char(nvl(a.bytes / 1024 / 1024, 0), '99,999,990.900') "Size (M)",
to_char(nvl(a.bytes - nvl(f.bytes, 0), 0) / 1024 / 1024,'99999999.999') || '/' ||
to_char(nvl(a.bytes / 1024 / 1024, 0), '99999999.999') "Used (M)",
to_char(nvl((a.bytes - nvl(f.bytes, 0)) / a.bytes * 100, 0),'990.00') "Used %"
FROM sys.dba_tablespaces d,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_data_files
GROUP BY tablespace_name) a,
(SELECT tablespace_name, SUM(bytes) bytes
FROM dba_free_space
GROUP BY tablespace_name) f
WHERE d.tablespace_name = a.tablespace_name(+)
AND d.tablespace_name = f.tablespace_name(+)
AND NOT
(d.extent_management LIKE 'LOCAL' AND d.contents LIKE 'TEMPORARY')
UNION ALL
SELECT d.status "Status",
d.tablespace_name "Name",
d.contents "Type",
d.extent_management "Extent Management",
to_char(nvl(a.bytes / 1024 / 1024, 0),  '99,999,990.900') "Size (M)",
to_char(nvl(t.bytes, 0) / 1024 / 1024, '99999999.999') || '/' ||
to_char(nvl(a.bytes / 1024 / 1024, 0), '99999999.999') "Used (M)",
to_char(nvl(t.bytes / a.bytes * 100, 0), '990.00') "Used %"
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 'TEMPORARY'
ORDER BY "Used %" DESC;
 
结果如下
Status    Name                           Type      Extent Man Size (M)
--------- ------------------------------ --------- ---------- ---------------
Used (M)                    Used %
--------------------------- -------
ONLINE    USERS                          PERMANENT LOCAL            2,083.750
     2078.438/     2083.750   99.75
ONLINE    SYSTEM                         PERMANENT LOCAL              740.000
      721.313/      740.000   97.47
ONLINE    SYSAUX                         PERMANENT LOCAL              270.000
      261.500/      270.000   96.85
ONLINE    TEMP                           TEMPORARY LOCAL               20.000
       18.000/       20.000   90.00
ONLINE    UNDOTBS1                       UNDO      LOCAL              675.000
      298.313/      675.000   44.19
ONLINE    EXAMPLE                        PERMANENT LOCAL              200.000
       77.750/      200.000   38.88
 
二、
SELECT D.TABLESPACE_NAME, 
      SPACE || 'M' "SUM_SPACE(M)", 
       BLOCKS "SUM_BLOCKS", 
       SPACE - NVL (FREE_SPACE, 0) || 'M' "USED_SPACE(M)", 
       ROUND ( (1 - NVL (FREE_SPACE, 0) / SPACE) * 100, 2) || '%' 
          "USED_RATE(%)", 
       FREE_SPACE || 'M' "FREE_SPACE(M)" 
  FROM (  SELECT TABLESPACE_NAME, 
                 ROUND (SUM (BYTES) / (1024 * 1024), 2) SPACE, 
                 SUM (BLOCKS) BLOCKS 
           FROM DBA_DATA_FILES 
        GROUP BY TABLESPACE_NAME) D, 
       (  SELECT TABLESPACE_NAME, 
                 ROUND (SUM (BYTES) / (1024 * 1024), 2) FREE_SPACE 
            FROM DBA_FREE_SPACE 
        GROUP BY TABLESPACE_NAME) F 
 WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+) 
UNION ALL                                                           --如果有临时表空间  
SELECT D.TABLESPACE_NAME, 
      SPACE || 'M' "SUM_SPACE(M)", 
      BLOCKS SUM_BLOCKS, 
      USED_SPACE || 'M' "USED_SPACE(M)", 
      ROUND (NVL (USED_SPACE, 0) / SPACE * 100, 2) || '%' "USED_RATE(%)", 
       NVL (FREE_SPACE, 0) || 'M' "FREE_SPACE(M)" 
 FROM (  SELECT TABLESPACE_NAME, 
                ROUND (SUM (BYTES) / (1024 * 1024), 2) SPACE, 
                SUM (BLOCKS) BLOCKS 
           FROM DBA_TEMP_FILES 
        GROUP BY TABLESPACE_NAME) D, 
      (  SELECT TABLESPACE_NAME, 
               ROUND (SUM (BYTES_USED) / (1024 * 1024), 2) USED_SPACE, 
                 ROUND (SUM (BYTES_FREE) / (1024 * 1024), 2) FREE_SPACE 
          FROM V$TEMP_SPACE_HEADER 
        GROUP BY TABLESPACE_NAME) F 
 WHERE D.TABLESPACE_NAME = F.TABLESPACE_NAME(+) 
order by 1;
 
参考:http://blog.csdn.net/tianlesoftware/article/details/7619732

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/9537053/viewspace-752534/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-06-11

  • 博文量
    97
  • 访问量
    178944