Master Note:Online Redefinition of Tables (DBMS_REDEFINITION)_1357825.1

rongshiyuan發表於2014-08-24

Master Note:Overview of Online Redefinition of Tables (DBMS_REDEFINITION) (Doc ID 1357825.1)



In this Document

Purpose
Scope
Details
  I) TASK OVERVIEW
  II) TASK EXAMPLES (HOW TO)
 
Examples Of The Use Of Dbms_redefinition
  III) TROUBLESHOOTING

References

Applies to:

Oracle Database - Enterprise Edition - Version 9.0.1.0 and later
Information in this document applies to any platform.

Purpose

The purpose of this bulletin is to give a broad overview of the use of DBMS_REDEFINITION to redefine tables while online (accessible to users for selects as well as insert/update/deletes etc).   

Scope

This bulletin is for experienced database administrators (DBAs).

Details

I) TASK OVERVIEW

DBMS_REDEFINITION is an extremely powerful package that is used to 'online redefine' tables

  Online redefinition of a table means that changes (inserts / updates / deletes / merges) can be made to the table while changes to the data are being made

 

DBMS_REDEFINITION uses Materialized View (MVIEW) technology in order to online redefine tables

DBMS_REDEFINITION.START_REDEF_TABLE -

* Initially instantiates the interim table as a fast refresh MVIEW
* Loads the data from the original table into the interim table
* A materialized view log is created on the original table if one does not already exist

DBMS_REDEFINITION.SYNC_INTERIM_TABLE - Performs a fast refresh on the MVIEW (original -> interim tables)

DBMS_REDEFINITION.FINISH_REDEF_TABLE - Peforms

Phase 1 - DBMS_REDEFINITION.SYNC_INTERIM_TABLE ... This brings the interim table as close to curent with the original as possible
Phase 2 - Locks the original table such that no changes can occur during the next phase
Phase 3 - DBMS_REDEFINITION.SYNC_INTERIM_TABLE ... This brings the interim table to curent with the original .. this phase should not take much time as phase 3 just 'synched' the tables
Phase 4 - The interim and original table names are swapped
Phase 5 - The MVIEW is unregistered and if this was the only fast refresh on the table the MVIEW log is dropped
Phase 6 -  The lock on the interim table (former original) is released



THINGS TO CONSIDER WHEN CHOOSING TO REDEFINE A TABLE ONLINE

1) Does the table need to be redefined online?

    Would doing the redefinition offline cause an unacceptable outage?
       if not ... then often it is faster to do the redefintion in a conventional (offline) manner
          (Create table as ... rename ... ALTER TABLE ... MOVE ... import/drop/export ... ETC)
       if so then online redefintion may be the only way to redefine the table

2) Is there sufficient storage space for the original and interim tables to exist at the same time?

   The interim and original tables must exist simultaneously until the redefinition is finished and the interim table is dropped ...
       as such .. there has to be sufficient space in the tablespace(s) to store both tables for this time

3) Online redefinition will often take longer ... sometimes much longer .. than doing a conventional redefinition

     This truly is not a concern as this process leaves the table being redefined accessible at all times except during the finish of the redefinition

This is because in actuality DBMS_REDEFINITION is doing similar operations to the conventional steps as well as the overhead of doing the redefinition online

4) The transaction rate at which the table that is being redefined needs to be considered

     If the transaction rate on the table is so high that the amount of time that consecutive synchronizations of the original and interim table take longer than
         an acceptable outage for the table then the either the transaction rate will need to be throttled before the last synchronization or the table will need to be
         redefined offline

     The reason why consideration needs to be given to the speed of synchronization is finishing the redefinition requires that the table be locked and then another
          synchronize is executed to make sure that all changes to the original table are made to the interim table .. before the tables are swapped

II) TASK EXAMPLES (HOW TO)


GENERAL STEPS TO ONLINE REDEFINE A TABLE

1) Determine if the table to be moved can be redefined online (DBMS_REDEFINITION.CAN_REDEF_TABLE)

2) Create the interim table

The interim table need not be the same 'shape' (have similar structure) as the original table

3) Start the redefinition of the table (DBMS_REDEFINITION.START_REDEF_TABLE)

4) Copy the dependents from the original table to the interim table (DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS)

5) Execute a final synchronization between the original and interim tables (DBMS_REDEFINITION.SYNC_INTERIM_TABLE)

         This step will minimize the amount of time needed to execute the finish of the redefinition

6) Finish the redefinition (DBMS_REDEFINITION.FINISH_REDEF_TABLE)

7) Verify that the redefinition succeeded by comparing the original table (formerly interim) to the interim table (formerly original)

8) Drop the interim table

 


Examples Of The Use Of Dbms_redefinition

 

HOW TO SHRINK A SECUREFILE LOB USING ONLINE REDEFIITION (DBMS_REDEFINITION)? Document 1394613.1
HOW TO ADD (OR DROP) A COLUMN USING DBMS_REDEFINITION - Document 1120704.1
HOW TO MOVE A TABLE TO A NEW/DIFFERENT TABLESPACE WHILE IT IS ONLINE - Document 1357742.1
HOW TO SHRINK A TABLE USING ONLINE REDEFINITION Document 1357878.1
How to Compress a Table While it is Online Document 1353967.1
HOW TO ONLINE CONVERT TO/FROM SECUREFILES FROM/TO BASICFILES Document 728758.1
How to Disassemble (Uncluster / Decluster) Clustered Tables Online Document 807004.1
How to Convert Date Column to Timestamp Using DBMS_REDEFINITION Package? Document 556283.1
HOW TO USE DBMS_REDEFINITION.REGISTER_DEPENDENT_OBJECT Document 1304838.1
How to convert LONG column to CLOB using package DBMS_REDEFINITION Document 251417.1
How To Partition Existing Table Using DBMS_Redefinition Document 472449.1
How To Use DBMS_REDEFINITION Package To Move All the IOTs And QUEUE TABLE To the New Tablespace Document 1296663.1
How To Change the Partition Column Of A Partitioned Table Using DBMS_Redefinition Document 846405.1
How To Encrypt/Rekey a Table for TDE and Avoid the Associated Performance Problems and Locks? Document 848298.1
How To Move SinglePartion Table To A New Tablespace? Document 795893.1
AN EXAMPLE OF A COMPLEX ONLINE TABLE REDEFINITION (DBMS_REDEFINITION) Document 1358236.1

 

III) TROUBLESHOOTING


KNOWN PROBLEMS

Cannot Drop Unused Columns Using dbms_redefinition Without PK And Compressed Table Document 1233204.1
WHY DOES DBMS_REDEFINITION NOT COPY NAMED LOBSEGMENT NAMES? Document 1237593.1
Reorganizing a Table with no Primary Key Using Dbms_redefinition Causes its Size to Increase Document 804575.1
WHY ARE 'NOT NULL' CONSTRAINTS NOT COPIED BY DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS? Document 1089860.1
ORA-1442 DURING DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS Document 1116785.1
ORA-904 DURING DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS Document 837751.1
Online Reorganization for Partition fails with ORA-39726 Document 462783.1
ORA-12091: Cannot Online Redefine Table When Running dbms_redefinition.start_redef_table Document 784086.1
Online Redefinition fails with ora-12015 when calling an external function Document 312010.1

ORA-23413 OR ORA-12034 DURING DBMS_REDEFINITION (Document 1455575.1)


KNOWN BUGS

Bug 5221192 - ORA-01430: column being added already exists in table on DBMS_REDEFINITION Document 1299025.1
Bug 6379441 - ORA-600 [kdlm_merge_lobs:1] When Using DBMW_REFEFINITION On LOB Document 602850.1
Bug 6978410 - Parallel online redefinition of LONG/LOB->Securefile does not work on non-partitioned tables Document 6978410.8
Bug 7007594 - ORA-600 [12261] at DBMS_REDEFINITION.FINISH_REDEF_TABLE of partitioned table Document 7007594.8
Bug 7316385 - DBMS_REDEFINITION.START_REDEF_TABLE Fails ORA-32412 Because Of Encrypted Column Document 1329419.1
Bug 7363460 - After Running DBMS_REDEFINITION.FINISH_REDEF_TABLE Source in DBA_TRIGGERS Has Extra Characters Document 760072.1
Bug 8507266 - DBMS_REDEFINITION needs ANY privileges - cannot be used by normal users Document 8507266.8
Bug 8984274 - ORA-1749 Error Running DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS Document 1345539.1
Bug 9069310 - Table And Column Comments Are Not Copied To The Redefined Table When Using DBMS_REDEFINITION Document 1142595.1
Bug 9103484 - Library cache lock and TM lock not released after ABORT_REDEF_TABLE finished Document 9103484.8
Bug 9375982 - DBMS_REDEFINITION builds target table with PK index with NOPARALLEL option Document 9375982.8
Bug 9777229 - Extra foreign key on child table when child and parent tables are redefined with DBMS_REDEFINITION Document 9777229.8
Bug 10302581 - START_REDEF_TABLE creates index in SYSTEM tablespace Document 10302581.8
Bug 11068025 - DBMS_REDEFINITION Fails To Move Table & Lob Columns If Lob Segment Names Not System Generated Document 1317168.1
Bug 11068025 - DBMS_REDEFINITION.copy_table_dependents fails with ORA-936 when using named LOBs Document 11068025.8
Bug 12765293 - ORA-600 [kkzuord_copycolcomcb.2.prepare] during DBMS_REDEFINITION of table with comments Document 1339277.1

References

NOTE:462783.1 - Online Reorganization for Partition fails with ORA-39726
NOTE:848298.1 - How To Encrypt/Rekey a Table for TDE and Avoid the Associated Performance Problems and Locks?
NOTE:1357878.1 - HOW TO SHRINK A TABLE USING ONLINE REDEFINITION
NOTE:1089860.1 - Why are Not Null Constraints not Copied by Dbms_redefinition.copy_table_dependents?
NOTE:728758.1 - HOW TO ONLINE CONVERT TO/FROM SECUREFILES FROM/TO BASICFILES
NOTE:807004.1 - How to Disassemble (Uncluster / Decluster) Clustered Tables Online
NOTE:795893.1 - How To Move SinglePartion Table To A New Tablespace?
NOTE:1358236.1 - AN EXAMPLE OF A COMPLEX ONLINE TABLE REDEFINITION (DBMS_REDEFINITION)
NOTE:1455575.1 - ORA-23413 OR ORA-12034 DURING DBMS_REDEFINITION
NOTE:1233204.1 - Cannot Drop Unused Columns Using dbms_redefinition Without PK And Compressed Table
NOTE:1237593.1 - Why Does Dbms_redefinition not Copy Named Lobsegment Names
NOTE:556283.1 - How to Convert Date Column to Timestamp Using DBMS_REDEFINITION Package?
NOTE:1394613.1 - How to Shrink a Securefile LOB Using Online Redefinition (DBMS_REDEFINITION)?
NOTE:1304838.1 - HOW TO USE DBMS_REDEFINITION.REGISTER_DEPENDENT_OBJECT
NOTE:1120704.1 - How to Add (or Drop) a Column Using Dbms_redefinition
NOTE:251417.1 - How to Convert LONG Column to CLOB Using DBMS_REDEFINITION Package
NOTE:472449.1 - How To Partition Existing Table Using DBMS_Redefinition
NOTE:1296663.1 - How To Use DBMS_REDEFINITION Package To Move All the IOTs And QUEUE TABLE To the New Tablespace
NOTE:846405.1 - How To Change the Partition Column Of A Partitioned Table Using DBMS_Redefinition
NOTE:784086.1 - Problem: ORA-12091: Cannot Online Redefine Table When Running dbms_redefinition.start_redef_table
NOTE:312010.1 - Online Redefinition fails with ora-12015 when calling an external function

NOTE:1357742.1 - HOW TO MOVE A TABLE TO A NEW/DIFFERENT TABLESPACE WHILE IT IS ONLINE
NOTE:1353967.1 - How to Compress a Table While it is Online
NOTE:1116785.1 - ORA-1442 DURING DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS
NOTE:804575.1 - Reorganizing a Table with no Primary Key Using Dbms_redefinition Causes its Size to Increase
NOTE:837751.1 - ORA-904 DURING DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17252115/viewspace-1256711/,如需轉載,請註明出處,否則將追究法律責任。

相關文章