Oracle在线重定义之DBMS_REDEFINITION
11g官方文档关于DBMS_REDEFINITION的详细说明:
******************************************************************************************************
UsingDBMS_REDEFINITION· Overview
· Constants
· Operational Notes
Overview
To achieve onlineredefinition, incrementally maintainable local materialized views are used.These logs keep track of the changes to the master tables and are used by thematerialized views during refresh synchronization.
为了实现在线重新定义,使用使用本地物化视图。 这些日志将跟踪主表的更改,并在刷新同步期间由物化视图使用。
Constants
TheDBMS_REDEFINITIONpackage uses the constants shown inTable 110-1, "DBMS_REDEFINITION Constants":
Table 110-1DBMS_REDEFINITION Constants
Constant
Type
Value
Description
CONS_CONSTRAINT
PLS_INTEGER
3
Used to specify that dependent object type is a constraint
CONS_INDEX
PLS_INTEGER
2
Used to specify that dependent object type is a index
CONS_MVLOG
PLS_INTEGER
10
Used to (un)register a materialized view log, as a dependent object of the table, through theREGISTER_DEPENDENT_OBJECT Procedureand theUNREGISTER_DEPENDENT_OBJECT Procedure.
CONS_ORIG_PARAMS
PLS_INTEGER
1
Used to specify that indexes should be cloned with their original storage parameters
CONS_TRIGGER
PLS_INTEGER
4
Used to specify that dependent object type is a trigger
CONS_USE_PK
BINARY_INTEGER
1
Used to indicate that the redefinition should be done using primary keys or pseudo-primary keys (unique keys with all component columns having not-NULLconstraints)
CONS_USE_ROWID
BINARY_INTEGER
2
Used to indicate that the redefinition should be done using rowids
Operational Notes
·CONS_USE_PKandCONS_USE_ROWIDare constants used as input to the "options_flag"parameter in both theSTART_REDEF_TABLE ProcedureandCAN_REDEF_TABLE Procedure.CONS_USE_ROWIDis used to indicate that the redefinition should be done usingrowids whileCONS_USE_PKimplies that the redefinition should be done using primary keysor pseudo-primary keys (which are unique keys with all component columns havingNOTNULLconstraints).
CONS_USE_PK和CONS_USE_ROWID是用作START_REDEF_TABLE过程和CAN_REDEF_TABLE过程中“options_flag”参数的输入的常量。 CONS_USE_ROWID用于指示重新定义应使用rowid完成,而CONS_USE_PK意味着重新定义应该使用主键或伪主键(这是所有组件列具有NOT NULL约束的唯一键)来完成。
·CONS_INDEX,CONS_MVLOG,CONS_TRIGGERandCONS_CONSTRAINTare used to specify the type of the dependent object being (un)registeredinREGISTER_DEPENDENT_OBJECT ProcedureandUNREGISTER_DEPENDENT_OBJECT Procedure(parameter "dep_type").
CONS_INDEX,CONS_MVLOG,CONS_TRIGGER和CONS_CONSTRAINT用于指定在REGISTER_DEPENDENT_OBJECT过程和UNREGISTER_DEPENDENT_OBJECT过程(参数“dep_type”)中注册的依赖对象的类型。
CONS_INDEX==> dependent object is of typeINDEX
CONS_TRIGGER==> dependent object is of typeTRIGGER
CONS_CONSTRAINT==>dependent object type is of typeCONSTRAINT
CONS_MVLOG==> dependent object is of typeMATERIALIZEDVIEWLOG
·CONS_ORIG_PARAMSas used as input to the "copy_indexes"parameter inCOPY_TABLE_DEPENDENTS Procedure. Using thisparameter implies that the indexes on the original table be copied onto theinterim table using the same storage parameters as that of the original index.
作为COPY_TABLE_DEPENDENTS过程中“copy_indexes”参数的输入的CONS_ORIG_PARAMS。 使用此参数意味着使用与原始索引相同的存储参数将原始表上的索引复制到临时表上。
Rules and Limits
For information aboutvarious rules and limits that apply to implementation of this package, see theOracle Database Administrator'sGuide.
Summary ofDBMS_REDEFINITION Subprograms
Table 110-2DBMS_REDEFINITION Package Subprograms
Subprogram
Description
ABORT_REDEF_TABLE Procedure
Cleans up errors that occur during the redefinition process and removes all temporary objects created by the reorganization process
CAN_REDEF_TABLE Procedure
Determines if a given table can be redefined online
COPY_TABLE_DEPENDENTS Procedure
Copies the dependent objects of the original table onto the interim table
FINISH_REDEF_TABLE Procedure
Completes the redefinition process.
REGISTER_DEPENDENT_OBJECT Procedure
Registers a dependent object (index, trigger, constraint or materialized view log) on the table being redefined and the corresponding dependent object on the interim table
START_REDEF_TABLE Procedure
Initiates the redefinition process
SYNC_INTERIM_TABLE Procedure
Keeps the interim table synchronized with the original table
UNREGISTER_DEPENDENT_OBJECT Procedure
Unregisters a dependent object (index, trigger, constraint or materialized view log) on the table being redefined and the corresponding dependent object on the interim table
ABORT_REDEF_TABLEProcedure
This procedure cleansup errors that occur during the redefinition process. This procedure can alsobe used to terminate the redefinition process any time after theSTART_REDEF_TABLE Procedurehas been called and before theFINISH_REDEF_TABLE Procedureis called. This process will removethe temporary objects that are created by the redefinition process such asmaterialized view logs.
此过程可以清除在重新定义过程中发生的错误。 此过程也可以在START_REDEF_TABLE程序被调用之后和调用FINISH_REDEF_TABLE过程之前的任何时候用于终止重新定义过程。 此过程将删除由重定义过程创建的临时对象,例如物化视图日志。
Syntax
DBMS_REDEFINITION.ABORT_REDEF_TABLE (
uname IN VARCHAR2,
orig_table IN VARCHAR2,
int_table IN VARCHAR2,
part_name IN VARCHAR2 := NULL);
Parameters
Table 110-3ABORT_REDEF_TABLE Procedure Parameters
Parameter
Description
uname
Schema name of the tables
orig_table
Name of the table to be redefined
int_table
Name of the interim table
part_name
Name of the partition being redefined. If redefining only a single partition of a table, specify the partition name in this parameter.NULLimplies the entire table is being redefined.
CAN_REDEF_TABLEProcedure
This proceduredetermines if a given table can be redefined online. This is the first step ofthe online redefinition process. If the table is not a candidate for onlineredefinition, an error message is raised.
此过程确定给定的表是否可以在线重新定义。 这是在线重新定义过程的第一步。 如果表不是在线重新定义的候选者,则会出现错误消息。
Syntax
DBMS_REDEFINITION.CAN_REDEF_TABLE (
uname IN VARCHAR2,
tname IN VARCHAR2,
options_flag IN PLS_INTEGER := 1,
part_name IN VARCHAR2 := NULL);
Parameters
Table 110-4CAN_REDEF_TABLE Procedure Parameters
Parameter
Description
uname
Schema name of the table
tname
Name of the table to be re-organized
options_flag
Indicates the type of redefinition method to use.
· Ifdbms_redefinition.cons_use_pk, the redefinition is done using primary keys or pseudo-primary keys (unique keys with all component columns havingNOTNULLconstraints). The default method of redefinition is using primary keys.
· Ifdbms_redefinition.cons_use_rowid, the redefinition is done using rowids.
part_name
Name of the partition being redefined. If redefining only a single partition of a table, specify the partition name in this parameter.NULLimplies the entire table is being redefined.
Exceptions
If the table is not acandidate for online redefinition, an error message is raised.
COPY_TABLE_DEPENDENTSProcedure
This procedure clonesthe dependent objects of the table being redefined onto the interim table andregisters the dependent objects. This procedure does not clone the alreadyregistered dependent objects.
This subprogram is usedto clone the dependent objects like grants, triggers, constraints andprivileges from the table being redefined to the interim table (whichrepresents the post-redefinition table).
此过程克隆表重新定义到临时表上的依赖对象,并注册依赖对象。 此过程不会克隆已注册的从属对象。
该子程序用于将重新定义的表中的依赖对象(如授权,触发器,约束和权限)克隆到临时表(表示后重新定义表)。
Syntax
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS(
uname IN VARCHAR2,
orig_table IN VARCHAR2,
int_table IN VARCHAR2,
copy_indexes IN PLS_INTEGER := 1,
copy_triggers IN BOOLEAN := TRUE,
copy_constraints IN BOOLEAN := TRUE,
copy_privileges IN BOOLEAN := TRUE,
ignore_errors IN BOOLEAN := FALSE,
num_errors OUT PLS_INTEGER,
copy_statistics IN BOOLEAN := FALSE,
copy_mvlog IN BOOLEAN := FALSE);
Parameters
Table 110-5COPY_TABLE_DEPENDENTS Procedure Parameters
Parameter
Description
uname
Schema name of the tables
orig_table
Name of the table being redefined
int_table
Name of the interim table
copy_indexes
Flag indicating whether to copy the indexes
· 0- do not copy any index
· dbms_redefinition.cons_orig_params– copy the indexes using the physical parameters of the source indexes
copy_triggers
TRUE= clone triggers,FALSE= do nothing
copy_constraints
TRUE= clone constraints,FALSE= do nothing. If compatibility setting is 10.2 or higher, then cloneCHECKandNOTNULLconstraints
copy_privileges
TRUE= clone privileges,FALSE= do nothing
ignore_errors
TRUE= if an error occurs while cloning a particular dependent object, then skip that object and continue cloning other dependent objects.FALSE= that the cloning process should stop upon encountering an error.
num_errors
Number of errors that occurred while cloning dependent objects
copy_statistics
TRUE= copy statistics,FALSE= do nothing
copy_mvlog
TRUE= copy materialized view log,FALSE= do nothing
Usage Notes
·The user must check the columnnum_errorsbefore proceeding to ensure that no errors occurred during thecloning of the objects.
·In case of an error, the user should fix the cause of the errorand call theCOPY_TABLE_DEPENDENTS Procedureagain to clone the dependent object.Alternatively the user can manually clone the dependent object and thenregister the manually cloned dependent object using theREGISTER_DEPENDENT_OBJECT Procedure.
·All cloned referential constraints involving the interim tableswill be created disabled (they will be automatically enabled after theredefinition) and all triggers on interim tables will not fire till theredefinition is completed. After the redefinition is complete, the clonedobjects will be renamed to the corresponding pre-redefinition names of theobjects (from which they were cloned from).
·It is the user's responsibility that the cloned dependentobjects are unaffected by the redefinition. All the triggers will be cloned andit is the user's responsibility that the cloned triggers are unaffected by theredefinition.
?用户必须先检查列num_errors,然后继续确保克隆对象期间不会发生错误。
?如果发生错误,用户应该修复错误的原因并再次调用COPY_TABLE_DEPENDENTS过程来克隆依赖对象。或者,用户可以手动克隆依赖对象,然后使用REGISTER_DEPENDENT_OBJECT过程注册手动克隆的依赖对象。
?涉及临时表的所有克隆参照约束将被禁用(重定义后将自动启用),并且临时表上的所有触发器都不会触发,直到重新定义完成。重新定义完成后,克隆的对象将被重命名为对象的重新定义名称(从中克隆到它们)。
?用户有责任克隆的依赖对象不受重新定义的影响。所有的触发器将被克隆,用户有责任克隆的触发器不受重新定义的影响。
FINISH_REDEF_TABLE Procedure
This procedurecompletes the redefinition process. Before this step, you can create newindexes, triggers, grants, and constraints on the interim table. Thereferential constraints involving the interim table must be disabled. Aftercompleting this step, the original table is redefined with the attributes anddata of the interim table. The original table is locked briefly during thisprocedure.
此过程完成重新定义过程。 在此步骤之前,您可以在临时表上创建新的索引,触发器,授予和约束。 必须禁用涉及临时表的参照约束。 完成此步骤后,原始表格将重新定义为临时表格的属性和数据。 在此过程中,原始表被短暂锁定。
Syntax
DBMS_REDEFINITION.FINISH_REDEF_TABLE (
uname IN VARCHAR2,
orig_table IN VARCHAR2,
int_table IN VARCHAR2,
part_name IN VARCHAR2 := NULL);
Parameters
Table 110-6FINISH_REDEF_TABLE Procedure Parameters
Parameters
Description
uname
Schema name of the tables
orig_table
Name of the table to be redefined
int_table
Name of the interim table
part_name
Name of the partition being redefined. If redefining only a single partition of a table, specify the partition name in this parameter.NULLimplies the entire table is being redefined.
REGISTER_DEPENDENT_OBJECTProcedure
This procedureregisters a dependent object (index, trigger, constraint or materialized viewlog) on the table being redefined and the corresponding dependent object on theinterim table.
此过程在重新定义的表上注册依赖对象(索引,触发器,约束或物化视图日志),并在临时表上注册相应的依赖对象。
This can be used tohave the same object on each table but with different attributes. For example:for an index, the storage and tablespace attributes could be different but thecolumns indexed remain the same
这可以用于在每个表上具有相同的对象,但具有不同的属性。 例如:对于索引,存储和表空间属性可能不同,但索引的列保持不变
Syntax
DBMS_REDEFINITION.REGISTER_DEPEPENDENT_OBJECT(
uname IN VARCHAR2,
orig_table IN VARCHAR2,
int_table IN VARCHAR2,
dep_type IN PLS_INTEGER,
dep_owner IN VARCHAR2,
dep_orig_name IN VARCHAR2,
dep_int_name IN VARCHAR2);
Parameters
Table 110-7REGISTER_DEPENDENT_OBJECT Procedure Parameters
Parameters
Description
uname
Schema name of the tables
orig_table
Name of the table to be redefined
int_table
Name of the interim table
dep_type
Type of the dependent object (seeConstantsandOperational Notes)
dep_owner
Owner of the dependent object
dep_orig_name
Name of the original dependent object
dep_int_name
Name of the interim dependent object
Usage Notes
·Attempting to register an already registered object will raisean error.
·Registering a dependent object will automatically remove thatobject fromDBA_REDEFINITION_ERRORSif an entry exists for that object.
?尝试注册已注册的对象会引发错误。
?如果该对象存在条目,则注册依赖对象将自动从DBA_REDEFINITION_ERRORS中删除该对象。
START_REDEF_TABLEProcedure
Prior to calling thisprocedure, you must manually create an empty interim table (in the same schemaas the table to be redefined) with the desired attributes of thepost-redefinition table, and then call this procedure to initiate theredefinition.
在调用此过程之前,你必须手动创建一个空的临时表(与要重新定义的表相同的模式)与所需的后重新定义表的属性,然后调用此过程来启动重定义。
Syntax
DBMS_REDEFINITION.START_REDEF_TABLE (
uname IN VARCHAR2,
orig_table IN VARCHAR2,
int_table IN VARCHAR2,
col_mapping IN VARCHAR2 := NULL,
options_flag IN BINARY_INTEGER := 1,
orderby_cols IN VARCHAR2 := NULL,
part_name IN VARCHAR2 := NULL);
Parameters
Table 110-8START_REDEF_TABLE Procedure Parameters
Parameter
Description
uname
Schema name of the tables
orig_table
Name of the table to be redefined
int_table
Name of the interim table
col_mapping
Mapping information from the columns in the original table to the columns in the interim table. (This is similar to the column list on theSELECTclause of a query.) IfNULL,all the columns in the original table are selected and have the same name after redefinition.
options_flag
Indicates the type of redefinition method to use:
· Ifdbms_redefinition.cons_use_pk, the redefinition is done using primary keys or pseudo-primary keys (unique keys with all component columns havingNOTNULLconstraints). The default method of redefinition is using primary keys.
· Ifdbms_redefinition.cons_use_rowid, the redefinition is done using rowids.
orderby_cols
This optional parameter accepts the list of columns (along with the optional keyword(s) ascending/descending) with which to order by the rows during the initial instantiation of the interim table (the order by is only done for the initial instantiation and not for subsequent synchronizations)
part_name
Name of the partition being redefined. If redefining only a single partition of a table, specify the partition name in this parameter.NULLimplies the entire table is being redefined.
SYNC_INTERIM_TABLEProcedure
This procedure keepsthe interim table synchronized with the original table.
此过程使临时表与原始表同步。
Syntax
DBMS_REDEFINITION.SYNC_INTERIM_TABLE (
uname IN VARCHAR2,
orig_table IN VARCHAR2,
int_table IN VARCHAR2,
part_name IN VARCHAR2 := NULL);
Parameters
Table 110-9SYNC_INTERIM_TABLE Procedure Parameters
Parameter
Description
uname
Schema name of the table
orig_table
Name of the table to be redefined
int_table
Name of the interim table
part_name
Name of the partition being redefined. If redefining only a single partition of a table, specify the partition name in this parameter.NULLimplies the entire table is being redefined.
Usage Notes
·This step is useful in minimizing the amount of synchronizationneeded to be done by theFINISH_REDEF_TABLE Procedurebefore completing the onlineredefinition.
·This procedure can be called between long running operations(such asCREATEINDEX) on theinterim table to sync it up with the data in the original table and speed upsubsequent operations.
?在完成在线重新定义之前,此步骤对于最小化FINISH_REDEF_TABLE过程需要完成的同步量很有用。
?可以在临时表上的长时间运行操作(如CREATE INDEX)之间调用此过程,以将其与原始表中的数据进行同步,并加快后续操作。
UNREGISTER_DEPENDENT_OBJECTProcedure
This procedureunregisters a dependent object (index, trigger, constraint or materialized viewlog) on the table being redefined and the corresponding dependent object on theinterim table.
此过程在重新定义的表上取消注册依赖对象(索引,触发器,约束或物化视图日志),并在临时表上注销相应的依赖对象。
Syntax
DBMS_REDEFINITION.UNREGISTER_DEPEPENDENT_OBJECT(
uname IN VARCHAR2,
orig_table IN VARCHAR2,
int_table IN VARCHAR2,
dep_type IN PLS_INTEGER,
dep_owner IN VARCHAR2,
dep_orig_name IN VARCHAR2,
dep_int_name IN VARCHAR2);
Parameters
Table 110-10UNREGISTER_DEPENDENT_OBJECT Procedure Parameters
Parameters
Description
uname
Schema name of the tables
orig_table
Name of the table to be redefined
int_table
Name of the interim table
dep_type
Type of the dependent object
dep_owner
Owner of the dependent object
dep_orig_name
Name of the original dependent object
dep_int_name
Name of the interim dependent object
作者:SEian.G(苦练七十二变,笑对八十一难)
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。