반응형

EDB에서 제공하는 Migration Tool Kit

 

소스는 Oracle, Mysql , EDB , PG 있고, 타겟은 EDB만 가능

 

사용가능 DBMS

PostgreSQL versions 9.5, 9.6, 10,11, and 12
Advanced Server versions 9.5, 9.6, 10,11 and 12
Oracle 10g Release 2
Oracle 11g Release 2
Oracle 12c Release 1
SQL Server 2008
SQL Server 2012
SQL Server 2014
MySQL 5.5.36
Sybase Adaptive Server Enterprise 15.7

 

필요 요구사항 : 자바 1.7이상

                     EDB 사이트 가입 아이디 필요 (설치 시에 물어 )

                     EDB owner(enterprisedb) Oracle Client 필요.

 

1. JAVA 설치 (root 유저)

Linux Java 압축 해제

tar xvfz jdk-8u241-linux-x64.tar.gz

Linux rpm으로 설치 아니라서 패스에 등록하기 위한 디렉터리 생성 java 파일 이동

mkdir /usr/local/JDK

mv jdk1.8.0_241 /usr/local/JDK/

Java Path 등록

vi /etc/profile  (파일 제일 밑에 다음 추가)

 

#JDK Path

export JAVA_HOME=/usr/local/JDK/jdk1.8.0_241

export PATH=$PATH:$JAVA_HOME/bin

 

서버 Rebooting  없이 Java 패스 적용

source /etc/profile

Java 확인

which java

/usr/local/JDK/jdk1.8.0_241/bin/java

java -version

java version "1.8.0_241"

Java(TM) SE Runtime Environment (build 1.8.0_241-b07)

Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)

 

2. MTK 설치 (root 유저)

unzip edb-migrationtoolkit-51.0.1-1-linux-x64.run.zip

chmod 777 edb-migrationtoolkit-51.0.1-1-linux-x64.run

./edb-migrationtoolkit-51.0.1-1-linux-x64.run

 

설치는 영어로 하고, 설치 중간에 EDB 가입 메일과 비번 물어보면 입력

기본 설치 경로는 /opt/edb/mtk

 

소스와 타겟 정보를 설정해 주는 파일 백업

cd /opt/edb/mtk/etc

cp toolkit.properties toolkit.properties.bak  (혹시 모르니 백업)

소스와 타겟 DB 설정

vi toolkit.properties  (소스,타겟 수정)

 

소스 : 192.168.56.200 / ora11g / SH유저의 데이터 마이그레이션 예정

타겟 : 192.168.56.110 / tpch DB sh 스키마로 데이터 이전 예정

 

RC_DB_URL=jdbc:oracle:thin:@192.168.56.200:1511:ora11g
SRC_DB_USER=system
SRC_DB_PASSWORD=oracle


TARGET_DB_URL=jdbc:edb://192.168.56.110:5444/tpch
TARGET_DB_USER=sh
TARGET_DB_PASSWORD=sh

 

기타 DB 설정 참고

다른 )
ex) EDB PG source/target 되고 나머지 Oracle,Mysql source 가능

[PG]
SRC_DB_URL=jdbc:postgresql://192.168.56.110:5411/postgres
SRC_DB_USER=postgres
SRC_DB_PASSWORD=root

TARGET_DB_URL=jdbc:postgresql://192.168.56.110:5411/postgres
TARGET_DB_USER=postgres
TARGET_DB_PASSWORD=root

[Oracle]
SRC_DB_URL=jdbc:oracle:thin:@192.168.56.200:1511:ora11g
SRC_DB_USER=sh
SRC_DB_PASSWORD=sh

[Mysql]
SRC_DB_URL=jdbc:mysql://192.168.56.100[:5432]/tpch
SRC_DB_USER=soe
SRC_DB_PASSWORD=soe

 

소스가 Oracle인데 오라클 jar 파일 없으니 다음 파일 업로드 후에 /opt/edb/mtk/lib 넣어

 

[root@pgmechine lib]# pwd

/opt/edb/mtk/lib

[root@pgmechine lib]# ls

commons-lang3-3.1.jar  edb-commons.jar  edb-jdbc17.jar  log4j-1.2.17.jar  ojdbc6.jar  ojdbc7.jar  ojdbc8.jar

 

3. MTK 사용 (root 유저)

cd /opt/edb/mtk/bin

 

3.1 스키마만 먼저 conversion

./runMTK.sh -schemaOnly SH  <-- 유저 대문자

3.2 스키마는 만들어 졌으니 data conversion

./runMTK.sh -dataOnly -fastCopy SH    <-- fastCopy 벌크 로딩으로 속도를 빠르게 하기 위함

 

CLOB 테이블은 마이그레이션 하는데 다음과 같은 에러

 

Loading Large Objects into table: TEST_CLOB ...

MTK-17001: Error Loading Data into Table: TEST_CLOB

DB-42501: com.edb.util.PSQLException: ERROR: permission denied for relation pg_class

 

LOB fastCopy 사용하지 못하고 copyViaDBLinkOra 사용해서 넣어야 .

 

3.3 LOB 가져오기 위해서는 EDB 기동 오라클 클라이언트를 물고 기동해야 한다.

 

오라클 클라이언트 설치 (enterprisedb 유저)

su - enterprisedb

unzip instantclient-basic-linux.x64-19.5.0.0.0dbru.zip

unzip instantclient-sqlplus-linux.x64-19.5.0.0.0dbru.zip

unzip instantclient-sdk-linux.x64-19.5.0.0.0dbru.zip

cd ~

 

vi .bash_profile

export ORACLE_HOME=/home/enterprisedb/instantclient_19_5
export TNS_ADMIN=/home/enterprisedb/instantclient_19_5

export PATH=$PATH:$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME

 

3.4 EDB postgresql.conf 환경변수 oracle_home 설정

 

vi postgresql.conf

 

oracle_home ='/home/enterprisedb/instantclient_19_5'        

 

EDB 기동

 

3.5 Error났던 LOB 테이블만 다시 데이터 밀어 넣기

 

./runMTK.sh -dataOnly -copyViaDBLinkOra -tables TEST_CLOB SH  <-- 테이블 , 유저 대문자

 

혹시 명령어 수행하다가 아래와 같은 에러 나면

 

MTK-11014: Error connecting to DBLinkOra
DB-HV00N: com.edb.util.PSQLException: ERROR: unable to load OCI library: libnnz19.so: cannot open shared object file: No such file
  Hint: Either the oracle_home guc setting or Oracle library must be in path at the time you start the server.

 

enterprisedb 유저의 ORACLE_HOME 설정 postgresql.conf oracle_home 설정이 제대로 되어 있는지 확인하고, 제대로 되어 있는데도 에러가 나면 수동으로 enterprisedb 기동 해줌

서버 start시에 자동으로 edb 기동되게 되어 있는데 이때 환경변수나 postgresql.conf 읽어 가는 .

 

./runMTK.sh -dataOnly -copyViaDBLinkOra -tables TEST_CLOB SH  

 

수행 아래 에러가 발생 . LOB 가져오기 위해서는 super 유저 권한이 필요 .

 

MTK-11014: Error connecting to DBLinkOra
DB-42501: com.edb.util.PSQLException: ERROR: must be superuser to use dblink_ora

 

enterprisedb 로그인해서 superuser 권한을 SH에게 부여

 

alter user sh with superuser ;

 

./runMTK.sh -dataOnly -copyViaDBLinkOra -tables TEST_CLOB SH       --> 정상적으로 마이그레이션이 .

 

4. 다른 유저로 데이터 넘기기

기본적으로 MTK 사용하면 오라클의 스키마와 같은 스키마로 데이터를 마이그레이션 한다.

SH 유저에 superuser 권한이 부여 되어 있는 상태이니 toolkit.properties 파일은 수정하지 않고 오라클의 SH 유저의 테이블을 EDB soe 유저로 옮기는 테스트를 진행해 본다.

넘어 가는 지만 테스트 하면 되니, 일반 테이블과 LOB 테이블 개만 테스트 보기로 ...

 

create tablespace tbs2 location '/edb10.5/tbs2' ;
create user soe identified by soe ;
create database tpcc owner soe tablespace tbs2 ;

 

./runMTK.sh -schemaOnly -targetSchema soe -tables CHANNELS,TEST_CLOB SH

 

toolkit.properties파일에는 EDB 로그인을 SH 유저로 하고 , targetschema soe 했더니

pg_tables 조회해 보면 chanels test_clob 테이블의 스키마는 soe 되었지만, table_owner sh .

 

LOB 데이터도 넘겨야 하니 EDB에서 superuser 권한을 soe에게 주고 toolkit.properties 파일의 EDB 로그인 유저를 soe 바꿔서 다시 수행해 보자.

 

alter user soe with superuser ;

 

SRC_DB_URL=jdbc:oracle:thin:@192.168.56.200:1511:ora11g
SRC_DB_USER=system
SRC_DB_PASSWORD=oracle

TARGET_DB_URL=jdbc:edb://192.168.56.110:5444/tpcc
TARGET_DB_USER=soe
TARGET_DB_PASSWORD=soe

 

./runMTK.sh -schemaOnly -targetSchema soe -tables CHANNELS,TEST_CLOB SH

 

정상적으로 schema tableowner soe 생성 .

 

이제 데이터 넣어보기

 

./runMTK.sh -dataOnly -fastCopy -targetSchema soe -tables CHANNELS SH

./runMTK.sh -dataOnly -copyViaDBLinkOra -targetSchema soe -tables TEST_CLOB SH

 

개의 테이블 모두 정상적으로 데이터가 들어 .

 

5. 스키마의 여러 테이블 중에서 특정 테이블만 넘기기

scott 여러 테이블 중에서 2개의 테이블만 넘기고자 한다면

 

./runMTK.sh -tables EMP,DEPT SCOTT

 

******************** Migration Summary ********************

Tables: 2 out of 2

 

Total objects: 2

Successful count: 2

Failed count: 0

Invalid count: 0

 

*************************************************************

 

위와 같이 넘기면 오로지 테이블 생성과 테이블 데이터만 넘어감.  emp dept 각자 PK FK 가지고 있으며, PK 해당하는 인덱스가 존재 .

 

SQL> select constraint_name , table_name , constraint_type from user_constraints ;

CONSTRAINT_NAME                TABLE_NAME                      C
------------------------------ ------------------------------ -
FK_DEPTNO                       EMP                              R
PK_DEPT                        DEPT                              P
PK_EMP                               EMP                              P
SQL> create index emp_idx01 on emp ( empno , sal ) ;
Index created.

SQL> select index_name , table_name from user_indexes ;

INDEX_NAME                       TABLE_NAME
------------------------------ ------------------------------
PK_EMP                               EMP
EMP_IDX01                       EMP
PK_DEPT                        DEPT

 

제약 조건 인덱스를 생성하고자 다음과 같이 옵션을 주고 다시 시도하면

 

./runMTK.sh -indexes -constraints -tables EMP,DEPT SCOTT

******************** Migration Summary ********************

Tables: 2 out of 2

Constraints: 3 out of 3

Indexes: 1 out of 1

 

Total objects: 6

Successful count: 6

Failed count: 0

Invalid count: 0

*************************************************************

 

위의 결과를 보면 인덱스는 1 마이그레이션 처럼 보이지만 대한 언급은 없지만 실제 EDB에서 조사를 보면 PK 해당하는 인덱스가 생성

 

tiger=> /c tiger scott


tiger=> \d
       List of relations
 Schema | Name | Type  | Owner
--------+------+-------+-------
 scott  | dept | table | scott
 scott  | emp  | table | scott
(2 rows)


tiger=> \dt+
                    List of relations
 Schema | Name | Type  | Owner |    Size    | Description
--------+------+-------+-------+------------+-------------
 scott  | dept | table | scott | 8192 bytes |
 scott  | emp  | table | scott | 8192 bytes |
(2 rows)


tiger=> \di
             List of relations
 Schema |   Name    | Type  | Owner | Table
--------+-----------+-------+-------+-------
 scott  | emp_idx01 | index | scott | emp
 scott  | pk_dept   | index | scott | dept
 scott  | pk_emp    | index | scott | emp
(3 rows)


tiger=> \d+ emp
                                                Table "scott.emp"
  Column  |            Type             | Collation | Nullable | Default | Storage  | Stats target | Description
----------+-----------------------------+-----------+----------+---------+----------+--------------+-------------
 empno    | numeric(4,0)                |           | not null |         | main     |              |
 ename    | character varying(10)       |           |          |         | extended |              |
 job      | character varying(9)        |           |          |         | extended |              |
 mgr      | numeric(4,0)                |           |          |         | main     |              |
 hiredate | timestamp without time zone |           |          |         | plain    |              |
 sal      | numeric(7,2)                |           |          |         | main     |              |
 comm     | numeric(7,2)                |           |          |         | main     |              |
 deptno   | numeric(2,0)                |           |          |         | main     |              |
Indexes:
    "pk_emp" PRIMARY KEY, btree (empno)
    "emp_idx01" btree (empno, sal)
Foreign-key constraints:
    "fk_deptno" FOREIGN KEY (deptno) REFERENCES dept(deptno)


tiger=> \d+ dept
                                           Table "scott.dept"
 Column |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description
--------+-----------------------+-----------+----------+---------+----------+--------------+-------------
 deptno | numeric(2,0)          |           | not null |         | main     |              |
 dname  | character varying(14) |           |          |         | extended |              |
 loc    | character varying(13) |           |          |         | extended |              |
Indexes:
    "pk_dept" PRIMARY KEY, btree (deptno)
Referenced by:
    TABLE "emp" CONSTRAINT "fk_deptno" FOREIGN KEY (deptno) REFERENCES dept(deptno)


tiger=>

 

6. MTK 옵션

참고 URL : https://www.enterprisedb.com/edb-docs/d/edb-postgres-advanced-server/user-guides/migration-guide/9.4/Postgres_Plus_Migration_Guide.1.24.html#

 

Feature: Section Relevant Options:
Offline Migration 7.1 -offlineMigration
Import Options 7.2 -sourcedbtype, -targetdbtype, -schemaOnly, -dataOnly
Schema Creation Options 7.3 -dropSchema, -targetSchema
Schema Object Selection Options 7.4 -allTables, -tables,
-constraints, -ignoreCheckConstFilter,
-skipCKConst, -skipFKConst,
-skipColDefaultClause,
-indexes, -triggers,
-allViews, -views,
-allSequences, -sequences,
-allProcs, -procs,
-allFuncs, -funcs,
-checkFunctionBodies,
-allPackages, -packages,
-allRules,
Migration Options 7.5 -truncLoad, -enableConstBeforeDataLoad,
-retryCount, -safeMode, -fastCopy,
-analyze, vacuumAnalyze, -replaceNullChar,
-copyDelimiter, -batchSize,
-cpBatchSize,
-fetchSize, -filterProp
-customColTypeMapping, -customColTypeMappingFile
Oracle Specific Options 7.6 -allUsers, -users, -importPartitionAsTable,
-objectTypes,
-copyViaDBLinkOra, -allDBLinks
-allSynonyms, -allPublicSynonyms,
-allPrivateSynonyms, -useOraCase
Miscellaneous Options 7.7 -help, -logDir, -logFileCount, -logFileSize,
-logBadSQL -verbose, -version

 

반응형

+ Recent posts