Tuesday, June 3, 2008

Data file fragmentation and Data file resize

There is no fragmentation at datafile level but sometime datafile is created in big size and actually data in datafile is very less then we can resize datafile to reduce database size.We can reduce datafile size upto HWM (High Water Mark)
SQL> select df.file_name,round(df.bytes/1024/1024) TotalSize,fs.FreeSizefrom dba_data_files df,(select file_id,round(sum(bytes/1024/1024)) FreeSizefrom dba_free_spacegroup by file_id) fswhere df.file_id=fs.file_id(+)order by 2,3 descFILE_NAME TOTALSIZE FREESIZE-------------------------------------------------- ---------- ----------D:\ORACLE\PRODUCT\10.1.0\ORADATA\USERS01.DBF 46 1D:\BIG01.DBF 100 100D:\ORACLE\PRODUCT\10.1.0\ORADATA\UNDOTBS01.DBF 465 436D:\ORACLE\PRODUCT\10.1.0\ORADATA\SYSTEM01.DBF 620 63D:\ORACLE\PRODUCT\10.1.0\ORADATA\SYSAUX01.DBF 700 32Note: Size in MB (Mega Bytes)Two datafiles which we can reduce 1.big01.dbf 2.undotbs01.dbf
SQL> alter databasedatafile ‘d:\big01.dbf’ resize 50m;Database altered.SQL> alter databasedatafile 'd:\oracle\product\10.1.0\oradata\undotbs01.dbf' resize 100m;alter database*ERROR at line 1:ORA-03297: file contains used data beyond requested RESIZE : ORA-03297 error happens because we are trying to reduce datafile below HWM and it is not possible. Go through above link and check from where you can reduce datafile size.

No comments: