Database초보우낙

13-2 본문

oracle 12c

13-2

오운학 2024. 5. 1. 11:12
수업시간에 배운 내용중에 데이터를 이행하는 방법에는 뭐가 있나요?

1. data pump  를 이용해서 데이터 이행

* data pump 를 이용하지 못하는 경우 
 1.   as-is db 와  to-be간에 컬럼의 변경이 많은 경우
 2.   이기종간 데이터 이행(서로 다른 db간의 데이터 이행)

2. append 와 parallel 힌트를 이용해서 서브쿼리를 사용한 insert 문


3. SQL*loader 를 이용해서 데이터 이행

 

 

 * 데이터 펌프의 종류

1) table level

2) user level

3) tablespace level  <-----제일 간단하고 쉬운 데이터 이행방법

4) database level

 

 


■  tablespace  level  로 export / import  pump 를 하는 방법

        as-is  db -------------------------------> to-be  db
          orcl                                              prod
   /home/oracle/pump_orcl                      /home/oracle/pump_prod
        datapump_dir                                 prod_dir 
          scott                                             jones

#1. orcl 쪽에 ts2000 이라는 테이블 스페이스를 생성합니다. 

 

#<orcl에서 진행>

select file_name from dba_data_files;

 

create tablespace ts2000
	datafile '/u01/app/oracle/oradata/ts2000.dbf' size 10m;

 

#2. scott유저로 접속해서 ts2000테이블 스페이스에 emp2000테이블을 생성

 

create table emp2000
tablespace ts2000
as
	select *
    	from emp;
        
        
select count(*) from emp2000;

 

 

#3. ts2000테이블 스페이스를 read only로 변경

#변경
alter tablespace ts2000 read only;

#변경되었는지 확인
select t.name , d.enabled
from v$tablespace t, v$datafile d
where t.ts# = d.ts#;

 

#4. ts2000 테이블 스페이스를 export

expdp directory=datapump_dir dumpfile=ts2000.dmp transport_tablespace=y tablespaces=ts2000

유져명: system
패스워드: oracle_4U

출력되는 메세지 중에 아래의 2개의 위치를 확인합니다.  

/home/oracle/oradata/ts2000.dbf   <----  data file 의 위치

/home/oracle/pump_orcl/ts2000.dmp  <--- pump 파일의 위치

 

#5. pump 파일인 /home/oracle/pump_orcl/ts2000.dmp 를
      /home/oracle/pump_prod/ts200.dmp 에 카피 하세요

$ cp /home/oracle/pump_orcl/ts2000.dmp  /home/oracle/pump_prod/ts200.dmp

#6. <prod>에서 진행
       datafile도 다음과 같이 카피

 

cd
pwd
cp /u01/app/oracle/oradata/ts2000.dbf /u01/app/oracle/oradata/PROD/ts2000.dbf

 

 

#7. prod 쪽에 ts2000.dmp 파일을 임폴트 합니다.

prod >  alter session set "_ORACLE_SCRIPT"=true;

prod > create user scott identified by tiger;

prod > grant dba to scott;

$ . oraenv
[prod:~]$ impdp  directory=prod_dir  dumpfile=ts200.dmp  transport_datafiles='/u01/app/oracle/oradata/PROD/ts2000.dbf'

유져이름: system
패스워드: oracle_4U 

#4. ts2000 테이블 스페이스를 read write 로 변경하시오 !

prod > select  t.name,  d.enabled
            from  v$tablespace   t,  v$datafile   d
            where  t.ts# = d.ts#; 

prod > alter  tablespace  ts2000  read  write; 

prod > select  t.name,  d.enabled
            from  v$tablespace   t,  v$datafile   d
            where  t.ts# = d.ts#; 

prod > connect scott/tiger


#5.  scott 유져의 테이블의 갯수와 그 건수를 확인합니다.

prod > connect scott/tiger

prod > exec dbms_stats.gather_schema_stats('SCOTT');

prod > select  table_name, num_rows from  user_tables;