查询表空间利用率

查询表空间利用率--考虑自增长情况,此处利用率考虑的是相对于阀值的表空间利用率

select a.tablespace_name, total || 'M', free+shortNum|| 'M' free, total-free-shortNum || 'M' as used,
Round((free+shortNum)/total * 100, 3) as "FREE%",Round((total - free-shortNum)/total * 100, 3) as "USED%" from
(select tablespace_name,autoextensible,case when t.autoextensible='YES' then (maxbytes-bytes)/1024/1024 else 0 end shortNum,case when t.autoextensible='YES' then sum(maxbytes)/1024/1024 else sum(bytes)/1024/1024 end as total from dba_data_files t group by tablespace_name,autoextensible,maxbytes,bytes) a,
(select tablespace_name, sum(bytes)/1024/1024 as free from dba_free_space group by tablespace_name) b
where a.tablespace_name = b.tablespace_name order by a.tablespace_name

查询结果

 追加,由于数据不断增多,原定机器表空间大小有可能不够用,也许会扩展表空间大小,即同一个表空间名可能包含扩展和非扩展属性的表空间,file_id也不一样,于是有了下面这一条sql

select a.tablespace_name,a.file_id,
       total,
       free + shortNum free,
       total - free - shortNum as used,
       Round((free + shortNum) / total * 100, 2) as "FREE%",
       Round((total - free - shortNum) / total * 100, 2) as "USED%",
       autoextensible
  from (select tablespace_name,
               file_id,
               autoextensible,
               case
                 when t.autoextensible = 'YES' then
                  (sum(maxbytes) - sum(bytes)) / 1024 / 1024
                 else
                  0
               end shortNum,
               case
                 when t.autoextensible = 'YES' then
                  sum(maxbytes) / 1024 / 1024
                 else
                  sum(bytes) / 1024 / 1024
               end as total
          from dba_data_files t
         group by tablespace_name,file_id, autoextensible ) a,
       (select tablespace_name, file_id,sum(bytes) / 1024 / 1024 as free
          from dba_free_space
         group by tablespace_name,file_id) b
 where a.tablespace_name = b.tablespace_name and a.file_id=b.file_id
 order by a.tablespace_name

设置自动增长的,可取其最大阀值,不管自增量为多少,在磁盘空间足够的情况下,表空间最终大小=阀值 

没有你想要的?再逛逛:https://www.cnblogs.com/lipera/p/6201434.html

原文地址:https://www.cnblogs.com/personsiglewine/p/11400679.html