Monday 20 June 2011

Oracle database: Reducing datafile size to recover free space

The following are queries you may use:
select 'alter table '||owner||'.'||table_name||' move tablespace STG_TS1 ;'
from dba_tables
where tablespace_name = 'STG_TS'
order by 1;

select 'alter index '||owner||'.'||index_name||' rebuild tablespace STG_TS1 ;'
from dba_indexes
where tablespace_name = 'STG_TS'
and index_type != 'LOB'
order by 1;


select 'alter table '||TABLE_OWNER||'.'||table_name||' move partition '||PARTITION_NAME||' tablespace STG_TS1 ;'
from dba_tab_partitions
where tablespace_name = 'STG_TS'
order by 1;

select 'alter table '||OWNER||'.'||table_name||' move lob('||SEGMENT_NAME||') store as (TABLESPACE STG_TS1) ;'
from dba_lobs
where tablespace_name = 'STG_TS'
order by 1;

select 'alter table ' ||owner || '.' || table_name||' move lob ('||column_name||') store as (tablespace STG_TS1);'
from dba_lobs where SEGMENT_NAME in ( select segment_name from dba_segments where tablespace_name ='STG_TS' and segment_type like '%LOB%');

No comments:

Post a Comment

Number of Visitors