標籤:準備 使用者登入 復原 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清理大表,降水位