Oracle數據庫表空間碎片的查詢和整理方法

1、查看錶空間碎片的方法spa

1.查看fsfi值table

 

select a.tablespace_name,select

trunc(sqrt(max(blocks)/sum(blocks))* (100/sqrt(sqrt(count(blocks)))),2) fsfi 方法

from dba_free_space  a,dba_tablespaces bdb

where a.tablespace_name=b.tablespace_nametab

and b.contents not in('TEMPORARY','UNDO','SYSAUX')文件

group by A.tablespace_name vi

order by fsfi; dba

 

若是FSFI小於<30則表空間碎片太多.co

 

fsfi的最大可能值爲100(一個理想的單文件表空間)。隨着範圍的增長,fsfi值緩慢降低,而隨着最大範圍尺寸的減小,fsfi值會迅速降低。

 

2.查看dba_free_space

 

dba_free_space 顯示的是有free 空間的tablespace ,若是一個tablespace 的free 空間不連續,

那每段free空間都會在dba_free_space中存在一條記錄。若是一個tablespace 有好幾條記錄,

說明表空間存在碎片,當採用字典管理的表空間碎片超過500就須要對錶空間進行碎片整理。

 

select a.tablespace_name ,count(1) 碎片量 from 

dba_free_space a, dba_tablespaces b 

where a.tablespace_name =b.tablespace_name

and b.contents not in('TEMPORARY','UNDO','SYSAUX')

group by a.tablespace_name

having count(1) >20

order by 2;

 

2、整理方法

 

alter tablespace 表空間名 coalesce;

若是再次查看碎片沒有減小,則需考慮重建表空間。

相關文章
相關標籤/搜索