【TABLE】oracle表線上重定義注意事項

xysoul_雲龍發表於2017-06-10

點選(此處)摺疊或開啟

  1. DBMS_REDEFINITION
  2. ==================

  3. With DBMS_REDEFINITION, you can perform an online reorganization of tables. To
  4. achieve this online reorganization, incrementally maintainable local
  5. materialized views are used. Snapshot logs need to be defined on the master
  6. tables to support incrementally maintainable materialized views. These logs
  7. keep track of the changes to the master tables and are used by the materialized
  8. views during refresh synchronization. To keep table indexes and privileges you must use the
  9. copy_table_dependents procedure.

此處需要注意,如果想改變表的索引、許可權,必須執行過程DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS



下面是無法使用線上重定義的一些情況:


點選(此處)摺疊或開啟

  1. Tables with the following characteristics cannot be redefined online:
  2.   - [9.0.1]Tables with no primary keys
  3.   - Tables that have materialized view logs defined on them
  4.   - [9i] Tables that are materialized view container tables and AQ tables
  5.   - [10g] Tables that are replicated in an n-way master configuration can
  6.     be redefined, but horizontal subsetting (subset of rows in the table),
  7.     vertical subsetting (subset of columns in the table), and column
  8.     transformations are not allowed.
  9.   - The overflow table of an IOT table
  10.   - Tables with fine-grained access control (row-level security)
  11.   - Tables with BFILE columns
  12.   - Tables with LONG columns can be redefined online, but those columns must be --注意LOB相關表,LONG型別必須轉換為CLOBS. LONG RAW=>BLOBS
  13.     converted to CLOBS. Also, LONG RAW columns must be converted to BLOBS.
  14.     Tables with LOB columns are acceptable.
  15.   - Tables in the SYS and SYSTEM schema
  16.   - Temporary tables


其他的一些約束:


點選(此處)摺疊或開啟

  1. Other restrictions:
  2.   - A subset of rows in the table
  3.   - Only simple deterministic expressions, sequences, and SYSDATE can be used
  4.     when mapping the columns in the interim table to those of the original table.
  5.     For example, subqueries are not allowed.
  6.   - If new columns are being added with no column mappings, then they must not
  7.     be declared NOT NULL until the redefinition is complete.
  8.   - There cannot be any referential constraints between the table being redefined
  9.     and the interim table.
  10.   - Table redefinition cannot be done NOLOGGING.
  11.   - [10g] For materialized view logs and queue tables, online redefinition is
  12.     restricted to changes in physical properties.
  13.   - You cannot convert a nested table to a VARRAY.

使用者所需許可權


點選(此處)摺疊或開啟

  1. Privileges Required
  2. ====================
  3. Following privileges are needed to run this package:
  4.   - Execute privilege to DBMS_REDEFINITION
  5.   - Create any table
  6.   - Alter any table
  7.   - Drop any table
  8.   - Lock any table
  9.   - Select any table
  10.   - Create any index
  11.   - Create any trigger

下面是相關包的說明


點選(此處)摺疊或開啟

  1. Summary of DBMS_REDEFINITION Subprograms:
  2. =========================================

  3. CAN_REDEF_TABLE Procedure:
  4. --------------------------
  5. This procedure determines if a given table can be reorganized online. This is
  6. the first step of the online reorganization process. If the table is not a
  7. candidate for online redefinition, an error message is raised.

  8. SYNTAX

  9. DBMS_REDEFINITION.can_redef_table (
  10. uname IN VARCHAR2,
  11. tname IN VARCHAR2);

  12. CAN_REDEF_TABLE Procedure Parameters:

  13. Parameter Description
  14. --------- ------------
  15. uname The schema name of the table.
  16. tname The name of the table to be reorganized.



  17. START_REDEF_TABLE Procedure:
  18. ----------------------------
  19. This procedure initiates the reorganization process. After verifying that the
  20. table can be reorganized online, you create an empty interim table (in the same
  21. schema as the table to be reorganized) with the desired attributes of the
  22. post-reorganization table.

  23. SYNTAX

  24. DBMS_REDEFINITION.start_redef_table (
  25. uname IN VARCHAR2,
  26. orig_table IN VARCHAR2,
  27. int_table IN VARCHAR2,
  28. col_mapping IN VARCHAR2 := NULL);

  29. START_REDEF_TABLE Procedure Parameters:

  30. Parameter Description
  31. ---------- ------------
  32. uname The schema name of the tables.
  33. orig_table The name of the table to be reorganized.
  34. int_table The name of the interim table.
  35. col_mapping The mapping information from the columns in the interim
  36.                    table to the columns in the original table. (This is similar
  37.                    to the column list on the SELECT clause of a query.) If NULL,
  38.                    all the columns in the original table are selected and have
  39.                    the same name after reorganization.

  40. FINISH_REDEF_TABLE Procedure:
  41. ----------------------------
  42. This procedure completes the reorganization process. Before this step you can
  43. create new indexes, triggers, grants, and constraints on the interim table. The
  44. referential constraints involving the interim table must be disabled. After
  45. completing this step, the original table is locked briefly during this
  46. procedure.

  47.  
  48. SYNTAX

  49. DBMS_REDEFINITION.finish_redef_table (
  50. uname IN VARCHAR2,
  51. orig_table IN VARCHAR2,
  52. int_table IN VARCHAR2);

  53. FINISH_REDEF_TABLE Procedure Parameters:

  54. Parameter Description
  55. --------- ------------
  56. uname The schema name of the tables.
  57. orig_table The name of the table to be reorganized.
  58. int_table The name of the interim table.



  59. SYNC_INTERIM_TABLE Procedure:
  60. ----------------------------
  61. This procedure keeps the interim table synchronized with the original table.
  62. This step is useful in minimizing the amount of synchronization needed to be
  63. done by finish_reorg_table before completing the online reorganization. This
  64. procedure can be called between long running operations (such as create index)
  65. on the interim table to sync it up with the data in the original table and
  66. speed up subsequent operations.

  67. SYNTAX

  68. DBMS_REDEFINITION.sync_interim_table (
  69. uname IN VARCHAR2,
  70. orig_table IN VARCHAR2,
  71. int_table IN VARCHAR2);

  72. SYNC_INTERIM_TABLE Procedure Parameters:

  73. Parameters Description
  74. ---------- ------------
  75. uname The schema name of the tables.
  76. orig_table The name of the table to be reorganized.
  77. int_table The name of the interim table.


  78. ABORT_REDEF_TABLE Procedure:
  79. ----------------------------
  80. This procedure cleans up errors that occur during the reorganization process.
  81. This procedure can also be used to abort the reorganization process any time
  82. after start_reorg_table has been called and before finish_reorg_table is called.

  83. SYNTAX

  84. DBMS_REDEFINITION.abort_redef_table (
  85. uname IN VARCHAR2,
  86. orig_table IN VARCHAR2,
  87. int_table IN VARCHAR2);

  88. ABORT_REDEF_TABLE Procedure Parameters:

  89. Parameters Description
  90. ---------- ------------
  91. uname The schema name of the table.
  92. orig_table The name of the table to be reorganized.
  93. int_table The name of the interim table.


  94. If we have an encrypted column which is part of primary key then
  95. follow the steps mentioned in the bug below.

  96. Reference: Bug 6034260 DBMS_REDEFINITION.START_REDEF_TABLE FAILS ORA-32412 BECAUSE
  97. OF ENCRYPTED COLUMN

  98. COPY_TABLE_DEPENDENTS (Procedure)
  99. Copies the dependent objects of the original table to the interim table


  100. COPY_TABLE_DEPENDENTS.dbms_redefinition.copy_table_dependents(
  101. uname IN VARCHAR2,
  102. orig_table IN VARCHAR2,
  103. int_table IN VARCHAR2,
  104. copy_indexes IN PLS_INTEGER := 1,
  105. copy_triggers IN BOOLEAN := TRUE,
  106. copy_constraints IN BOOLEAN := TRUE,
  107. copy_privileges IN BOOLEAN := TRUE,
  108. ignore_errors IN BOOLEAN := FALSE,
  109. num_errors OUT PLS_INTEGER,
  110. copy_statistics IN BOOLEAN := FALSE
  111. copy_mvlog IN BOOLEAN := FALSE);

  112. RELATED DOCUMENTS
  113. -----------------

  114. Oracle9i Database Administrator


可以參考相關文章:
NOTE:1089860.1 - Why are Not Null Constraints not Copied by Dbms_redefinition.copy_table_dependents?
NOTE:807004.1 - How to Disassemble (Uncluster / Decluster) Clustered Tables Online
NOTE:1116785.1 - ORA-1442 Error During Online Redefinition - DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS
NOTE:1170351.1 - Secure file Migration and Accessing securefile metadata information [Video]
NOTE:1233204.1 - Cannot Drop Unused Columns Using dbms_redefinition Without PK And Compressed Table
NOTE:251417.1 - How to Convert LONG Column to CLOB Using DBMS_REDEFINITION Package
NOTE:837751.1 - ORA-904 Error During Online Redefinition - DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS
NOTE:848298.1 - How To Encrypt/Rekey a Table for TDE and Avoid the Associated Performance Problems and Locks?
NOTE:556283.1 - How to Convert Date Column to Timestamp Using DBMS_REDEFINITION Package?

分割槽表參考
How To Partition Existing Table Using DBMS_REDEFINITION (Doc ID 472449.1)


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

相關文章