是平時自己看公司數據庫表空間狀態時用的。你可以參考下:.查看所有表空間的碎片程度(值在30以下表示碎片很多)
select tablespace_name, sum(bytes), sum(free), sum(free) * 100 / sum(bytes)
from (select b.file_id file_ID,
b.tablespace_name tablespace_name,
b.bytes Bytes,
(b.bytes - sum(nvl(a.bytes, 0))) used,
sum(nvl(a.bytes, 0)) free,
sum(nvl(a.bytes, 0)) / (b.bytes) * 100 Percent
from dba_free_space a, dba_data_files b
where a.file_id = b.file_id
group by b.tablespace_name, b.file_id, b.bytes
order by b.file_id)
group by tablespace_name
order by sum(free) * 100 / sum(bytes) ;
查看錶空間是否自動擴展
select file_name,autoextensible,
increment_by from dba_data_files;
表空間自動擴展
alter database datafile 'path:\datafile name'
autoextend on next 1M maxsize 100M;
表空間大小
select tablespace_name,count(*),sum(blocks),
sum(bytes)/1024/1024 from dba_data_files group by tablespace_name;
使用情況
select df.tablespace_name "表空間名",--表空間名
totalspace "總空間M",
freespace "剩餘空間M",
round((1 - freespace / totalspace) * 100, 2) "使用率%"
from (select tablespace_name, round(sum(bytes) / 1024 / 1024) totalspace
from dba_data_files
group by tablespace_name) df,
(select tablespace_name, round(sum(bytes) / 1024 / 1024) freespace
from dba_free_space
group by tablespace_name) fs
where df.tablespace_name = fs.tablespace_name;