首页 > Linux操作系统 > Linux操作系统 > ORACLE 在线重定义
系统中有个别表因为数据量巨大,需要改造成分区表,理所当然的就想到了ORACLE 的在线重定义功能,改功能存在于 9i及以上版本,
然而,在线表格重定义也不是完美无缺的。下面列出了Oracle9i重定义过程的部分限制。
l 你必须有足以维护两份表格拷贝的空间。
l 你不能更改主键栏。
l 表格必须有主键。
l 必须在同一个大纲中进行表格重定义。
l 在重定义操作完成之前,你不能对新加栏加以NOT NULL约束。
l 表格不能包含LONG、BFILE以及用户类型(UDT)。
l 不能重定义链表(clustered tables)。
l 不能在SYS和SYSTEM大纲中重定义表格。
l 不能用具体化视图日志(materialized view logs)来重定义表格;不能重定义含有具体化视图的表格。
l 不能在重定义过程中进行横向分集(horizontal subsetting)。
Restrictions for Online Redefinition of Tables
The following restrictions apply to the online redefinition of tables:
If the table is to be redefined using primary key or pseudo-primary keys (unique keys or constraints with all component columns having not null constraints), then the post-redefinition table must have the same primary key or pseudo-primary key columns. If the table is to be redefined using rowids, then the table must not be an index-organized table.
Tables that are replicated in an n-way master configuration can be redefined, but horizontal subsetting (subset of rows in the table), vertical subsetting (subset of columns in the table), and column transformations are not allowed.
The overflow table of an index-organized table cannot be redefined online independently.
Tables with fine-grained access control (row-level security) cannot be redefined online.
Tables with BFILE columns cannot be redefined online.
Tables with LONG columns can be redefined online, but those columns must be converted to CLOBS. Also, LONG RAW columns must be converted to BLOBS. Tables with LOB columns are acceptable.
On a system with sufficient resources for parallel execution, and in the case where the interim table is not partitioned, redefinition of a LONG column to a LOB column can be executed in parallel, provided that:
The segment used to store the LOB column in the interim table belongs to a locally managed tablespace with Automatic Segment Space Management (ASSM) enabled.
There is a simple mapping from one LONG column to one LOB column, and the interim table has only one LOB column.
In the case where the interim table is partitioned, the normal methods for parallel execution for partitioning apply.
Tables in the SYS and SYSTEM schema cannot be redefined online.
Temporary tables cannot be redefined.
A subset of rows in the table cannot be redefined.
Only simple deterministic expressions, sequences, and SYSDATE can be used when mapping the columns in the interim table to those of the original table. For example, subqueries are not allowed.
If new columns are being added as part of the redefinition and there are no column mappings for these columns, then they must not be declared NOT NULL until the redefinition is complete.
There cannot be any referential constraints between the table being redefined and the interim table.
Table redefinition cannot be done NOLOGGING.
For materialized view logs and queue tables, online redefinition is restricted to changes in physical properties. No horizontal or vertical subsetting is permitted, nor are any column transformations. The only valid value for the column mapping string is NULL.
Tables with materialized view logs defined on them cannot be redefined online.
You can convert a VARRAY to a nested table with the CAST operator in the column mapping. However, you cannot convert a nested table to a VARRAY.
主要有以下步骤
--ORACLE 9i
第一步:
--查看表格是否能够重定义
SQL> exec dbms_redefinition.can_redef_table(uname => 'JUSTONE4',tname => 'LIST_SENDBOX');
第二步:
--建立一个要改造后的重定义的 interm_table 中间表 并开始重定义
SQL> EXEC DBMS_REDEFINITION.start_redef_table(uname => 'JUSTONE4',orig_table => 'LIST_SENDBOX',int_table => 'TMP_LIST_SENDBOX');
--将原有表上的对象重新补充(约束 索引 等等),名字不能和之前的冲突
第三步:
--同步数据 提高 finish_redef 的速度 (可选),如果现在不做,在完成的时候会自动完成该步骤
SQL> EXEC DBMS_REDEFINITION.sync_interim_table(uname => 'JUSTONE4',orig_table => 'LIST_SENDBOX',int_table => 'TMP_LIST_SENDBOX');
第四步:
--完成在线重定义
SQL> EXEC DBMS_REDEFINITION.finish_redef_table(uname => 'JUSTONE4',orig_table => 'LIST_SENDBOX',int_table => 'TMP_LIST_SENDBOX');
--清除因为在线重定义过程中,系统自动创建的部分对象
SQL> exec dbms_redefinition.abort_redef_table(uname => 'JUSTONE4',orig_table => 'LIST_SENDBOX',int_table => 'TMP_LIST_SENDBOX');
ORACLE 10g
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 or constraint) 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 or constraint) on the table being redefined and the corresponding dependent object on the interim table
参考文档 Oracle Database PL/SQL Packages and Types Reference DBMS_REDEFINITION包部分和 Oracle Database Administrator's Guide
相比9i 多了 COPY_TABLE_DEPENDENTS ,REGISTER_DEPENDENT_OBJECT,UNREGISTER_DEPENDENT_OBJECT相当实用的功能,自动完成9i中重建索引等对象的操作
注意如果是巨大的表 可以修改当前 session 增加并发,提高速度
ex:
Because CUSTOMER is a very large table, specify parallel operations for the next step.
alter session force parallel dml parallel 4;
alter session force parallel query parallel 4;
需要的权限
Privileges Required for the DBMS_REDEFINITION Package
Execute privileges on the DBMS_REDEFINITION package are granted to EXECUTE_CATALOG_ROLE. In addition to having execute privileges on this package, you must be granted the following privileges:
CREATE ANY TABLE
ALTER ANY TABLE
DROP ANY TABLE
LOCK ANY TABLE
SELECT ANY TABLE
The following additional privileges are required to execute COPY_TABLE_DEPENDENTS:
CREATE ANY TRIGGER
CREATE ANY INDEX
参考:piner的 http://www.ixdba.net/article/47/1604.html
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7813229/viewspace-611359/ ,如需转载,请注明出处,否则将追究法律责任。