반응형
/********************************************************************************************
-- Title : [10g] EXPORT/IMPORT 사용법 - ver.dbrang
-- Reference : dbrang.tistory.com
-- Key word : 임포트 익스포트 exp imp
********************************************************************************************/
/********************************
-- 테이블 생성
********************************/
-- drop table scott.empexp purge;
create table scott.empexp
as
select * from scott.emp;

-- 생성 확인
select * from scott.empexp;

-- 인덱스 생성
alter table scott.empexp
add constraint pk_empexp primary key(empno);

create index scott.ix_empexp
on scott.empexp(sal);

-- 인덱스 확인
select * from dba_indexes where owner='SCOTT' and table_name = 'EMPEXP';

-- 제약 추가
alter table scott.empexp
add constraint chk_empexp check (sal > 100);

-- 제약 확인
select * from dba_constraints where owner='SCOTT' and table_name = 'EMPEXP';
 

/********************************
-- EXPORT
********************************/
-- 전체 EXP
-- 가능한 한 사용자나 한 테이블스페이스로 제약하자.
$ exp userid=user/password full=y \
      file=/home/oracle/EXP/1_full.dmp

-- 테이블스페이스 EXP
$ exp userid=user/password tablespaces=users \
      file=/home/oracle/EXP/2_ts_users.dmp

-- 스키마 EXP
$ exp userid=user/password owner=scott \
      file=/home/oracle/EXP/3_sch_scott.dmp

-- 테이블 EXP
$ exp userid=user/password tables=scott.emp \
      file=/home/oracle/EXP/4_tbl_emp.dmp

-- 테이블 EXP(constraints=N)
$ exp userid=user/password tables=scott.empexp constraints=y \
      file=/home/oracle/EXP/5_tbl_empexp_const.dmp

-- 테이블 EXP(direct=Y)
$ exp userid=user/password tables=scott.empexp direct=y \
      file=/home/oracle/EXP/6_tbl_empexp_dirct.dmp

-- 테이블 EXP(indexes=N)
$ exp userid=user/password tables=scott.empexp indexes=y \
      file=/home/oracle/EXP/7_tbl_empexp_idx.dmp

-- 테이블 EXP(rows=N)
$ exp userid=user/password tables=scott.empexp rows=y \
      file=/home/oracle/EXP/8_tbl_empexp_rows.dmp

-- 테이블 EXP(query)
$ exp userid=user/password tables=scott.empexp \
      query=\"where job\=\'SALESMAN\' and sal \<1600\" \
      file=/home/oracle/EXP/9_tbl_empexp_qry.dmp
 


 
/********************************
-- IMPORT
********************************/
-- 전체 IMP(왠만하면 사용자 스키마로 제약해서 export하자)
$ imp userid=user/password full=y \
      file=/home/oracle/EXP/1_full.dmp

-- 테이블스페이스 IMP
-- 다른 소유자로 생성
-- drop table mapbak.* purge;
$ imp userid=user/password tablespaces=users \
      file=/home/oracle/EXP/2_ts_users.dmp \
      fromuser=scott touser=mapbak

-- 스키마 IMP
-- drop table scott.* purge;
$ imp userid=user/password \
      file=/home/oracle/EXP/3_sch_scott.dmp \
      fromuser=scott touser=scott

-- 테이블 IMP
-- tables에 (소유자.)을 넣으면 에러 발생
-- drop table scott.emp purge;
$ imp userid=user/password tables=emp \
      file=/home/oracle/EXP/4_tbl_emp.dmp \
      fromuser=scott touser=scott

-- 테이블 IMP(constraint=N)
-- drop table scott.empexp purge;
$ imp userid=mapbak/passwd tables=empexp constraints=n \
      file=/home/oracle/EXP/5_tbl_empexp_const.dmp \
      fromuser=scott touser=scott

select * from dba_constraints where owner='SCOTT' and table_name = 'EMPEXP';

-- 테이블 IMP(indexes=N)
-- drop table scott.empexp purge;
$ imp userid=mapbak/passwd tables=empexp indexes=n \
      file=/home/oracle/EXP/7_tbl_empexp_idx.dmp \
      fromuser=scott touser=scott

select * from dba_indexes where owner='SCOTT' and table_name = 'EMPEXP';

-- 테이블 IMP(rows=N)
-- drop table scott.empexp purge;
$ imp userid=mapbak/passwd tables=empexp rows=n \
      file=/home/oracle/EXP/8_tbl_empexp_idx.dmp \
      fromuser=scott touser=scott
     
select * from scott.empexp;
 



/********************************
-- IMP/EXP 빠르게 하는 방법
********************************/
-- 노아카이브 모드
   DIRECT=Y, INDEXES=N
-- 아카이브 모드
   DIRECT=N, INDEXES=Y
-- 옵션
   > 한 개의 커다른 Rollback Segment 생성(가장 큰 테이블의 50%정도)
   > Noarchive Mode
   > SORT_AREA_SIZE 증가
   > COMMIT=N
   > Buffer 크기 증가
   > INDEXES=N, INDEXFILE Option 사용
   > Direct Path 사용
-- 시간 체크
& time exp user/password full=y ....

-- BEST CASE(Direct IMP는 Direct EXP된 파일을 올릴 때 자동으로 Direct 되는 듯...)
    > 노아카이브
    > EXP DIRECT=Y
    > IMP COMMIT=N
    > IMP BUFFER=10247680

 
 
반응형

+ Recent posts