Oracle表空间查询
set linesize 200
set pagesize 5000
set timing on
select tablespace_name,
ts_max_mb / 1024 ts_max_gb,
ts_used_mb / 1024 ts_used_gb,
(ts_max_mb - ts_used_mb) / 1024 ts_free_gb,
round(100 * ts_used_mb / ts_max_mb, 2) ts_per
from (select a.tablespace_name tablespace_name,
round((a.bytes_alloc - nvl(b.bytes_free, 0)) / power(2, 20),
2) ts_used_mb,
round(a.maxbytes / power(2, 20), 2) ts_max_mb
from (select f.tablespace_name,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible,
'YES',
f.maxbytes,
'NO',
f.bytes)) maxbytes
from dba_data_files f
group by tablespace_name) a,
(select f.tablespace_name, sum(f.bytes) bytes_free
from dba_free_space f
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
union all
select h.tablespace_name tablespace_name,
round(sum(nvl(p.bytes_used, 0)) / power(2, 20), 2) ts_used_MB,
round(sum(decode(f.autoextensible,
'YES',
f.maxbytes,
'NO',
f.bytes)) / power(2, 20),
2) ts_max_mb
from v$temp_space_header h, v$temp_extent_pool p, dba_temp_files f
where p.file_id(+) = h.file_id
and p.tablespace_name(+) = h.tablespace_name
and f.file_id = h.file_id
and f.tablespace_name = h.tablespace_name
group by h.tablespace_name) a
order by 5 desc;