資料檔案resize回收空間
阿新 • • 發佈:2021-06-25
問題描述:有一個數據檔案縮容的需求,提前測試下,回收完要做表壓縮的操作
1.查詢可以resize的資料檔案
select a.file#, a.name, c.tablespace_name, round(a.bytes/1024/1024) CurrentMB, ceil(HWM *a.block_size)/1024/1024 ResizeTo, (a.bytes - HWM*a.block_size)/1024/1024 ReleaseMB, 'alter database datafile ' || a.FILE# || ' resize ' || round(ceil(HWM*a.block_size)/1024/1024+5)||'M;' ResizeCmd from v$datafile a, (SELECT file_id,MAX(block_id+blocks-1) HWM FROM DBA_EXTENTS GROUP BY file_id) b, dba_data_files c where a.file# = b.file_id(+) And (a.bytes - HWM * a.block_size) >0 and a.FILE#=c.file_id and c.tablespace_name not in ('SYSTEM','SYSAUX') and c.tablespace_name not like'%UNDO%' order by 6 desc;
2.查詢資料檔案的大小
select file_name,bytes/1024/1024/1024 as GB from dba_data_files
3.進行資料檔案resize的回收
alter database datafile 4 resize 1363M; alter database datafile 8 resize 574M; alter database datafile 7 resize 6M; alter database datafile 9 resize 6M; alter database datafile6 resize 16M; alter database datafile 5 resize 318M;
3.檢視資料檔案大小,可以看到資料檔案已經變小
select file_name,bytes/1024/1024/1024 as GB from dba_data_files