oDiWuYuanSu 2017-11-24
错误号信息分析:
--------------------------------------------------------------------------------
[Oracle@localhost ~]$ oerr ora 03297
03297, 00000, "file contains used data beyond requested RESIZE value"
// *Cause: Some portion of the file in the region to be trimmed is
// currently in use by a database object
// *Action: Drop or move segments containing extents in this region prior to
// resizing the file, or choose a resize value such that only free
// space is in the trimmed.
[oracle@Database-backup ~]$
报错信息很提示:文件包含超出要求的调整值的数据,如下来看下各数据文件可回收到的最小大小,若没resize回收余地如何解决。
Oracle 查看DBF回收resize最小大小 -->各DBF最大block大小
--------------------------------------------------------------------------------
SQL>
select 'alter database datafile ''' || file_name || ''' resize ' ||decode(MAX_GB, 0, '100M;', MAX_GB || 'G;') RESIZE命令,
a.TABLESPACE_NAME,
a.AUTOEXTENSIBLE,
a.TOTAL_GB,
a.MAX_GB
from (SELECT TABLESPACE_NAME,
FILE_NAME,
AUTOEXTENSIBLE,
CEIL(SUM(BYTES / 1024 / 1024 / 1024)) TOTAL_GB,
CEIL(SUM(case when MAX_BLOCK.FILE_ID is null then 0 else MAX_BLOCK.MAX_BLOCK end)) MAX_GB
--由于size大小需为整
--CEIL(N) 取大于等于数值N的最小整数
--FLOOR(N)取小于等于数值N的最大整数
FROM DBA_DATA_FILES
LEFT JOIN (SELECT MAX(BLOCK_ID) * 8 / 1024 / 1024 MAX_BLOCK,
FILE_ID
FROM DBA_EXTENTS
GROUP BY FILE_ID) MAX_BLOCK
ON MAX_BLOCK.FILE_ID = DBA_DATA_FILES.FILE_ID
GROUP BY TABLESPACE_NAME, /*MAX_BLOCK.FILE_ID,*/
FILE_NAME,
AUTOEXTENSIBLE
ORDER BY TABLESPACE_NAME) A
where TOTAL_GB != MAX_GB;
RESIZE命令 TABLESPACE_NAME AUTOEXTENSIBLE TOTAL_GB MAX_BLOCK_GB
---------------------------------------------------------------------------- -------- -------- -------- -------- -------- ----------------------------- ----------------- ------------- ------------
alter database datafile '/data/datafiles/ZB_LSP_001/sysaux01.dbf' resize 8G; SYSAUX YES 10 8
alter database datafile '/data/datafiles/ZBLSP_DATA_001.dbf' resize 27G; TBS_LMP YES 30 27
alter database datafile '/data/datafiles/ZB_LSP_001/tbs_scheduler.dbf'resize 10G; TBS_SCHEDULER YES 32 10
SQL>
--------------------------------------------------------------------------------
提示:
当MAX_BLOCK_GB接近TOTAL_GB时,可通过查询DBA_EXTENTS按照block_id排序,move部分最大块对象(适用于block_id极其且较少的不连续block_id'例如:数据文件Resize引起的ORA-03297报错')
当然,若通过dba_free_space查询数据文件空间剩余较多,想对剩余空间进行部分resize来释放系统空间,可同如下方式解决
1、写个批处理 move 对象,注意索引失效处理;
2、导出,重建数据文件,再导入;
扩展:
查看碎片比:select tablespace_name,count(*) chunks,max(bytes/1024/1024) max_chunk from dba_free_space group by tablespace_name;
#CHUNK列表示表空间中可用有多少可用的空闲数据块,如果空闲块较多,超过100,则需要对相邻碎片进行整合
查看block_id极其不连续情况
select * from (SELECT segment_name,block_id ,LEAD( block_id) OVER ( ORDER BY block_id desc)/*整列向下移动一行*/ block_id_ FROM dba_extents) where block_id -block_id_ >10000