把datafile的size用resize方法变成最小
SQL> set verify off
column file_name format a50 word_wrapped
column smallest format 999,990 heading "Smallest|Size|Poss."
column currsize format 999,990 heading "Current|Size"
column savings format 999,990 heading "Poss.|Savings"
break on report
compute sum of savings on report
column value new_val blksize
1)Oracle block的大小
SQL>select value from v$parameter where name = 'db_block_size';
VALUE
--------------------------------------------------------------------------------
8192
2)算出每个文件的信息
select file_name,
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) smallest,
ceil( blocks*&&blksize/1024/1024) currsize,
ceil( blocks*&&blksize/1024/1024) -
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) savings
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(+)
/
Smallest
Size Current Poss.
FILE_NAME Poss. Size Savings
-------------------------------------------------- -------- -------- --------
/oracle/oradata/orcl/system01.dbf 705 710 5
/oracle/product/10.2.0/db_1/dbs/tivoliorts.dbf 2 250 248
/oracle/oradata/orcl/sysaux01.dbf 764 810 46
/oracle/oradata/orcl/users01.dbf 2 5 3
/oracle/oradata/orcl/undotbs01.dbf 87 100 13
/oracle/ts_cus/ts_cus.dbf 2 100 98
/oracle/oradata/orcl/dyx 1
/oracle/oradata/orcl/ddd.ora 1
/oracle/oradata/orcl/testtb.dbf 1
Smallest
Size Current Poss.
FILE_NAME Poss. Size Savings
-------------------------------------------------- -------- -------- --------
--------
sum 413
3)动态生成resizesql语句
column cmd format a75 word_wrapped
select 'alter database datafile '''||file_name||''' resize ' ||
ceil( (nvl(hwm,1)*&&blksize)/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*&&blksize/1024/1024) -
ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0
/
SQL>
CMD
---------------------------------------------------------------------------
alter database datafile '/oracle/oradata/orcl/system01.dbf' resize 705m;
alter database datafile '/oracle/product/10.2.0/db_1/dbs/tivoliorts.dbf' resize 2m;
alter database datafile '/oracle/oradata/orcl/sysaux01.dbf' resize 764m;
alter database datafile '/oracle/oradata/orcl/users01.dbf' resize 2m;
alter database datafile '/oracle/oradata/orcl/undotbs01.dbf' resize 87m;
alter database datafile '/oracle/ts_cus/ts_cus.dbf' resize 2m;
6 rows selected.
阅读(11237) | 评论(0) | 转发(1) |