Oracle 12c 新特性 --- 在线重新定义多个分区

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/leo__1990/article/details/90032333

概念

Online redefinition supports redefinition of multiple partitions in a single redefinition session. This feature reduces the completion time to redefine multiple partitions while still providing access to the underlying table.
在线重新定义支持在一个重新定义会话中重新定义多个分区。这个特性减少了重新定义多个分区的完成时间,同时还能提供对底层表的访问。

You can redefine online one or more partitions of a table. This is useful if, for example, you want to move partitions to a different tablespace and keep the partitions available for DML during the operation.
您可以在网上重新定义一个或多个表的分区。这很有用,例如,您希望将分区移到不同的表空间,并在操作期间为DML保留分区。You can redefine multiple partitions in a table at one time. If you do, then multiple interim tables are required during the table redefinition process. Ensure that you have enough free space and undo space to complete the table redefinition.
您可以一次重新定义一个表中的多个分区。如果您这样做,那么在表重新定义过程中需要多个临时表。确保您有足够的空闲空间和还原空间来完成表重新定义。
When you redefine multiple partitions, you can specify that the redefinition continues even if it encounters an error for a particular partition. To do so, set the continue_after_errors parameter to TRUE in redefinition procedures in the DBMS_REDEFINITION package. You can check the DBA_REDEFINITION_STATUS view to see if any errors were encountered during the redefinition process. The STATUS column in this view shows whether the redefinition process succeeded or failed for each partition.
当您重新定义多个分区时,您可以指定重新定义继续,即使它遇到一个特定分区的错误。为此,在DBMS_REDEFINITION包中的redefinition过程中设置continue_after_errors参数。您可以检查DBA_REDEFINITION_STATUS视图,看看在重新定义过程中是否遇到了错误。此视图中的STATUS列显示每个分区的重新定义过程是否成功或失败。
You can also redefine an entire table one partition at a time to reduce resource requirements. For example, to move a very large table to a different tablespace, you can move it one partition at a time to minimize the free space and undo space required to complete the move.
您还可以在一个时间内重新定义整个表一个分区,以减少资源需求。例如,为了将一个非常大的表移动到一个不同的表空间,您可以在一个时间内移动一个分区,以最小化完成移动所需的空闲空间和撤销空间。

实验

这个示例演示重新定义多个分区。它将一个范围分区销售表的两个分区移动到新的表空间。重新定义的分区表定义如下:
1)创建分区表

[[email protected] ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.1.0.2.0 Production on Fri Aug 25 02:00:29 2017

Copyright (c) 1982, 2014, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL> conn test/test@pdbcndba
Connected.
SQL> CREATE TABLE salestable
  (s_productid NUMBER,
  s_saledate DATE,
  s_custid NUMBER,
  s_totalprice NUMBER)
  TABLESPACE users
  PARTITION BY RANGE(s_saledate)
  (PARTITION sal10q1 VALUES LESS THAN (TO_DATE('01-APR-2010', 'DD-MON-YYYY')),
  PARTITION sal10  2    3    4    5    6    7    8    9  q2 VALUES LESS THAN (TO_DATE('01-JUL-2010', 'DD-MON-YYYY')),
  PARTITION sal10q3 VALUES LESS THAN (TO_DATE('01-OCT-2010', 'DD-MON-YYYY')),
  PARTITION sal10q4 VALUES LESS THAN (TO_DATE('01-JAN-2011', 'DD-MON-YYYY'))); 10   11  

Table created.

2) 创建sales1,sales2 表空间

这个示例将sal10q1分区转移到sales1表空间和sal10q2分区到sales2表空间。sal10q3和sal10q4分区没有移动。
要移动分区,表空间sales1和sales2必须存在。下面的示例创建了这些表空间:

SQL> CREATE TABLESPACE sales1 DATAFILE '/u01/app/oracle/oradata/cndba/pdbcndba/sales01.dbf' SIZE 50M
    EXTENT MANAGEMENT LOCAL AUTOALLOCATE;  2  

Tablespace created.

SQL> CREATE TABLESPACE sales2 DATAFILE '/u01/app/oracle/oradata/cndba/pdbcndba/sales02.dbf' SIZE 50M
    EXTENT MANAGEMENT LOCAL AUTOALLOCATE;  2  

Tablespace created.

3)创建局部分区索引

SQL> CREATE INDEX sales_index ON salestable 
   (s_saledate, s_productid, s_custid) LOCAL;  2  

Index created.

4) 确保salestable是一个重新定义的候选人。
SQL> BEGIN
  DBMS_REDEFINITION.CAN_REDEF_TABLE(
   uname        => 'TEST',
   tname        => 'salestable',
   options_flag => DBMS_REDEFINITION.CONS_USE_ROWID,
   part_name    => 'sal10q1, sal10q2');
END;
/  2    3    4    5    6    7    8   

PL/SQL procedure successfully completed.

5) 在新的表空间中创建临时表。因为这是对范围分区的重新定义,所以临时表是非分区的。
SQL> CREATE TABLE int_salestb1
  (s_productid NUMBER,
  s_saledate DATE,
  s_custid NUMBER,
  s_totalprice NUMBER)
  TABLESPACE sales1;  2    3    4    5    6  

Table created.

SQL> CREATE TABLE int_salestb2
  (s_productid NUMBER,
  s_saledate DATE,
  s_custid NUMBER,
  s_totalprice NUMBER)
  TABLESPACE sales2;
  2    3    4    5    6  
Table created.

6) 使用rowid启动重新定义过程。
SQL> BEGIN
  DBMS_REDEFINITION.START_REDEF_TABLE(
   uname        => 'TEST',
   orig_table   => 'salestable',
   int_table    => 'int_salestb1, int_salestb2',
   col_mapping  => NULL,
   options_flag => DBMS_REDEFINITION.CONS_USE_ROWID,
   part_name    => 'sal1  2    3    4    5    6    7    8  0q1, sal10q2',
   continue_after_errors => TRUE);
END;
/  9   10   11  

PL/SQL procedure successfully completed.
 7)在临时表上手工创建任何本地索引。

SQL> CREATE INDEX int_sales1_index ON int_salestb1 
(s_saledate, s_productid, s_custid)
TABLESPACE sales1;   2    3  

Index created.

SQL> CREATE INDEX int_sales2_index ON int_salestb2 
(s_saledate, s_productid, s_custid)
TABLESPACE sales2;   2    3  

Index created.

8) 可选地同步临时表。
SQL> BEGIN 
  DBMS_REDEFINITION.SYNC_INTERIM_TABLE(
   uname      => 'TEST', 
   orig_table => 'salestable', 
   int_table  => 'int_salestb1, int_salestb2',
   part_name    => 'sal10q1, sal10q2',
   continue_after_errors => TRUE);
END;
/
  2    3    4    5    6    7    8    9  

PL/SQL procedure successfully completed.
 9) 完成重新定义
SQL> BEGIN 
  DBMS_REDEFINITION.FINISH_REDEF_TABLE(
   uname      => 'TEST', 
   orig_table => 'salestable', 
   int_table  => 'int_salestb1, int_salestb2',
   part_name    => 'sal10q1, sal10q2',
   continue_after_errors => TRUE);
END;
/  2    3    4    5    6    7    8    9  

PL/SQL procedure successfully completed.

10)等待任何针对临时表的长时间查询完成,然后删除临时表。

11)(可选)查询DBA_REDEFINITION_STATUS视图,以确保重新定义每个分区成功。
SQL> SELECT BASE_TABLE_OWNER, BASE_TABLE_NAME, OPERATION, STATUS
  FROM DBA_REDEFINITION_STATUS;  2  

no rows selected

12) 如果对任何分区重新定义失败,则查询DBA_REDEFINITION_ERRORS视图,以确定失败的原因。纠正导致故障的条件,重新运行在线重新定义。
下面的查询显示表中的两个分区已经移动到新的表空间中:

SQL> col PARTITION_NAME for a20
SQL> col TABLESPACE_NAME for a20 
SQL> SELECT PARTITION_NAME, TABLESPACE_NAME FROM DBA_TAB_PARTITIONS
 WHERE TABLE_NAME = 'SALESTABLE';  2  

PARTITION_NAME	     TABLESPACE_NAME
-------------------- --------------------
SAL10Q4 	     USERS
SAL10Q3 	     USERS
SAL10Q2 	     SALES2
SAL10Q1 	     SALES1

参考文档

http://docs.oracle.com/database/121/NEWFT/chapter12101.htm#NEWFT002

http://docs.oracle.com/database/121/ADMIN/tables.htm#ADMIN11675 

猜你喜欢

转载自blog.csdn.net/leo__1990/article/details/90032333
今日推荐