ORACLE Online Table redefinition

Source: Internet
Author: User

ORACLE in fact some of the tables due to the increase in traffic, some of the original planning is not very large data volume of the table, in order to optimize the table from the ordinary table into a partitioned table. Now let's introduce a technique that Oracle comes with to handle this situation-a technique called online table redefinition.

The first step is to create a temporary table:

CREATE TABLE Test_table

(ID Numeber (Ten) is not NULL,

STATUS VARCHAR2 (+) NULL,

Create_date DATE

) PARTITION by RANGE (create_date)
(PARTITION part23 VALUES less THAN (to_date (' 2010-09-24 ', ' yyyy-mm-dd '),
PARTITION part24 VALUES less THAN (to_date (' 2010-09-25 ', ' yyyy-mm-dd ')),
PARTITION Part25 VALUES less THAN (to_date (' 2010-09-26 ', ' yyyy-mm-dd ')),
PARTITION Partmax VALUES less THAN (MAXVALUE)
);

ALTER TABLE test_table ADD constraint TEST_TABLE_PK primary key (ID);

The second step is to determine whether the target data table can be redefined. Use the Dbms_redefinition package of the Can_redef_table method to judge.

EXEC dbms_redefinition.can_redef_table (' User ', ' table ', DBMS_REDEFINITION.CONS_USE_PK);

Materialized views created with CONS_USE_PK redefined are based on the normal refresh mode.

You can also use the rowID method

EXEC dbms_redefinition.can_redef_table (' User ', ' table ', dbms_redefinition.cons_use_rowid);

Materialized views created with Cons_use_rowid redefined are refreshed based on ROWID.

The third step starts redefining

EXEC dbms_redefinition.start_redef_table (' User ', ' table ', ' test_table ');

Synchronizing temporary tables with data from the original table

EXEC dbms_redefinition.sync_interim_table (' User ', ' table ', ' test_table ');

Start copying properties of a table

DECLARECLAR

Num_errors Pls_integer;

BEGIN

Dbms_redefinition. Copy_table_dependents (' user ', ' TABLE ', ' test_table ',

Dbms_redefinition. Cons_orig_params, True, True, true, true, num_errors);

END;

/

Include indexes, rules, hair enhancers

Finish redefining

EXEC dbms_redefinition.finish_redef_table (' User ', ' table ', ' test_table ');



_PK);




This article is from the "12024114" blog, please be sure to keep this source http://12034114.blog.51cto.com/12024114/1879218

ORACLE Online Table redefinition

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.