select distinct
tablespace_name key_value,
free_bytes_in_ts attribute1,
total_bytes_in_ts attribute2,
round( free_bytes_in_ts / total_bytes_in_ts * 100) attribute3,
null attribute4,
null attribute5
from
(
select
df.tablespace_name,
df.file_name,
sum(NVL(fs.bytes, 0) ) free_bytes_in_file,
df.bytes total_bytes_in_file,
sum(sum(NVL(fs.bytes, 0) ) ) over (partition by df.tablespace_name) free_bytes_in_ts,
sum(NVL(df.bytes, 0) ) over (partition by df.tablespace_name) total_bytes_in_ts--,
from
dba_free_space fs,
dba_data_files df,
dba_tablespaces ts
where
fs.file_id (+) = df.file_id
and fs.tablespace_name = ts.tablespace_name
and ts.contents != 'UNDO'
group by
df.tablespace_name,
df.file_name,
df.bytes
)
union all
select
tablespace_name key_value,
(free_bytes_in_ts + expired_bytes_in_ts) attribute1,
total_bytes_in_ts attribute2,
round( (free_bytes_in_ts + expired_bytes_in_ts) / total_bytes_in_ts * 100) attribute3,
null attribute4,
null attribute5
from
(
select
ts.tablespace_name,
(select sum(bytes) from dba_free_space fs
where fs.tablespace_name = ts.tablespace_name) free_bytes_in_ts,
(select sum(bytes) from dba_undo_extents ue
where ue.tablespace_name = ts.tablespace_name
and status = 'EXPIRED') expired_bytes_in_ts,
(select sum(bytes) from dba_data_files
where tablespace_name = ts.tablespace_name) total_bytes_in_ts
from
dba_tablespaces ts
where
ts.contents = 'UNDO'
)
order by
key_value;
|