Академический Документы
Профессиональный Документы
Культура Документы
tablespace
Posted on October 26, 2014 by admin
In Oracle Database, Whenever statistics in the dictionary are modified, old versions of statistics
are saved automatically for future restoring purpose. But this old statistics which are saved
automatically, are purged automatically at regular intervals based on the statistics history
retention setting and the time of recent statistics gathering performed in the system.
If the retention period is not managed then the SYSAUX tablespaces can grow very large.
This is only a small workout in a small database with less data. So the reclaim size of the
SYSAUX tablespace will be less. There will be a huge difference in space reclaim of the SYSAUX
tablespace on a big database with huge data.
This blog entry will provide the scripts and steps to diagnose and correct the excessive or rapid
growth of the tablespace due to retained statistics.
select rpad(a.tablespace_name,30,’.’)tablespace_name,
sum(a.bytes)/(1024*1024) Allocated,
sum(a.bytes)/(1024*1024) – max(nvl(b.space,0)) Used,
max(nvl(b.space,0)) Free,round(((max(nvl(b.space,0)))/(sum(a.bytes)/(1024*1024))),4)*100
perctfree,
max(nvl(b.cont,0))/(1024*1024) Contiguous
from dba_data_files a,
(select tablespace_name,sum(bytes)/(1024*1024) space,max(bytes) cont
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
and a.tablespace_name=’SYSAUX’
group by a.tablespace_name
order by a.tablespace_name
/
From the output we can see that only 150 MB of free space is available in SYSAUX tablespace.
exec dbms_stats.alter_stats_history_retention(10);
4. Now execute the below command to PURGE the Old Statistics. That is purge the
statistics which are older than 10 Days.
If there is huge data, then it is recommended to purge in stages like (sysdate-30,sydate-25 etc).
exec DBMS_STATS.PURGE_STATS(SYSDATE-10);
7. Show how big the indexes are ready for a rebuild after stats have been purged.
select ‘alter table ‘||segment_name||’ move tablespace SYSAUX;’ from dba_segments where
tablespace_name = ‘SYSAUX’
and segment_name like ‘%OPT%’ and segment_type=’TABLE’
/
9. Run the commands generated by the script.
10. Rebuild the indexes since the status of the Indexes will be in Unusable state.
Use the below script to generate the rebuild statements.
select ‘alter index ‘||segment_name||’ rebuild online parallel (degree 14);’ from dba_segments
where tablespace_name = ‘SYSAUX’
and segment_name like ‘%OPT%’ and segment_type=’INDEX’
/
11. Run the rebuild statements generated by the script.
12. Before rebuilding the indexes, the status of the indexes will be in Unusable state. After
rebuilding the indexes check the status of the indexes.
select rpad(a.tablespace_name,30,’.’)tablespace_name,
sum(a.bytes)/(1024*1024) Allocated,
sum(a.bytes)/(1024*1024) – max(nvl(b.space,0)) Used,
max(nvl(b.space,0)) Free,round(((max(nvl(b.space,0)))/(sum(a.bytes)/(1024*1024))),4)*100
perctfree,
max(nvl(b.cont,0))/(1024*1024) Contiguous
from dba_data_files a,
(select tablespace_name,sum(bytes)/(1024*1024) space,max(bytes) cont
from dba_free_space
group by tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
and a.tablespace_name=’SYSAUX’
group by a.tablespace_name
order by a.tablespace_name
/
From the output we can clearly see that there is space gain of nearly 250 MB from the Sysaux
tablespace.
If required you can bring back the retention period to the default value 31 days.
exec dbms_stats.alter_stats_history_retention(31);