Oracle: lower table high water mark tips

 Question:  I have deleted rows from a large table, but the space has not been released.  What are the different ways that I can lower the table high-water mark and release the disk space to be reused by another table?

Answer:  You are correct, when rows are deleted from a tables, Oracle does not release the free space for other tables, and you must explicitly lower the table high-water mark. 

Oracle leaves the high-water mark alone after rows are deleted, and you can reclaim space at the table level with these techniques, all of which lower the high water mark for the table, thereby freeing-up the space:

  • export-import - For a complete reorganization and space reclamation, export/import allows you to restructure your files and reclaim lost space.
     

  • dbms_redefinition - This procedure will reorganize a table while it remains online for updates.
     

  • "alter table xxx shrink" - - If you were 10g and beyond you could use "alter table xxx shrink space compact;" syntax.

  • You can look at the coalesce table syntax.  Unlike the "deallocate unused space" syntax which removes space above the high-water mark, "coalesce" puts together discontiguous fragmented extents.  There are two type of space fragmentation in Oracle.  First is the honeycomb fragmentation, when the free extents are side by side, and the "Swiss Cheese" fragmentation, when the extents are separated by live segments.
     
    alter table xxx coalesce;

  • You can deallocate unused space - Oracle notes that the "deallocate unused space" clause is used to to explicitly deallocate unused space at "the end" of a segment and makes that space available for other segments within the tablespace. 
     
    alter table xxx deallocate unused space;
    alter index xxx deallocate unused space;

     
    Internally, Oracle deallocates unused space beginning from the end of the objects (allocated space) and moving downwards toward the beginning of the object, continuing down until it reaches the high water mark (HWM).  

  • For indexes, "deallocate unused space" coalesces all leaf blocks within same branch of b-tree, and quickly frees up index leaf blocks for use.

  •  अनुक्रमितों के लिए, "अप्रयुक्त स्थान को निपटाएं" बी-पेड़ की एक ही शाखा के भीतर सभी पत्ती ब्लॉकों को समेटता है, और उपयोग के लिए जल्दी से सूचकांक पत्ती ब्लॉकों को मुक्त करता है।

Comments

Popular posts from this blog

Table high water mark tips

Create table of two consecutive months if date range belong to two months

Fill null values with last non-null amount - Oracle SQL