Thursday, March 27, 2008

Are your tablespaces shrinkable? (oracle)

here is a sql script by Tom Kyte.
if you have problems with sizes of tablespaces you can shrink datafiles. but if there is data at the end of the datafile you cannot shrink them.
with this sql script you can see if you can shrink them.
after running script you should copy the shrink commands and run them..

set verify offcolumn file_name format a50 word_wrappedcolumn smallest format 999,990 heading "SmallestSizePoss."column currsize format 999,990 heading "CurrentSize"column savings format 999,990 heading "Poss.Savings"break on reportcompute sum of savings on report
column value new_val blksizeselect value from v$parameter where name = 'db_block_size'/
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 ) savingsfrom dba_data_files a, ( select file_id, max(block_id+blocks-1) hwm from dba_extents group by file_id ) bwhere a.file_id = b.file_id(+)/
column cmd format a75 word_wrapped
select 'alter database datafile '''file_name''' resize ' ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) 'm;' cmdfrom dba_data_files a, ( select file_id, max(block_id+blocks-1) hwm from dba_extents group by file_id ) bwhere a.file_id = b.file_id(+) and ceil( blocks*&&blksize/1024/1024) - ceil( (nvl(hwm,1)*&&blksize)/1024/1024 ) > 0/


http://www.oracle.com/technology/oramag/oracle/04-sep/o54asktom.html

No comments: