方法 : 如果你想把 aa.dbf 这个数据文件给缩小。
1)查看这个数据文件上的数据库对象。
2)exp 出这些数据对象
3) drop 这些数据对象。
4) alter database datafile '/export/home/oraclle/aa.dbf' resize 1000m;
5) imp 这些数据对象
注意这些数据库对象所在的表空间。这一点是非常重要的 。
select 'alter database datafile ''' || file_name || ''' resize ' || ceil( (nvl(hwm,1)*8192)/1024/1024 ) || 'm;' cmd from dba_data_files a, ( select file_id, max(block_id+blocks-1) hwm from dba_extents group by file_id ) b where a.file_id = b.file_id(+) and ceil(blocks*8192/1024/1024)- ceil((nvl(hwm,1)* 8192)/1024/1024 ) > 0;
declare cursor c_dbfile is select tablespace_name ,file_name ,file_id ,bytes from sys.dba_data_files where status !='INVALID' order by tablespace_name,file_id; cursor c_space(v_file_id in number) is select block_id,blocks from sys.dba_free_space where file_id=v_file_id order by block_id desc; blocksize number(38); filesize number(38); extsize number(38); begin select value into blocksize from v$parameter where name = 'db_block_size'; for c_rec1 in c_dbfile loop filesize := c_rec1.bytes; <<outer>> for c_rec2 in c_space(c_rec1.file_id) loop extsize := ((c_rec2.block_id - 1)*blocksize + c_rec2.blocks*blocksize); if extsize = filesize then filesize := (c_rec2.block_id - 1)*blocksize; else exit outer; end if; end loop ; if filesize = c_rec1.bytes then dbms_output.put_line('Tablespace: '||' '||c_rec1.tablespace_name||' Datafile: '||c_rec1.file_name); dbms_output.put_line('Can not be resized, no free space at end of file.'); dbms_output.put_line('.'); else if filesize < 2*blocksize then dbms_output.put_line('Tablespace: '||' '||c_rec1.tablespace_name||' Datafile: '||c_rec1.file_name); dbms_output.put_line('Can be resized uptil: '||2*blocksize||' Bytes, Actual size: '||c_rec1.bytes||' Bytes'); dbms_output.put_line('.'); else dbms_output.put_line('Tablespace: ' ||' '||c_rec1.tablespace_name||' Datafile: '||c_rec1.file_name); dbms_output.put_line('Can be resized uptil: '||filesize ||' Bytes, Actual size: '||c_rec1.bytes); dbms_output.put_line('.'); end if; end if; end loop; end; /
1 select 2 max((e.block_id + e.blocks) * &&db_block_size/1024/1024) as "Can Resize(M)", 3 f.bytes/1024/1024 "Current Size(M)", 4 sum(e.bytes/1024/1024) as "totalUsed(M)", 5 file_name 6 from 7 dba_extents e,dba_data_files f 8 where 9 e.file_id= f.file_id 10 group by 11 file_name,f.bytes/1024/1024 12* order by 2-1 Can Resize(M) Current Size(M) totalUsed(M) FILE_NAME ------------- --------------- ------------ ---------------------------------------- 4 20 4 /data/oradata/rmanrep/drsys01.dbf 45 50 28 /data/oradata/rmanrep/rbs01.dbf 4 50 4 /data/oradata/rmanrep/rman8i01.dbf 4 50 4 /data/oradata/rmanrep/rman9i01.dbf 273 280 273 /data/oradata/rmanrep/system01.dbf 4 20 4 /data/oradata/rmanrep/temp01.dbf 116 512 116 /data/oradata/rmanrep/tools01.dbf 0 45 0 /data/oradata/rmanrep/users01.dbf