11g数据库大表数据快速清理方法 – insert+append+parallel+exchange (2)

2024-01-31Oracle / RAC

分类: Oracle

2. 由于2013-2014数据是表中较少量的数据,采用insert到其他表的方式处理,而不使用delete ,其中的parallel根据实际CPU设置.

# insert_ap_inv.sql spool insert_ap_inv.log set timing on alter session enable parallel DML ; insert /*+ append */ into AP.AP_INVOICE_DISTS_ARCH_WQ select /*+ parallel(32) */ * from AP.AP_INVOICE_DISTS_ARCH_WQ a where a.last_update_date>=to_date('20130101','yyyymmdd'); commit; set timing off spool off exit

nohup sqlplus / as sysdba @insert_ap_inv.sql &

3. 对原表和中间分区表(只有一个分区)进行数据置换 (注意只会进行数据置换, 索引不会有任何动作,这里没有使用including indexes, including indexes 表示). 将Local indexes 一同exchange出来, 此选项需要用来与之exchange的table 有建立一样的Index) alter table AP.AP_INVOICE_DISTS_ARCH_WQ exchange partition APINV_PART01 with table AP.AP_INVOICE_DISTS_ARCH without validation;

4. 进行exchange后原表的索引可能会变成unusable 状态,需要对原表中索引进行rebuild . select 'alter index '||owner||'.'||index_name||' rebuild parallel 32 nologging ;' from dba_indexes where table_name =

'AP_INVOICE_DISTS_ARCH'; 将查询出来的语句保存为 rebuild_idx2.sql 文件 ,后台执行。 nohup sqlplus / as sysdba @rebuild_idx2.sql &

5. 数据置换后需要对表进行统计信息重新收集 。

# gather_ap_inv.sql

spool gather_ap_inv.log set timing on EXEC dbms_stats.gather_table_stats(ownname => 'AP',tabname => 'AP_INVOICE_DISTS_ARCH',method_opt => 'FOR ALL COLUMNS SIZE

AUTO',degree=>32,cascade => TRUE); set timing off spool off exit

后台执行 : nohup sqlplus / as sysdba @gather_ap_inv.sql &

.

阅读(3830) | 评论(16777215) | 转发(0)

0