查询表空间使用情况
SELECT Upper(A.TABLESPACE_NAME) "表空间名",
D.TOT_GROOTTE_MB "表空间大小(M)",
D.TOT_GROOTTE_MB - A.TOTAL_BYTES "已使用空间(M)",
To_char(Round((D.TOT_GROOTTE_MB - A.TOTAL_BYTES) / D.TOT_GROOTTE_MB * 100,
2),
'990.99') || '%' "使用比",
A.TOTAL_BYTES "空闲空间(M)",
A.MAX_BYTES "最大块(M)",
D.AUTOEXTENSIBLE "是否自增长",
D.incrementSize "自增长大小(M)",
D.CREATE_TIME "创建时间"
FROM (select T.TABLESPACE_NAME,
Round(Sum(T.BYTES) / (1024 * 1024), 2) AS TOTAL_BYTES,
Round(Max(T.BYTES) / (1024 * 1024), 2) AS MAX_BYTES
from SYS.DBA_FREE_SPACE t
group by t.TABLESPACE_NAME) A,
(SELECT B.autoextensible,
Round(Sum(B.BYTES) / (1024 * 1024), 2) TOT_GROOTTE_MB,
Round(B.increment_by *
(select value
from v$parameter
where name = 'db_block_size') / (1024 * 1024),
2) AS incrementSize,--自增长大小为数据库中数据块的个数,一个数据块一般为8k
B.TABLESPACE_NAME,
min(C.CREATION_TIME) CREATE_TIME--获取创建时间,如果有多个数据文件,获取到最初时间
FROM SYS.DBA_DATA_FILES B, v$DATAFILE C
WHERE B.file_id = C.FILE#
group by B.TABLESPACE_NAME, B.autoextensible, B.increment_by) D
WHERE A.TABLESPACE_NAME = D.TABLESPACE_NAME
order by D.CREATE_TIME;