Vous êtes sur la page 1sur 2

SUNDAY, MARCH 14, 2010

How to check Tablespace Fragmentation in Oracle Database?


Oracle Tablespace Fragmentation
Honeycomb fragmentation
Which is easy to fix. All that needs to be done is to combine adjacent free segm
ents into one by issuing a coalesce statement:
alter tablespace USERS coalesce;
Bubble fragmentation
Which is more difficult to handle. Of course, the best course of action is to pr
event it in the first place. And as discussed earlier, the best weapon for this
is to use locally-managed tablespaces. It may sound too simple, but in reality,
implementing these storage structures in your database can just about remove the
need to perform full tablespace reorganizations.
However, what do you do if you are in a situation where you have many databases
that were set up with dictionary-managed tablespaces? You have two options, at l
east if you are running Oracle 8i (the version that gave birth to locally-manage
d tablespaces). First, you can create new locally-managed tablespaces in your da
tabase and then perform one last, full tablespace reorganization of all the data
base objects into the new tablespaces.
Needless to say, this can be a difficult task if you have large databases and no
third-party reorganization tool. However, it will be worth the effort as you wi
ll likely never have to reorganize your tablespaces again, and your objects shou
ld never again encounter a maximum extent limit.
If you are using Oracle 8.1.6 or higher, you can convert any current dictionary-
managed tablespaces to locally-managed tablespaces. Buried in the Oracle documen
tation is a procedure for converting a tablespace's extent management from dicti
onary to local or vice-versa.
convert DMT to LMT:
sys.dbms_space_admin .tablespace_migrate_to_local('USERS');
If you are afraid of how long this procedure might take on large tablespaces, do
not be. It actually runs very fast.
convert LMT to DMT:
sys.dbms_space_admin .tablespace_migrate_from_local('USERS');
Detecting Oracle Tablespace Fragmentation
How can you tell if your tablespaces are suffering from fragmentation problems a
nd then identify the type of fragmentation? The detection and diagnosis is not h
ard to make at all. To determine if your tablespaces are having a problem with f
ragmentation, you can use the tsfrag.sql script:
select
tablespace_name,
count(*) free_chunks,
decode(
round((max(bytes) / 1024000),2),
null,0,
round((max(bytes) / 1024000),2)) largest_chunk,
nvl(round(sqrt(max(blocks)/sum(blocks))*(100/sqrt(sqrt(count(blocks)) )),2),
0) fragmentation_index
from
sys.dba_free_space
group by
tablespace_name
order by
2 desc, 1;
When you examine the script output, you need to hone in on a couple of columns i
n particular. First, notice the fragmentationindex column. This will give your t
ablespace an overall ranking with respect to how badly it is actually fragmented
. A 100% score indicates no fragmentation at all. Lesser scores verify the prese
nce of fragmentation.
The free chunks count column will tell you how many segments of free space are s
cattered throughout the tablespace. One thing to keep in mind is that tablespace
s with multiple datafiles will always show a free chunk count greater than one b
ecause each datafile will likely have at least one pocket of free space.
POSTED BY PLANETOFSOLUTIONS AT 9:27 PM
LABELS: FRAGMENTATION, ORACLE, TABLESPACE

Vous aimerez peut-être aussi