-- Title : [10g] Datapump 사용법 - ver.dbrang
-- Reference : dbrang.tistory.com dinggur.tistory.com/
-- Key word : 데이터펌프 데이터 펌프 expdp impdp
********************************************************************************************/
/********************************
-- 디렉토리 생성
********************************/
-- 디렉토리 생성
create or replace directory pump_dir as '/home/oracle/pump';
-- 생성 확인
select * from dba_directories
-- 권한 부여
grant read, write on directory pump_dir to public;
/********************************
-- EXPDP
********************************/
-- full
$ expdp ttt/ttt full=y \
directory=pump_dir dumpfile=1_full.dmp
-- tablespace
$ expdp ttt/ttt tablespaces=users \
directory=pump_dir dumpfile=2_tbs_users.dmp
-- schema
$ expdp ttt/ttt schemas=scott \
directory=pump_dir dumpfile=3_sch_scott.dmp
-- table
$ expdp ttt/ttt tables=scott.emp \
directory=pump_dir dumpfile=4_tbl_emp.dmp
-- table(parallel=2)
$ expdp ttt/ttt tables=scott.emp parallel=2 \
directory=pump_dir \
dumpfile=5_tbl_emp_paral_1.dmp, 5_tbl_emp_paral_2.dmp
-- table(exclude=indexes)
$ expdp ttt/ttt tables=scott.emp exclude=index:\"like \'EMP%\'\" \
directory=pump_dir dumpfile=6_tbl_emp_excl_idx.dmp
-- table(content=metadata_only)
$ expdp ttt/ttt tables=scott.emp content=metadata_only \
directory=pump_dir dumpfile=7_tbl_emp_cntnt_meta.dmp
-- table(query)
$ expdp ttt/ttt tables=scott.emp \
query=\"where job\=\'SALESMAN\' and sal \<1600\" \
directory=pump_dir dumpfile=8_tbl_emp_query.dmp
/********************************
-- IMPDP
********************************/
-- tablespace(include, table_exists_action)
$ impdp ttt/ttt tablespaces=users \
include=table:\"like \'EMP\'\" table_exists_action=replace \
directory=pump_dir dumpfile=2_tbs_users.dmp
-- schema(remap_schema)
$ impdp ttt/ttt schemas=scott \
remap_schema='scott':'ttt' \
directory=pump_dir dumpfile=3_sch_scott.dmp
-- schema(exclue=table:"='EMP'")
$ impdp ttt/ttt schemas=scott \
exclude=table:"\='EMP'" \
directory=pump_dir dumpfile=3_sch_scott.dmp
-- table(exclude=index)
$ impdp ttt/ttt tables=scott.emp \
exclude=index table_exists_action = replace \
directory=pump_dir dumpfile=4_tbl_emp.dmp
-- table(content=metadata_only)
$ impdp ttt/ttt tables=scott.emp \
content=metadata_only table_exists_action = replace \
directory=pump_dir dumpfile=4_tbl_emp.dmp
-- table(sqlfile)
$ impdp ttt/ttt tables=scott.emp \
sqlfile=datapump.sql \
directory=pump_dir dumpfile=4_tbl_emp.dmp
impdp 관련 파라미터
○ Include
: Import 원하는 테이블만
- Include=object_name:\"\=\'조건\'\"
Ex. SQL> impdp scott/tiger directory=datapump dumpfile=scott05.dmp include=table:\"\=\'emp\'\"
→ emp테이블만 impdp해라.
○ Exclude
: 특정 테이블만 빼고 impdp 하려고 할때 사용
- 사용법은 include와 동일
○ Table_exists_action
- skip : 같은 테이블을 만나면 건너뛰고 다음 테이블을 impdp 한다.
- append : 같은 테이블을 만나면 기존 내용에 데이터를 추가 한다.
Cf. exp는 무조건 append 이다.
- truncate : 같은 테이블을 만나면 기존 테이블을 truncate 하고 새로 impdp 한다.
- drop : 기존 테이블을 drop 하고 테이블을 새로 만들어서 새로운 내용을 impdpd 한다.
○ Remap_schema
: Scott user로 expdp 받은테이블을 다른 유저로 impdp 할때 사용함
- remap_schema=scott:hr
○ Remap_tablespace
: 기존 테이블스페이스에서 다른 테이블스페이스로 테이블을 impdp 시킬때 사용
- Remap_tablespace='users':'example'
Cf. 테이블 스페이스 이동시키기
※ 하고나서 주의사항 : 인덱스까지 재생성 or Rebuild
이유 : 테이블 스페이스가 바뀌었기 때문에(인덱스안의 RowID에는 테이블스페이스번호 맨앞부분에 포함됨)
Ex. SQL> Alter table hr.employees move tablespace data1;