SELECT
mAX(B.file_id) id,
B.TABLESPACE_NAME 表空间,
B.FILE_NAME 物理文件名,
B.BYTES / 1024 / 1024 大小M,
(B.BYTES - SUM(NVL(A.BYTES,0))) / 1024 / 1024 已使用M,
SUBSTR((B.BYTES - SUM(NVL(A.BYTES,0))) / (B.BYTES) * 100,1,5) 利用率
FROM DBA_FREE_SPACE A,DBA_DATA_FILES B
WHERE A.FILE_ID = B.FILE_ID
GROUP BY B.TABLESPACE_NAME,B.FILE_NAME,B.BYTES
ORDER BY B.TABLESPACE_NAME;
select 'alter database datafile ''' || a.file_name || ''' resize ' ||
round(a.filesize - (a.filesize - c.hwmsize - 100) * 0.8) || 'M;',
a.filesize || 'M' as "数据文件的总大小",
c.hwmsize || 'M' as "数据文件的实用大小"
from (select file_id,file_name,round(bytes / 1024 / 1024) as filesize
from dba_data_files) a,
(select file_id,round(max(block_id) * 8 / 1024) as HWMsize
from dba_extents
group by file_id) c
where a.file_id = c.file_id
and a.filesize - c.hwmsize > 100;
-- 执行缩小表空间文件
ALTER DATABASE DATAFILE 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\ORCL\USERS02.DBF' RESIZE 300M
-- 查看表空间文件
select file#,name from v$datafile
原文链接:https://www.f2er.com/oracle/213120.html