Search code examples
oracleperformancepartition

Oracle 12c: Wasted Disk Space and Performance


The nature of my application involves daily deleting and bulk inserting of large datasets into an Oracle 12c database. My tables are interval-partitioned by a date field and partitioned-indexed. I use a stored procedure to gather statistics for the affected partitions after each run. Lately, I found that the runs have been slowing down considerably and was wondering if this was due to the increasing size of the database.

I have searched for how to calculate the total disk space that my tables use and usually arrive at this:

select sum(bytes)/1024/1024/1024 
from dba_segments 
where owner='SCHEMA' and segment_name in ('TABLE_A', 'TABLE_B');

However, the numbers were huge and do not reflect the actual data volume used. When we exported the tables for restoration to another database, the file was much smaller than that query suggests. I dug deeper and arrived at this query instead:

select partition_name, 
       blocks*8/1024 size_m, 
       num_rows*avg_row_len/1024/1024 occ_m, 
       blocks*8/1024 - num_rows*avg_row_len/1024/1024 wast_m 
from dba_tab_partitions 
where table_name='TABLE_A'; 

This query suggests that there is a "wasted" space concept where after performing bulk inserts and deleting the data before it is replaced again, the space used is not reclaimed.

Thus I have the following questions:

  1. Does the "wasted" space contribute to performance degradation when I perform delete from table where ..?
  2. Is there a difference between performing a delete from table where .. as compared to dropping the partitions with regard to "wasted" space?
  3. Is performing table reorganization / defragmentation on a regular basis to reclaim table space a recommended practice?

Solution

  • Does the "wasted" space contribute to performance degradation when I perform delete from table where ..?

    Yes, you are deleting from table Oracle has to to perform Full Tabl Scan/Index Range Scan(Index leaf node may lead to empty blocks) on the underlying table up to High Water Mark, which makes your delete slow.

    Is there a difference between performing a delete from table where .. as compared to dropping the partitions with regard to "wasted" space?

    Deleting is a slow process. It has to create before images(undo), update indexes, write redo logs and remove the data. Since DDL(Drop) doesnt generate redo/undo(Generate tiny bit of undo/redo for meta data) it would be faster than DML(delete).

    Is performing table reorganization/defragmentation on a regular basis to reclaim table space a recommended practice?

    Objects with fragmented free space can result in much wasted space, and can impact database performance. The preferred way to defragment and reclaim this space is to perform an online segment shrink.

    For details:Reclaiming Unused Space

    The following blog post demostrate the performance impact during DML becuase of wasted space and how to get rid of it.

    Defragmentation Can Degrade Query Performance