天天看点

查看表空间及文件大小的语句

select d.tablespace_name ts_name,

       d.contents ts_type,

       d.status ts_status,

       d.extent_management ts_extentmanagement,

       trunc(nvl(a.bytes / 1024 / 1024, 0)) ts_size,

       trunc(nvl(a.bytes - nvl(f.bytes, 0), 0) / 1024 / 1024) ts_usedsize,

       trunc(nvl((a.bytes - nvl(f.bytes, 0)) / a.bytes * 100, 0)) ts_used

  from sys.dba_tablespaces d,

       (select tablespace_name, sum(bytes) bytes

          from dba_data_files

         group by tablespace_name) a,

          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

       trunc(nvl(t.bytes, 0) / 1024 / 1024) ts_usedsize,

       trunc(nvl(t.bytes / a.bytes * 100, 0)) ts_used

          from dba_temp_files

       (select tablespace_name, sum(bytes_cached) bytes

          from v$temp_extent_pool

         group by tablespace_name) t

   and d.tablespace_name = t.tablespace_name(+)

   and d.extent_management like 'local'

   and d.contents like 'temporary'

 order by ts_name;

ts_name                        ts_type   ts_status ts_extentmanagement ts_size_mb ts_usedsize_mb    ts_used

------------------------------ --------- --------- ------------------- ---------- -------------- ----------

example                        permanent online    local                      100             77         77

sysaux                         permanent online    local                      240            238         99

system                         permanent online    local                      480            475         99

temp                           temporary online    local                       20             18         90

undotbs1                       undo      online    local                       35             28         81

users                          permanent online    local                        5              3         65

--查看数据文件大小

select a.tablespace_name,a.file_name,a.bytes/1024/1024 total_mb, (a.bytes - nvl(c.bytes, 0))/1024/1024 use_mb

  from (select a.*,

               d.status file_status,

               a.increment_by * b.block_size extendbytes

          from dba_data_files a, dba_tablespaces b, v$datafile d

         where a.tablespace_name = b.tablespace_name

           and a.file_id = d.file#

           /*and a.file_id = :file_id*/) a

  left join (select file_id, sum(bytes) bytes

               from dba_free_space

              /*where file_id = :file_id*/

              group by file_id) c on a.file_id = c.file_id

select a.tablespace_name,a.file_name,a.bytes/1024/1024 total_mb, c.bytes/1024/1024 use_mb

          from dba_temp_files a, dba_tablespaces b, v$tempfile d

         where a.tablespace_name= b.tablespace_name

  left join (select file_id, sum(bytes_cached) bytes

               from v$temp_extent_pool

tablespace_name                file_name                                                                          total_mb     use_mb

------------------------------ -------------------------------------------------------------------------------- ---------- ----------

system                         d:\oracle\product\10.2.0\oradata\jingyong\system01.dbf                                  480      475.5

undotbs1                       d:\oracle\product\10.2.0\oradata\jingyong\undotbs01.dbf                                  35    28.4375

users                          d:\oracle\product\10.2.0\oradata\jingyong\users01.dbf                                     5       3.25

example                        d:\oracle\product\10.2.0\oradata\jingyong\example01.dbf                                 100    77.6875

sysaux                         d:\oracle\product\10.2.0\oradata\jingyong\sysaux01.dbf                                  240   238.8125

temp                           d:\oracle\product\10.2.0\oradata\jingyong\temp01.dbf                                     20         18