Oracleオンライン再定義Online Redefinitionによる履歴データのクリーンアップ


では、Oracleオンライン再定義の特徴とその使用手順について説明します.Online Redefinitionの適用シーンは次のとおりです.
  • Modify the storage parameters of a table or cluster
  • Move a table or cluster to a different tablespace
  • Add, modify, or drop one or more columns in a table or cluster
  • Add or drop partitioning support (non-clustered tables only)
  • Change partition structure
  • Change physical properties of a single table partition, including moving it to a different tablespace in the same schema
  • Change physical properties of a materialized view log or an Oracle Streams Advanced Queueing queue table
  • Add support for parallel queries
  • Re-create a table or cluster to reduce fragmentation
  • Change the organization of a normal table (heap organized) to an index-organized table, or do the reverse.
  • Convert a relational table into a table with object columns, or do the reverse.
  • Convert an object table into a relational table or a table with object columns, or do the reverse.

  • しかしOnline Redefinitionは、テーブル上の履歴データのクリーンアップ(データ更新updateでもサポート)をサポートしていないため、大量のデータが格納され、パーティションがない大きなテーブルにとって履歴データのクリーンアップは非常に頭が痛い作業であり、特に7*24がラインオフできない環境では、CTASまたはINSERT APPEND+NOLOGGINGを使用してテーブルを再構築することはできませんが、最も原始的なDELETE DMLしか使用できません.DELETEの動作が遅いことを知っています(前に述べた方法に比べて、実際の世界ではDELETEの効率はINDEX clustering_factor集計因子などの要因の影響を受けて遅く見えます.)を参照してください.ORA-01555スナップショットの長すぎるエラーを回避するために、データをクリーンアップするためにDELETE SQLを簡単に使用することはできませんが、ORA-01555を回避するためにPL/SQL匿名ブロック制御を使用し、定期的にcommitを送信する必要があります.実際には、非パーティションテーブルOnline RedefinitionをRange範囲のパーティションを削除するためのパーティション-ed Tableに変換し、ビジネスのオンラインに影響を与えずに履歴データのクリーンアップを直接Truncate Partitonする方法で加速することもできます.たとえば、次のような非パーティション表があります.
    create table order_history
    (
    order_id number primary key,
    issue_date date ,
    location varchar2(200),
    amount number,
    maclean varchar2(200),
    QUANTITY_SOLD number,
    PROMO_ID number,
    CUST_ID number,
    CHANNEL_ID number) tablespace users pctfree 0;
    
    SQL> select count(*) from ORDER_HISTORY;