DBMS_REDEFINITION converted with ordinary table partition table

Introduction 1. DBMS_REDEFINITION

  • Import and Export;
  • insert … select …;
  • Swap zoning laws;
  • Online redefinition (DBMS_REDEFINITION).

The idea of ​​these programs is to create a new partition table, and then to transfer data from the old table to the new table top, then transfer the corresponding dependencies, and finally re-table the name, the new table the old table and rename. Compared with the previous three programs, DBMS_REDEFINITION almost does not affect the normal use of the old table, so becoming the partition table of the conversion program currently in common use.

The following project in a large table TP_CARD_INFO (about 12 million records), for example, to convert an ordinary table to illustrate the steps of the partition table.

2. Check whether the ordinary partition table

It was confirmed on a primary key:

SQL> begin
  2  DBMS_REDEFINITION.CAN_REDEF_TABLE('HSADM', 'TP_CARD_INFO', Dbms_Redefinition.cons_use_pk);
  3  end;
  4  /
PL/SQL procedure successfully completed

No error output represents.

3. Create partition table

By primary key partitions, each no more than 2 million records:

create table TP_CARD_INFO_PART
(
  id              NUMBER(15) not null,
  card_num        VARCHAR2(32),
  card_num2      VARCHAR2(32),
  create_time    DATE,
  create_user    VARCHAR2(16),
  update_time    DATE,
  update_user    VARCHAR2(16),
  print_date      VARCHAR2(8),
  print_by        NVARCHAR2(40),
  print_unit_code VARCHAR2(16),
  print_unit_name NVARCHAR2(70),
  print_reason    NVARCHAR2(40),
  finger_absence  NVARCHAR2(10)
)
partition by range(ID)
(
  partition TP_CARD_INFO_01 values less than (2000000) tablespace HS_DAT,
  partition TP_CARD_INFO_02 values less than (4000000) tablespace HS_DAT,
  partition TP_CARD_INFO_03 values less than (6000000) tablespace HS_DAT,
  partition TP_CARD_INFO_04 values less than (8000000) tablespace HS_DAT,
  partition TP_CARD_INFO_05 values less than (10000000) tablespace HS_DAT,
  partition TP_CARD_INFO_06 values less than (12000000) tablespace HS_DAT,
  partition TP_CARD_INFO_99 values less than (MAXVALUE) tablespace HS_DAT
);

4. Data Migration

SQL> exec DBMS_REDEFINITION.start_redef_table('HSADM', 'TP_CARD_INFO', 'TP_CARD_INFO_PART');
PL/SQL procedure successfully completed

The whole process is 256 seconds with.

The migration permission object

SQL> declare
  2  num_errors PLS_INTEGER;
  3  begin
  4  dbms_redefinition.copy_table_dependents('HSADM', 'TP_CARD_INFO', 'TP_CARD_INFO_PART',
  5  dbms_redefinition.cons_orig_params, TRUE, TRUE, TRUE, TRUE, num_errors);
  6  end;
  7  /
PL/SQL procedure successfully completed

The whole process with 526 seconds.

6. Is there a wrong query

SQL> select object_name, base_table_name, ddl_txt from  DBA_REDEFINITION_ERRORS;
OBJECT_NAME                                                                      BASE_TABLE_NAME                                                                  DDL_TXT
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

No error.

7. End redefinition process

begin
  2  dbms_redefinition.finish_redef_table('HSADM', 'TP_CARD_INFO', 'TP_CARD_INFO_PART');
  3  end;
  4  /
PL/SQL procedure successfully completed

73 seconds the whole process.

Exit 8. When an exception occurs

If unusual redefinition process, you must perform the exit procedure:

SQL> begin
  2  dbms_redefinition.abort_redef_table('HSADM', 'TP_CARD_INFO', 'TP_CARD_INFO_PART');
  3  end;
  4  /

Guess you like

Origin www.linuxidc.com/Linux/2019-07/159602.htm