티스토리 뷰

 

OS 환경 : Oracle Linux 6.3
DB 환경 : Oracle Database 12.1.0.2
SID : PROD, testdb open
listener : startup

 

1. PROD의 employees, departments table을 기반으로 testdb의 hr schema에 emp_sample, dept_sample을 생성한다.

 

testdb 데이터베이스에서 PROD 데이터베이스의 데이터를 사용하기 위해서 DB Link를 사용하겠다.

 

 

*DB Link란?

- remote에 있는 데이터를 사용하기 위해 사용한다(다른 DB의 객체에 접근하기 위한 객체) .
- 서버에서 서버로 가기위한 링크이다.

- Local Server는 Remote Server에 대한 Client라고 할 수 있다(당연히 로컬서버의 리스너 필요 없음).

 

 

 

'AAA'라는 이름의 PROD 데이터베이스로 연결하는 네트워크를 이용하여 'prod_link'라는 이름의 DB Link를 생성한다.

create public database link prod_link 
connect to hr identified by hr 
using 'AAA';

 

 

 

 

먼저 리스너를 켜준다.

[testdb@host01 ~]$ lsnrctl start

 

 

 

DB Link를 사용하여 PROD DB의 데이터를 조회한다.

testdb> conn hr/hr
testdb> select * from departments@prod_link;

 

 

 

 

DB Link를 통해 PROD 데이터베이스의 데이터를 이용해서 testdb 데이터베이스의 hr 계정에 테이블을 생성한다.

newdb> create table emp_sample as select * from employees@prod_link;
newdb> create table dept_sample as select * from departments@prod_link;




2. testdb에 있는 emp_sample, dept_sample 테이블을 datapump를 활용하여 dump파일을 만든 후 PROD 데이터베이스로 다음과 같은 조건에 맞게 이동시킨다.

   2.1 HR schema에 있던 것을 SCOTT schema로 변경하여 impdp수행한다.

   2.2 테이블스페이스 오류 발생 문제를 해결한다.

   2.3 테이블의 이름은 EMP_SAMPE → EMP_TEST, DEPT_SAMPLE → DEPT_TEST로 생성한다.

 

먼저, 이동할 데이터의 파일 디렉토리를 생성한다.

[testdb@host01 ~]$ mkdir -p /home/oracle/testdb/datapump

 

 

export/import를 수행하기 위한 디렉토리 객체를 생성한다.

create or replace directory testdb_dir as '/home/oracle/testdb/datapump';

 

 

유저에게 권한을 부여한다.

grant read, write on directory testdb_dir to sh, hr, scott;

 

 

export 작업을 수행하였는데 ora-01658 에러가 발생했다. 해당 테이블스페이스의 공간이 부족해서 발생한 문제이다.

[testdb@host01 ~]$ expdp hr/hr dumpfile=hr.dmp directory=testdb_dir tables=emp_sample, dept_sample

 

 

 

USERS 테이블스페이스의 사용공간을 조회한다.

select * 
from dba_free_space 
where tablespace_name='USERS';

 

 

 

USERS 테이블스페이스의 파일 경로를 조회한다.

select tablespace_name, file_name
from dba_data_files;

 

 

 

데이터파일을 추가해준다.

alter tablespace users 
add datafile '/u01/app/oracle/oradata/testdb/disk1/users_a.dbf' size 50m;

 

 

 

다시 export 작업을 수행해보면 잘 수행된다.

[testdb@host01 ~]$ expdp hr/hr dumpfile=hr.dmp directory=testdb_dir tables=emp_sample, dept_sample

 

 

 

 

이제 PROD 데이터베이스로 import 작업을 수행한다. 그런데 PROD 데이터베이스는 디렉토리 객체로 '/home/oracle/prod/datapump' 위치의 prod_dir 디렉토리를 사용하고 있다. 따라서 아래와 같이 dumpfile을 PROD 데이터베이스의 디렉토리 객체 위치로 복사한 후 import 작업을 수행한다(import 작업은 system 유저만 가능하다).

[PROD@host01 ~]$ cp /home/oracle/testdb/datapump/hr.dmp /home/oracle/prod/datapump/
[PROD@host01 ~]$ impdp system/oracle_4U dumpfile=hr.dmp directory=prod_dir remap_schema=hr:scott remap_table=hr.emp_sample:emp_test, hr.dept_sample:dept_test;

 

 

 

*dumpfile 복사없이 import 하는 방법

PROD 데이터베이스의 디렉토리 객체 경로를 변경해준 후 import 작업을 수행한다.

PROD> create or replace directory testdb_dir as '/home/oracle/testdb/datapump';
PROD> grant read, write on directory testdb_dir to sh, hr, scott;
[PROD@host01 ~]$ impdp system/oracle_4U dumpfile=hr.dmp directory=testdb_dir remap_schema=hr:scott remap_table=hr.emp_sample:emp_test, hr.dept_sample:dept_test

 

 

 

import 작업이 성공적으로 완료되었다

 

 

 

 

 

3. PROD database의 scott, hr schema를 testdb로 이동하시오.

scott, hr 스키마 전체를 import 하기 위해서 이전에 실습했던 내용들을 지우기 위해 유저를 삭제한다.

testdb> drop user scott cascade;
testdb> drop user hr cascade;

 

 

이번 실습을 저장할 sample 테이블스페이스를 생성한다.

CREATE TABLESPACE SAMPLE 
DATAFILE '/u01/app/oracle/oradata/testdb/disk2/sample.dbf' SIZE 400M AUTOEXTEND ON
MAXSIZE 4G
EXTENT MANAGEMENT LOCAL UNIFORM SIZE 1M;

 

 

PROD 데이터베이스에서 scott, hr 스키마를 export 한다.

[PROD@host01 ~]$ expdp system/oracle_4U dumpfile=prod_full.dmp directory=prod_dir schemas=scott, hr;

 

 

 

dumpfile을 testdb의 디렉토리 객체 위치로 복사해준다.

[PROD@host01 ~]$ cp /home/oracle/prod/datapump/prod_full.dmp /home/oracle/testdb/datapump/

 

 

 

testdb 데이터베이스에서 import 작업을 수행하는데, 저장될 테이블스페이스를 example에서 sample로 변경한다.

[testdb@host01 ~]$ impdp system/oracle_4U dumpfile=prod_full.dmp directory=testdb_dir remap_tablespace=example:sample;

 

 

 

testdb> conn hr/hr
testdb> select table_name, tablespace_name from tabs;

 

 

 

testdb> conn scott/tiger
testdb> select table_name, tablespace_name from tabs;

정상적으로 import 되었다.

 

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
글 보관함