From 03dcb9e0b8f518d700c22604e4cbade79ff134b3 Mon Sep 17 00:00:00 2001 From: Yacine31 Date: Thu, 21 Dec 2023 11:41:47 +0100 Subject: [PATCH] Create maxshrink.sql --- maxshrink.sql | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 maxshrink.sql diff --git a/maxshrink.sql b/maxshrink.sql new file mode 100644 index 0000000..dcd0a6d --- /dev/null +++ b/maxshrink.sql @@ -0,0 +1,39 @@ +----------- maxshrink.sql ---------------------------------- + +set verify off +set pages 999 lines 100 +column file_name format a70 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 +select 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 ) 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(+) +/ + +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 +/