Oracle清理大表,降水位

來源:互聯網
上載者:User

標籤:準備   使用者登入   復原   line   port   並行   sda   使用率   tran   

背景:一張表的清理機制存在問題,導致該表的資料一直在增加,該表水位已很高,需要對該表的資料進行清理並降水位。

1.1 遷移前準備

步驟一、建立表 p_transaction_bak。

[email protected]:~/orcale > sqlplus test/test

SQL> create table p_transaction_bak
as
select * from p_transaction where 1 = 0;
SQL> alter table p_transaction_bak modify OPERATIONDATE DEFAULTsysdate;
SQL> alter table p_transaction_bak modify INVALID DEFAULT 0;

步驟二、有需要的有效資料插入新表中。

SQL> altersession enable parallel dml;

insert /*+ append parallel(p,8) */ intop_transaction_bak p select /*+ parallel(n,8) */ * fromp_transaction n
where to_char(n.operationdate, ‘yyyy-mm-dd‘) between
to_char(to_date(‘2016-06-27‘, ‘yyyy-mm-dd‘), ‘yyyy-mm-dd‘) and
to_char(to_date(‘2016-07-04‘, ‘yyyy-mm-dd‘), ‘yyyy-mm-dd‘);

commit;

步驟三、為新表 p_transaction

table建立主鍵和索引
SQL> create unique index PK_PO_TRANSACTION_NEW onp_transaction_bak(STREAMINGID) tablespace portaloneindx parallel 8 online;
SQL> alter table p_transaction_bak add constraintPK_PO_TRANSACTION_NEW primary key (STREAMINGID);
SQL> alter index PK_PO_TRANSACTION_NEW noparallel;
SQL> create index ix_transaction_operationdate onp_transaction_bak(operationdate) tablespace portaloneindx parallel 8 online;
SQL> alter index ix_transaction_operationdate noparallel;

----End

1.2 執行資料移轉

步驟一、停應用

步驟二、以SYSDBA使用者登入資料庫。

[email protected]:~/orcale > sqlplus/ as sysdba

步驟三、檢查資料資料表空間和索引資料表空間使用率。

SQL>select total.tablespace_name,
round(total.MB, 2) as Total_MB,
round(total.MB - free.MB, 2) as Used_MB,
round((1 - free.MB / total.MB) * 100, 2) || ‘%‘ as Used_Pct
from (select tablespace_name, sum(bytes) / 1024 / 1024 as MB
from dba_free_space
group by tablespace_name) free,
(select tablespace_name, sum(bytes) / 1024 / 1024 as MB
from dba_data_files
group by tablespace_name) total
where free.tablespace_name = total.tablespace_name;

步驟四、並行將資料插入新表。

SQL> altersession enable parallel dml;

insert /*+ append parallel(p,8) */ intop_transaction_bak p select /*+ parallel(n,8) */ * fromp_transaction n
where to_char(n.operationdate, ‘yyyy-mm-dd‘) =
to_char(to_date(‘2016-07-05‘, ‘yyyy-mm-dd‘), ‘yyyy-mm-dd‘);

commit;

步驟五、備份舊錶。

SQL> rename p_transactionto p_transaction_old;

步驟六、重新命名新表。

SQL> renamep_transaction_bak to p_transaction;

----End

1.3 復原以上操作 [email protected]:~/ orcale >sqlplus test/test

SQL>renamep_transaction to p_transaction_new;
SQL>rename p_transaction_old to p_transaction;
SQL>truncate table p_transaction_new;
SQL>drop table p_transaction_new;

----End

 

Oracle清理大表,降水位

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.