Anda di halaman 1dari 12

Oracle Table Reorg

By :
Akshay More
1
Contents

 Introduction
 Types of Reorg
 Rebuilding the table
 Export/Import
 Alter table Move
 CTAS method
 shrinking its free space

2
Introduction
 Because they are dynamic, Oracle databases will always fragment over time and
may require a periodic clean-up

 Reorganization is very useful and important tasks DBAs perform in order to


reduce space used by blocks and it also helps in improving the performance of
the Oracle Database.

 It also helps to reduce the fragmentation.

 Reclaiming Unused Space in Datafiles

 There are two types of table reorganization.

 Rebuilding the table by means of recreating it.


 Rebuilding the table by shrinking its free space ( Oracle 10g and up )

3
Types of table reorganization

 Rebuilding the table by means of recreating it


 There are two ways of rebuilding a table by recreating it.
 The first option is to export all the data into a file using the export utility.
After that truncate ( of recreate ) the table and reload the data back into it.
 Another method is moving the table either to another tablespace or within the same
tablespace.

 TYPES-

1.Export/Import
2.Alter table Move
3.CTAS method(Create table table_name2 as Select *from table_name1)

4
Types Rebuilding the table

1.Export/Import-

• The Export and Import utilities provide a simple way for you to transfer data objects
between Oracle databases.
• We can take export backup of table, tablespace or schema.

 STEPS-
• Take export backup of particular Table/schema/tablespace.
expdp system/system directory=<DIR_NAME> dumpfile=<TABLE_NAME>_%U.dmp logfile=<TABLE_NAME>.log
tables=<OWNER>.<TABLE_NAME> EXCLUDE=statistics parallel=40

• Take import of that table/schema/tablespace.


impdp system/system directory=<DIR_NAME> dumpfile=<TABLE_NAME>_%U.dmp logfile=<TABLE_NAME>.log
remap_schema=<OWNER>:<OWNER> table_exists_action=replace parallel=40

• While taking import ,old table remapped by new table.


• Run stale stats.

5
Types Rebuilding the table

Advantages-
•It handle large volume of data
•Easy to use
•Space reclaimed is more

 Disadvantages –
•More downtime required.
•Time consuming process.

6
Types Rebuilding the table
2.Alter table Move-

•In this method moving the table either to another tablespace or within the same tablespace.
•Tablespace should have space equal to or greater than size of table.
•It is good for small table

STEPS-

•Move table parallel in same or different tablespace.


alter table <OWNER>.<TABLE_NAME> move parallel 20;
•Move table no parallel.
alter table <OWNER>.<TABLE_NAME> noparallel;
•Rebuild index parallel.
alter index <OWNER>.< INDEX_NAME> rebuild parallel 60;
Move index no parallel.
alter index <OWNER>.< INDEX_NAME> noparallel;
•Run stale stats

7
Types Rebuilding the table
Advantages-
• Downtime required much less
• Used for small table/schema

 Disadvantages –
• The tablespace needs to be able to store this second copy of the table
• The tables indexes, any depending objects like packages, procedures can
become INVALI D and might need to be rebuild
• There will be a table-level exclusive lock on the table involved. Any application
using that table will be affected by this lock.

8
3.CTAS Method-
• The CTAS statement is one method for reorganizing an Oracle table or moving the
table to another tablespace.
• Instead of spending hours setting up parameter files and job steps, you can copy and
rename the table

 SYNTEX-
create table xxx_new
tablespace new_tablespace_name
storage (initial new_initial next new_next freelists new_freelist_number )
as
select * from xxx
order by primary_index_key_values;

9
Rebuilding the table by shrinking its free space

 Rebuilding the table by shrinking its free space


• Tables can be reorganized online, without affecting the users functionality.
• The table itself must be in an ASMM tablespace
• The table must have row movement enabled.
• At the end of the action a shortt table level lock takes place to adjust the HWM
(Highwater Mark) of the table.

10
Oracle Table Reorg

Reorg of Tablespace

11
Thank You

12

Anda mungkin juga menyukai