Beruflich Dokumente
Kultur Dokumente
First of all, I need to estimate how much space can be saved potentially after
the reorganization. For table segment, I use DBMS_SPACE.create_table_cost to est
imate the size after reorganization. Given the number of row and average row siz
e and the target tablespace, the following script can be used to estimate the si
ze if the table is moved to the target tablespace.
-----
script: tabsize_est.sql
get the avg row size and row cnt from analyze job
dba_tables
@tabsize_est 'table_size' 100 10000000
'
'
'
'
'
'
TTQ_ORD
TTQ_ORD
TTQ_ORD
TTQ_ORD
TTQ_ORD
TTQ_ORD
Then, executing above commands, I can obtain current and estimated table segmen
t size as shown below:
TTQ_ORD
TTQ_ORD
s
TTQ_ORD
TTQ_ORD
TTQ_ORD
TTQ_ORD
...
To estimate the size of index segment after rebuild, I use a script called inde
x_est_proc_2.sql by Joanathan Lewis (http://jonathanlewis.wordpress.com/index-si
zing/).
I use EXCEL to calcuate the size difference between the estimated size and curr
ent size for each index and table. As a result I can estimate the total space ga
in. Of course when I plan to do reoraganization, I can start with the segment wh
ich would give the most space gain.
The space gain estimated is at tabespace level. To actually release the space a
t OS level, the datafile needs to be shrinked. For this it is very useful to kno
w which segments reside at the end of datafile. Those segments should be moved f
irst to allow the datafile shrikable.
The following script is used to list the segment in each data file ordered by i
ts max(block_id). The segments that reside at the end of datafile should have la
rge max(block_id).
-- find segment at the end of the data files
-- so if this segment is removed, the data file could be resized down
spool shrinkdf_&tbs..log
col sum_mbytes format 999,999
col diff format 999,999,999
select name from v$database;
break on file_id skip 1
select file_id, segment_name, sum_mbytes, count_blocks, max_block_id,
max_block_id - lead(max_block_id,1) over (partition by file_id order by max_blo
It is clear that for the datafile with file_id=227, ORDER_TRANS is at the end,
followed by AUDIT_TRAIL.
Finally, the following script can be used to generate the resize statement:
rem script: red_df.sql
rem
rem Purpose: This gives the Total size of datafiles in a tablespace
rem
and also the size to which it can be reduced.
rem
It generated rdf.log spool file with commands to resize datafiles
rem Usage: @red_df.sql <TABLESPACE>
rem
rem Note: I got this script from a colleague but I once saw this script in AskT
om website
set verify off
col
col
col
col
col
col
tsname
nfrags
mxfrag
totsiz
avasiz
pctusd
format
a24
justify c
format
9,999,990 justify c
format 999,990.999 justify c
format 9,999,990.999 justify c
format 9,999,990.999 justify c
format
990.99 justify c
heading
heading
heading
heading
heading
heading
'Tablespace'
'Free|Frags'
'Largest|Free Frag'
'Total|Mbytes'
'Available|Mbytes'
'Percent|Used'