这几天看看业务有些日志表需要从堆表转成分区表,想想从9开始有了在线重定义,决定就用这个解决吧,而且做的时候对表不锁定,可以做DDL。好处还是挺多的。
步骤:
重定义的方法有两种:By key和by rowid,默认是主键模式
1:验证表是否可以重定义EXEC DBMS_REDEFINITION.CAN_REDEF_TABLE('username', 'tablename');
2:创建一个空的分区中间表,具体建表语句这里忽略
3:开始重定义EXEC DBMS_REDEFINITION.START_REDEF_TABLE('username', 'tablename', 'new_tablename',null);
4: 复制依赖对象(比如触发器,索引,约束,权限,等等)EXEC DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS()
5:同步中间表EXEC DBMS_REDEFINITION.SYNC_INTERIM_TABLE('username', 'tablename', 'new_tablename');
6:结束重定义EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE('username', 'tablename', 'new_tablename');
注意:
If START_REDEF_TABLE fails for any reason, you must call ABORT_REDEF_TABLE, otherwise subsequent attempts to redefine the table will fail.
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