我有一个 24x7 OLTP (11gR2) 应用程序,它可以承受对特定表的大量插入,流量增加到我们遇到严重索引争用的程度。我们对这个特定表上的主键使用序列,为了减少索引争用,我想将主键索引重新分区为具有 8 个哈希分区(当前索引和表未分区)。我可以重建索引以在线方式将其转换为分区,即不停止表上的 DML 吗?
经过深思熟虑,我想我已经做到了。唯一的缺点是您需要将基础表的空间加倍才能这样做......
不要认为还有其他方法可以做到这一点,因为您无法在不删除和重新创建的情况下重新定义 PK(如果我错了,请纠正我)。
PHIL@PHILL11G2 > alter table bigtable add constraint bigtable_pk primary key (object_id);
Table altered.
PHIL@PHILL11G2 > commit;
Commit complete.
PHIL@PHILL11G2 > create table bigtable_interim as ( select * from bigtable where 1=0 );
Table created.
PHIL@PHILL11G2 > EXEC dbms_redefinition.can_redef_table('PHIL', 'BIGTABLE');
PL/SQL procedure successfully completed.
PHIL@PHILL11G2 > exec DBMS_REDEFINITION.start_redef_table(uname => 'PHIL',orig_table => 'BIGTABLE',int_table => 'BIGTABLE_INTERIM');
PL/SQL procedure successfully completed.
PHIL@PHILL11G2 >
PHIL@PHILL11G2 > create unique index bigtable_int_hash on bigtable_interim (object_id) global partition by hash (object_id) (partition p1 tablespace users, partition p2 tablespace users) online;
Index created.
PHIL@PHILL11G2 > exec dbms_redefinition.finish_redef_table(uname => 'PHIL',orig_table => 'BIGTABLE',int_table => 'BIGTABLE_INTERIM');
PL/SQL procedure successfully completed.
PHIL@PHILL11G2 > select count(*) from bigtable_interim;
COUNT(*)
----------
2300640
PHIL@PHILL11G2 > select count(*) from bigtable;
COUNT(*)
----------
2300640
PHIL@PHILL11G2 >
PHIL@PHILL11G2 > alter table bigtable add constraint bigtable_hashed_pk primary key (object_id) ;
Table altered.
PHIL@PHILL11G2 > -- that reused the hashed index i created
Run Code Online (Sandbox Code Playgroud)
随时纠正我犯的任何错误:)
菲尔
归档时间: |
|
查看次数: |
1656 次 |
最近记录: |