Reorganize Oracle Tables To Reduce Disk IO
Reorganize Oracle Tables To Reduce Disk IO
Alireza Kamrani
06/24/2024
Reorganizing Oracle tables can be an e ective way to reduce disk I/O and improve database
performance. Here are some steps you can take to reorganize Oracle tables:
1. Analyze the tables: Use the Oracle Analyze command or the Automatic Workload Repository
(AWR) to collect statistics on the tables, including their size, row count, and distribution of
data. This will help you identify which tables are most in need of reorganization.
2. Determine the fragmentation level: Check the fragmentation level of the tables by running
queries that show the number of free blocks and the average row length. This will help you
identify which tables are most fragmented and require reorganization.
3. Choose a reorganization method: There are several methods for reorganizing Oracle tables,
including Export/Import, ALTER TABLE MOVE, and CTAS (Create Table As Select). Each
method has its own advantages and disadvantages, and the best method will depend on the
speci c needs and requirements of your database.
4. Create temporary tables: Before reorganizing a table, create temporary tables to store the
data. This will help ensure that no data is lost during the reorganization process.
5. Reorganize the tables: Use the chosen method to reorganize the tables, moving the data to a
new tablespace or segment, or creating a new table with the same data.
6. Update indexes and constraints: After reorganizing the tables, you will need to update the
indexes and constraints to re ect the new table structure.
7. Test the performance: After reorganizing the tables, test the performance of the database to
ensure that the reorganization has reduced disk I/O and improved overall performance.
By following these steps, you can reorganize Oracle tables to reduce disk I/O and improve
database performance. However, it's important to plan and test the reorganization carefully to
ensure that it meets the needs of the database and does not introduce any new performance or
stability issues.
Also yos can use DBMS_REDEFINITION package that have some good options to restructure
your table, such as partitioning of a nonpartition table, reoder columns, compression,change
storage parameters of table/index, shrink,...
so after REDEFINITION your table segmenets will be recreated and wasted space is minimal, this
operation is Online.
-- MODIFY THE LOB TO NOT USE RETENTION OR PCTVERSION (ie remove consistent read
copies)
commit;
declare
tmp_blob blob default EMPTY_BLOB();
tmp_b le b le:=null;
dest_o set integer:=1;
src_o set integer:=1;
begin
select b_ le into tmp_b le from test_b le;
DBMS_LOB.OPEN (tmp_b le, DBMS_LOB.FILE_READONLY);
dbms_lob.createtemporary(tmp_blob, TRUE);
COMMIT;
ff
ff
fi
ff
fi
fi
fi
fi
fi
fi
fi
fi
fi
fi
ff
-- DEMONSTRATE THAT ALTER TABLE ... SHRINK SPACE CASCADE ... DOES NOT WORK
WITH SECUREFILE LOBS
SET SERVEROUTPUT ON
BEGIN
DBMS_REDEFINITION.CAN_REDEF_TABLE('TEST','TEST',
DBMS_REDEFINITION.CONS_USE_ROWID);
END;
/
BEGIN
DBMS_REDEFINITION.START_REDEF_TABLE(
uname => 'TEST',
orig_table => 'TEST',
int_table => 'INTERIM',
options_ ag => DBMS_REDEFINITION.CONS_USE_ROWID);
END;
/
exec DBMS_REDEFINITION.FINISH_REDEF_TABLE('TEST','TEST','INTERIM');
NOTE: The new SECUREFILE LOB has 41 extents whereas the original has 57 extents ... thus
the segment has been shrunk.
Regards,
Alireza Kamrani.
06/24/2024