---
title: "oracle 大表复制"
author: "Fred_Han"
date: "2014-02-19T11:46:05Z"
tags: []
categories: ["数据库"]
slug: "oracle"
draft: false
lastmod: "2014-02-19T11:47:55Z"
id: 2019250
url: "https://fred-han.iteye.com/blog/2019250"
---

常用的大表复制技术

传统方法 建表然后insert into  
create table CLW\_TEMP1 (  DX\_PROCESS\_NO VARCHAR2(15),TELE\_NUM  VARCHAR2(11),OPER\_CODE VARCHAR2(10),  
DEPT\_CODE VARCHAR2(8),DO\_DEPT\_CODE VARCHAR2(8),PLAN\_ID NUMBER(8),ICC\_ID  VARCHAR2(25),PROCESS\_DATE  DATE);  
insert into clw\_temp1  select * from   clw\_Temp;  
执行时间  56.891s   
优化后的传统方法  
   Create table  as …  
CTAS的方法速度快是因为减少I/O  
drop table clw\_temp1;  
create table clw\_Temp1 as select * from clw\_temp;      
74.922  
CTAS UNRECOVERABLE  
UNRECOVERABLE 能减半建表的时间,同时能够减少资源占用 因为它可以越过redo log processing. drop table clw\_temp1;  
    create table clw\_Temp1 unrecoverable  as select * from clw\_temp;      
    26.531  
   CTAS PARALLEL  
 并行访问并不是degree越大越好的,下面的例子已经说明了这个问题 具体值和硬件和软件平台都有关系 也和oracle初始设置有关    
 PARALLEL\_MIN\_SERVERS    PARALLEL\_MAX\_SERVERS  
 PARALLEL\_AUTOMATIC\_TUNING = TRUE  
drop table clw\_temp1;  
create table clw\_Temp1 parallel (degree 4)   as select * from clw\_temp;  
49.797  
drop table clw\_temp1;  
create table clw\_Temp1 parallel (degree 2)   as select * from clw\_temp;  
36.359    APPEND  
Append 提示告诉Oracle 使用快速机制来插入数据,和nologging会有更好的效果  
If a table or an index is specified with nologging, this hint applied  
with an insert statement produces a direct path insert which reduces generation of redo.    
insert /\*+APPEND  \*/ into clw\_temp1   select * from clw\_temp;  
44.687  
NOLOGGING  
在归档的模式下是有用的 drop table clw\_temp1;  
create table clw\_Temp1 as  select * from clw\_temp;      
45.047  
综合使用各种提示优化  
Create table clw\_temp1 as select * from clw\_temp1 where rownum&lt;1 nologging;

insert /\*+APPEND  parallel (degree 2)   \*/ into clw\_temp1   select * from clw\_temp 

38.922  
从这里看出append 和nologging和parallel结合使用对效果提高是蛮大的  
create table CLW\_TEMP1 unrecoverable  
 parallel (degree 2)  as select  * from clw\_temp nologging   
 14.797   
看看用时14.797 堪称经典,与普通方法的执行时间相比,简直是天壤之别  

导入导出技术  
可以使用Oracle IMP/EMP