博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Oracle 12.2 联机重定义多个分区并将其移动到不同的表空间中
阅读量:2440 次
发布时间:2019-05-10

本文共 4129 字,大约阅读时间需要 13 分钟。

下面的例子将演示如何联机重定义多个分区并将基于范围分区的表salestable的两个分区移动到新表空间中。原始表jy.salestable的创建如下:

SQL> create table jy.salestable  2  (s_productid number,  3  s_saledate date,  4  s_custid number,  5  s_totalprice number)  6  tablespace users  7  partition by range(s_saledate)  8  (partition sal10q1 values less than (to_date('01-apr-2010', 'dd-mon-yyyy')),  9  partition sal10q2 values less than (to_date('01-jul-2010', 'dd-mon-yyyy')), 10  partition sal10q3 values less than (to_date('01-oct-2010', 'dd-mon-yyyy')), 11  partition sal10q4 values less than (to_date('01-jan-2011', 'dd-mon-yyyy')));Table created.

这个例子会将分区sal10q1与sal10q2移动到example表空间中。sal10q3与sal10q4分区不会被移动。为了移动分区表空间example必须存在。这里已经先创建好了表空间example。对原始表jy.salestable创建一个本地分区索引,操作如下:

SQL> create index jy.sales_index on jy.salestable (s_saledate, s_productid, s_custid) local;Index created.

注意,在12.2中也可以执行alter table ... move partition ... online语句来将分区移动到其它表空间中。

联机重定义操作如下:

1.用要执行联机重定义操作的用户登录数据库

SQL> conn jy/jy@jypdbConnected.

2.验证原始表jy.salestable是否可以执行联机重定义

SQL> begin  2  dbms_redefinition.can_redef_table(  3    uname => 'jy',  4    tname => 'salestable',  5    options_flag => DBMS_REDEFINITION.CONS_USE_ROWID,  6    part_name => 'sal10q1, sal10q2');  7  end;  8  /PL/SQL procedure successfully completed.

3.在新表空间example中创建中间表。因为这是对分区执行联机重定义,因此中间表不能是分区表。

SQL> create table jy.int_salestb1  2  (s_productid number,  3  s_saledate date,  4  s_custid number,  5  s_totalprice number)  6  tablespace example;Table created.SQL> create table jy.int_salestb2  2  (s_productid number,  3  s_saledate date,  4  s_custid number,  5  s_totalprice number)  6  tablespace example;Table created.

4.使用rowid方法来执行重定义操作

SQL> begin  2  dbms_redefinition.start_redef_table(  3    uname => 'jy',  4    orig_table => 'salestable',  5    int_table => 'int_salestb1, int_salestb2',  6    col_mapping => NULL,  7    options_flag => DBMS_REDEFINITION.CONS_USE_ROWID,  8    part_name => 'sal10q1, sal10q2',  9    continue_after_errors => TRUE); 10  end; 11  /PL/SQL procedure successfully completed.

注意,part_name参数用来指定所有要重定义的分区,int_table参数用来指定每个分区所对应的中间表,continue_after_errors参数被设置为true,因此重定义操作即使当某个特定分区遇到错误也会继续执行。

5.在中间表上创建任何本地索引

SQL> create index jy.int_sales1_index on jy.int_salestb1  2  (s_saledate, s_productid, s_custid)  3  tablespace example;Index created.SQL> create index jy.int_sales2_index on jy.int_salestb2  2  (s_saledate, s_productid, s_custid)  3  tablespace example;Index created.

6.可选操作同步中间表

SQL> begin  2  dbms_redefinition.sync_interim_table(  3    uname => 'jy',  4    orig_table => 'salestable',  5    int_table => 'int_salestb1, int_salestb2',  6    part_name => 'sal10q1, sal10q2',  7    continue_after_errors => TRUE);  8  end;  9  /PL/SQL procedure successfully completed.

7.完成重定义操作

SQL> begin  2  dbms_redefinition.finish_redef_table(  3    uname => 'jy',  4    orig_table => 'salestable',  5    int_table => 'int_salestb1, int_salestb2',  6    part_name => 'sal10q1, sal10q2',  7    continue_after_errors => TRUE);  8  end;  9  /PL/SQL procedure successfully completed.

8.可选操作,查询dba_redefinition_status视图来确保对每个分区都重定义操作成功

SQL> select base_table_owner, base_table_name, operation, status from dba_redefinition_status;no rows selected

如果有任何分区重定义失败,视图dba_redefinition_errors会显示出错误原因,修正故障重新执行联机重定义操作。

下面的查询显示了表jy.salestable有两个分区已经移动到了新的表空间example中了

SQL> select partition_name, tablespace_name from dba_tab_partitions where table_name = 'SALESTABLE' and table_owner='JY';PARTITION_NAME                                                                   TABLESPACE_NAME-------------------------------------------------------------------------------- ------------------------------SAL10Q1                                                                          EXAMPLESAL10Q2                                                                          EXAMPLESAL10Q3                                                                          USERSSAL10Q4                                                                          USERS

到此联机重定义操作完成

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26015009/viewspace-2142202/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26015009/viewspace-2142202/

你可能感兴趣的文章
Maven编译时指定JDK版本
查看>>
Hibernate单向关联N-1
查看>>
Hibernate单向关联1-1
查看>>
jQuery自定义动画
查看>>
Spring-data-redis在shiro中的实例
查看>>
GUN C中__attribute__作用
查看>>
3、系统调用之SYSCALL_DEFINE分析
查看>>
linux的signal_pending及signal
查看>>
OBJDUMP用法
查看>>
c/cplusplus通用makefile
查看>>
JavaScript-密码强度
查看>>
【SSH】1366-InCorrect string value:'\xE9\x99\x88\xE6\x96\xB0...'for column 'name' at row 1
查看>>
SpringCloud前身之微服务
查看>>
纵览全局——SSH
查看>>
Mybatis-略识之无
查看>>
[Vue warn]: Property or method "name" is not defined on the instance but referenced during render
查看>>
ts:json串转换成数组
查看>>
String、StringBuffer和StringBuilder的区别
查看>>
java——职责链模式
查看>>
java_选择类排序——简单选择排序
查看>>