oracle 12c

14. (데이터 이행 전체 과정) orcl쪽의 scott의 모든 테이블 스페이스의 테이블과 기타 object 들을 prod 쪽으로 깔끔하게 이행하는 방법

오운학 2024. 5. 1. 11:34

#1. prod쪽에 scott유저를 drop하세요

prod >  alter session set "_ORACLE_SCRIPT"=true;

prod > revoke dba from scott;

 

#2. prod 쪽에 ts2000 테이블 스페이스를   drop  하시오 !

prod> drop  tablespace   ts2000  including  contents  and datafiles;

 

#3. orcl 쪽에 scott유져가 가지고 있는 테이블들이 어느 테이블 스페이스에
     속해 있는지 확인하시오 !

COLUMN table_name FORMAT A30
COLUMN tablespace_name FORMAT A20

SELECT table_name, tablespace_name
FROM dba_tables
WHERE owner = 'SCOTT';


#4. orcl 쪽에  king 이라는 유져를 만들고 king 유져로 접속해서 테이블과
     인덱스를 여러개 생성하시오!

orcl> alter session set "_ORACLE_SCRIPT"=true;

orcl> create  user  king   identified  by  tiger;

orcl> grant  dba  to  king;

orcl>  connect  king/tiger

orcl>  create  tablespace  ts7000
          datafile  '/home/oracle/ts7000.dbf'  size  100m;

orcl> create  table   emp  
       tablespace  ts7000
    as  select * from scott.emp;

orcl> create  table   dept  
       tablespace  ts7000
      as  select * from scott.dept;

orcl> create  table  salgrade
        tablespace  ts7000
       as  select * from scott.salgrade;

#5. 인덱스도 다음과 같이 생성합니다.

orcl> create  index  emp_sal  
         on  emp(sal)
         tablespace   ts7000;

orcl> create  index  emp_job
         on  emp(job)
         tablespace  ts7000;

orcl> create  index  dept_deptno
        on  dept(deptno)
        tablespace  ts7000;

orcl> select  table_name, tablespace_name
        from  user_tables; 

orcl> select  index_name, tablespace_name
          from  user_indexes;

 

#6. ts7000테이블 스페이스를 read only로 변경하세요

alter tablespace ts7000 read only;

 

#7. ts7000테이블 스페이스를 tablesapce level로 export하세요

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

유저명 : system

패스워드 : oracle_4U

 

#8. /home/oracle/pump_orcl밑에 있는 ts7000.dmp파일을 /home/oracle/pump_prod 밑에 복사하세요

 

cp /home/oracle/pump_orcl/ts7000.dmp  /home/oracle/pump_prod/ts7000.dmp

 

#9. /home/oracle/ts7000.dbf파일을 /u01/app/oracle/oradata/PROD/ts7000.dbf로 copy합니다

cp /home/oracle/ts7000.dbf  /u01/app/oracle/oradata/PROD/ts7000.dbf

 

#10. prod db쪽에 king유저를 생성하세요

alter session set "_oracle_script"=true
create user king identified by tiger;
grant dba to king;

#11. ts7000.dmp 파일을 prod쪽에 임폴트합니다

impdp directory=prod_dir dumpfile=ts7000.dmp transport_datafiles='/u01/app/oracle/oradata/PROD/ts7000.dbf'

 

 

#12. prod쪽에서 ts7000테이블 스페이스를 read write하세요

alter tablespace ts7000 read write;

 

#13. prod쪽에 king유저로 접속해서 테이블이 잘이행되었는지 확인하세요

 

exec dbms_stats.gather_schema_stats('king');

select table_name , num_rows
from user_tables;


SELECT index_name
FROM user_indexes;

 

 

 

 

DB엔지니어로써 갖춰야할 기본적인 마음가짐

1) 오라클 기술 공부를 할때는 꼭 문서화를 해서 회사에 기술지원팀 메일로 배포하는 습관을 갖추어야한다

2) 사이트에 나가서 개인적으로 배운 경험들을 또 회사에 공유를 해주는 습관을 갖춰야한다.