15 thoughts on “Rebuild Table Online Script And Claim Space In Oracle”

  1. Amazing script but it misses to send the DBA an email confirmation when the rebuild complete.

  2. Actually it will write a message to the alertlog starting with ORA-NOTIFICATION… indicating the completion of the rebuild operation or requesting the DBA to complete the final step of the rebuild by running specific command manually, in case you are monitoring your alert log for "ORA-" errors via a script or a tool, it will catch that message and you will get informed. This is why I started this notification message with "ORA-".

  3. The script works fine but I'm getting this error:

    [Calculating Table Size] …
    awk: BEGIN {print 88 + 12:20:04 + 6}
    awk: ^ syntax error
    [TABLE & INDEXES SIZE: MB]
    awk: BEGIN {print * 1.25}
    awk: ^ syntax error

    The rest of script is fine.

  4. I can see the value of indexes size was translated to "12:20:04" which caused this error, I'm not sure how this value get picked up!
    I've received your Email as well and replied you with specific lines to add to the script it will help me understand how the indexes size got that wrong value, please run the script one more time after the modification and share the output with me.

  5. hello,
    while I'm rebuilding one table using your script it showed the new rebuilded table with bigger size than the original fragmented table, how this happen?

    Running a COMPARISON between the OLD and NEW TABLE:
    ***************************************************

    TABLES:
    —–

    Table Name TABLESPACE_NAME EXTENTS COMPRESS READONLY SIZE_MB
    ———————————– ——————– ———- ——– ——– ———- ORIGINAL_TABLE: ZX_LINES_DET_FACTORS APPS_TS_TX_DATA 84474 DISABLED NO 10549
    NEW_TABLE: ZX_LINES_DET_FACTORS_XNT APPS_TS_TX_DATA 88905 DISABLED NO 11102

    ORIGINAL_TABLE NUMBER OF ROWS: 12045445
    NEW_TABLE NUMBER OF ROWS: 12045445

  6. Sorry, outputs scrambled:

    Table Name SIZE_MB
    ORIGINAL_TABLE: ZX_LINES_DET_FACTORS 10549
    NEW_TABLE: ZX_LINES_DET_FACTORS_XNT 11102

  7. Thanks for the clear description.

    Actually, most of the time fragmented tables will not show their accurate size, it's something wrong with the data which DBA_SEGMENTS fetches, and by the way I'm not concerned here about the table size before the rebuild as I'm concerned about how much of MBs got freed up on the tablespace hosting that table after the rebuild and after dropping the interim table, if you compare the size of that tablespace before and after rebuilding the table, you will find a big space gain after dropping the old fragmented table: SQL> drop table .ZX_LINES_DET_FACTORS_XNT purge;

    Please let me know how much space got freed up on the hosting tablespace after the rebuild.

  8. yes you were right, comparing the tablespace size before and after I can see more than 60Gig of space been claimed after dropping the interim table.
    Thanks to you for the help.

  9. Thanks, I was looking for such a script very long time. I did it always manually, step by step. Are you planning to add rebuild to another tablespace ? Thanks again

  10. Hi Darko,

    For rebuilding the table to another tablespace this feature is added in the coming release for both "ALTER TABLE MOVE" and "ALTER TABLE MOVE ONLINE" options; I'll publish it shortly. But for DBMS_REDEFINITION this feature is not available in DB versions older than 12c, for 12c the steps has changed entirely and this needs a radical change in the script, if I find time I'll include this feature for 12c.
    But if your DB is 12c or higher I would recommend you to go with "ALTER TABLE REBUILD ONLINE" feature which will rebuild the table with minimal downtime as well.

  11. While the script accept using dbms_redefinition it moves to 'alter table move' option

    Do you want to use DBMS_REDEFINITION for ONLINE Table REBUILD with a MINIMAL DOWNTIME on the table? [Y|N] Y
    ===================================================================================================
    Enter NO in case you want to use ALTER TABLE MOVE option.

    INFO: Current PCTFREE: 10
    INFO: Number of "UPDATE" transactions on the table since the last Statistics Gather on []: 0

    Specify the table PCTFREE after the rebuild: [How much %Free space will be left in each block for future updates | Current 10%]
    ===========================================
    Note: The SMALLER the PCTFREE the SMALLER the table size after the rebuild. [Recommended for Archival/Datawarehouse Tables]
    Note: If the table is highly updated it's recommended to keep the current PCTFREE: 10
    Leave it BLANK and hit Enter to keep the default PCTFREE.

    Moving to "ALTER TABLE MOVE" Option.

    [Table [ra.GG_TEST_TAB2] Contains UN-SUPPORTED "LONG" DATA TYPE for "ALTER TABLE MOVE" operation.]

    Script Terminated!

    what is wrong?

  12. Your table has one or more columns with LONG data type. None of the rebuild options will be able to rebuild that table unless you change the data type from LONG to CLOB

    e.g.
    alter table ra.GG_TEST_TAB2 modify column1 CLOB;

Leave a Reply

Your email address will not be published. Required fields are marked *