码迷,mamicode.com
首页 > 数据库 > 详细

查询数据库表空间

时间:2015-12-02 01:14:42      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:查询数据库表空间

select df.tablespace_name,
       round(df.total_space / 1048576, 0) "Total Space(MB)",
       round((df.total_space - nvl(fs.free_space, 0)) / 1048576, 0) "Used Space(MB)",
       round(nvl(fs.free_space, 0) / 1048576, 0) "Free Space(MB)",
       round(100 * (1 - nvl(fs.free_space, 0) / df.total_space), 2) "%Used",
       to_char(Sysdate, ‘yyyy-mm-dd hh24:mi‘) Stat_Time
  from (select tablespace_name, sum(bytes) total_space
          from dba_data_files
         group by tablespace_name) df,
       (select b.tablespace_name, sum(b.bytes) free_space
          from dba_free_space b
         group by b.tablespace_name) fs
 where df.tablespace_name = fs.tablespace_name(+)
   and exists (select *
          from dba_tablespaces ts
         where ts.contents <> ‘TEMPORARY‘
           and ts.tablespace_name = df.tablespace_name)
union
select df.tablespace_name,
       round(df.total_space / 1048576, 0) "Total Space(MB)",
       round(nvl(us.used_space, 0) / 1048576, 0) "Used Space(MB)",
       round((df.total_space - nvl(us.used_space, 0)) / 1048576, 0) "Free Space(MB)",
       round(100 * (nvl(us.used_space, 0) / df.total_space), 2) "%Used",
       to_char(Sysdate, ‘yyyy-mm-dd hh24:mi‘) Stat_Time
  from (select tablespace_name, sum(bytes) total_space
          from dba_temp_files
         group by tablespace_name) df,
       (select b.tablespace_name, sum(b.bytes_cached) used_space
          from v$temp_extent_pool b
         group by b.tablespace_name) us
 where df.tablespace_name = us.tablespace_name(+)
   and exists (select *
          from dba_tablespaces ts
         where ts.contents = ‘TEMPORARY‘
           and ts.tablespace_name = df.tablespace_name)
 order by 5 desc;
!


本文出自 “北京——东东” 博客,请务必保留此出处http://bjdong.blog.51cto.com/507460/1718632

查询数据库表空间

标签:查询数据库表空间

原文地址:http://bjdong.blog.51cto.com/507460/1718632

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!