In oracle schema you found some tables which has huge difference in actual size (size from User_segments) and expected size from user_tables (Num_rows*avg_row_length (in bytes)). This all is due to fragmentation in the table or stats for table are not updated into user_tables.
If a table is only subject to inserts, there will not be any fragmentation. Fragmentation comes with when we update/delete data in table. The space which gets freed up during non-insert DML operations is not immediately re-used. This leaves behind holes in table which results in table fragmentation.
When rows are not stored contiguously, or if rows are split onto more than one block, performance decreases because these rows require additional block accesses.
Table fragmentation is different from file fragmentation. When a lot of DML operations are applied on a table, the table will become fragmented because DML does not release free space from the table below the HWM.(High Water Mark).
HWM is an indicator of USED BLOCKS in the database. Blocks below the high water mark (used blocks) have at least once contained data. This data might have been deleted. Since Oracle knows that blocks beyond the high water mark don't have data, it only reads blocks up to the high water mark when doing a full table scan.
i) Gather table stats:
To check exact difference in table actual size (dba_segments) and stats size (dba_tables). The difference between these value will report actual fragmentation to DBA. So, We have to have updated stats on the table stored in dba_tables. Check LAST_ANALYZED value for table in dba_tables. If this value is recent you can skip this step. Other wise i would suggest to gather table stats to get updated stats.
exec dbms_stats.gather_table_stats('&schema_name','&table_name');
ii) Check Table size:
Now again check table size using and will find reduced size of the table.
select table_name,bytes/(1024*1024*1024)
from dba_table
where table_name='&table_name';
iii) Check for Fragmentation in table:
If you find reclaimable space % value more than 20% then we can expect fragmentation in the table.
SQL> select owner,
table_name,
round((blocks * 8), 2) || 'kb' "Fragmented size",
round((num_rows * avg_row_len / 1024), 2) || 'kb' "Actual size",
round((blocks * 8), 2) - round((num_rows * avg_row_len / 1024), 2) || 'kb',
((round((blocks * 8), 2) - round((num_rows * avg_row_len / 1024), 2)) /
round((blocks * 8), 2)) * 100 - 10 "reclaimable space % "
from dba_tables
where table_name = '&table_Name'
AND OWNER LIKE '&schema_name';
/
We have three options to reorganize fragmented tables:
1. Alter table move and rebuild indexes
(Depends upon the free space available in the tablespace)
2. Export and import the table
3. Shrink command
(Shrink command is only applicable for tables which are tablespace with auto segment space management)
No comments:
Post a Comment