Quantcast
Channel: Database Administration Tips
Viewing all articles
Browse latest Browse all 214

Rebuild Table Script And Reclaim Wasted Space For Oracle

$
0
0
I have written a powerful script to rebuild a table and its indexes on Oracle, although I'm reluctant to share scripts that deal directly with the data, but thought it will be a great help for DBAs if they use it wisely.

Before you use this script, please read the full post carefully to understand how it works.

First, I'm sharing this script in the hope that it will be helpful for you without any warranty, you have to test the script yourself on a test environment before running against production.

How it works:

The script can rebuild one table and its indexes at a time, once you enter the OWNER and TABLE_NAME it will do the following:

In A Nutshell, It will check the available options for rebuilding the table:
Option 1: Will check if DBMS_REDEFINITION package can be used based on the database edition (Standard/Enterprise) and then take the user through the rest of the steps.

Option 2: If DBMS_REDEFINITION is not available in the current edition or the user didn't wish to proceed with DBMS_REDEFINITION, the script will move to ALTER TABLE MOVE option, if the database version is 12.2 or higher, the script will utilize "ALTER TABLE MOVE ONLINE" command which will rebuild the table with a negligible downtime, otherwise it will use "ALTER TABLE MOVE" command which will result in downtime on the table throughout the whole rebuild operation.

The following flowchart will explain the mechanism of the script in details: [I'm grateful to draw.io for making the drawing of this flowchart easy and free of cost for me]



If you are still confused, read the script prompted messages carefully and it will explain itself.

Here is the download link:
https://www.dropbox.com/s/bmgbc0u76okokcs/rebuild_table.sh?dl=0

In case the download link is broken you can copy the script from the below GitHub version:


Viewing all articles
Browse latest Browse all 214

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>