Tuesday, October 14, 2014

ORA-03297: file contains used data beyond requested RESIZE value


You can set your datafiles size up to hwm_bytes columns or you can resize your hwm through alter table move + rebuild index or export and import.

Error :

SQL> select bytes/1024 from dba_data_files where file_id = 7;
bytes/1024
----------
      7168
SQL> select sum(bytes/1024) from dba_segments where tablespace_name = 'USERS';
sum(bytes/1024)
---------------
           5440

SQL> alter database  datafile '/u02/data/db_1/db/ users 01.dbf' resize 5500k;
alter database
*
error at line 1:
ORA-03297: file contains used data beyond requested resize value

Solution:
You can resize your datafiles up to the hwm_bytes using the below output
select  a.file_name,    a.bytes file_size_in_bytes,
(c.block_id+(c.blocks-1)) * &block_size hwm_bytes,
a.bytes - ((c.block_id+(c.blocks-1)) * &block_size) saving
from dba_data_files a,
(select file_id,max(block_id) maximum
from dba_extents
group by file_id) b,
dba_extents c
where a.file_id = b.file_id
and c.file_id = b.file_id
and c.block_id = b.maximum
and c.tablespace_name = ' USERS '
SQL> /

enter value for _block_size: 8192
old   4:    (c.block_id+(c.blocks-1)) * &block_size hwm_bytes,
new   4:    (c.block_id+(c.blocks-1)) * 8192 hwm_bytes,
enter value for _block_size: 8192
old   5:    a.bytes - ((c.block_id+(c.blocks-1)) * &block_size) saving
new   5:    a.bytes - ((c.block_id+(c.blocks-1)) * 8192) saving

file_name            file_size_in_bytes  hwm_bytes     saving
-------------------------------- ------------------ ---------- ----------
/u02/data/db_1/db/ users 01.dbf
           7340032              6356992                        983040

SQL> alter database datafile '/u02/data/db_1/db/ users 01.dbf' resize 6356992;
database altered.