Script to Detect Tablespace Fragmentation (Doc ID 1020182.6)
set pagesize 60
set newpage 0
set echo off
ttitle center 'Contiguous Extents Report' skip 3
break on "TABLESPACE NAME" skip page duplicate
spool contig_free_space.lis
rem
column "CONTIGUOUS BYTES" format 999,999,999
column "COUNT" format 999
column "TOTAL BYTES" format 999,999,999
column "TODAY" noprint new_value new_today format a1
rem
with a
as
(
SELECT tablespace_name,file_id,block_id,bytes,blocks,LEVEL,CONNECT_BY_ROOT
block_id as root,
count(*) over(partition by tablespace_name, file_id, CONNECT_BY_ROOT block_id)
as EXTENTS,
sum(bytes) over(partition by tablespace_name, file_id, CONNECT_BY_ROOT block_id)
as CONTIGUOUS_BYTES
FROM dba_free_space
CONNECT BY PRIOR (block_id+blocks) = block_id
and PRIOR tablespace_name = tablespace_name
and PRIOR file_id = file_id
)
select TABLESPACE_NAME "TABLESPACE NAME",
CONTIGUOUS_BYTES "CONTIGUOUS BYTES"
from a
where (tablespace_name, file_id, block_id) in
(select tablespace_name, file_id, block_id from
a
group by tablespace_name, file_id, block_id
having count(*)=1
)
order by 1,2 desc;
with a
as
(
SELECT tablespace_name,file_id,block_id,bytes,blocks,LEVEL,CONNECT_BY_ROOT
block_id as root,
count(*) over(partition by tablespace_name, file_id, CONNECT_BY_ROOT block_id)
as EXTENTS,
sum(bytes) over(partition by tablespace_name, file_id, CONNECT_BY_ROOT block_id)
as CONTIGUOUS_BYTES
FROM dba_free_space
CONNECT BY PRIOR (block_id+blocks) = block_id
and PRIOR tablespace_name = tablespace_name
and PRIOR file_id = file_id
)
select tablespace_name,count(*) "# OF EXTENTS",sum(CONTIGUOUS_BYTES) "TOTAL
BYTES"
from a
where (tablespace_name, file_id, block_id) in
(select tablespace_name, file_id, block_id from
a
评论