DBAtlas · 데이터베이스 운영 아틀라스

다른 데이터베이스로 마이그레이션(이기종)

Oracle

# Oracle -> PostgreSQL: Ora2Pg (schema + data + PL/SQL conversion)
ora2pg -c ora2pg.conf -t TABLE   -o schema.sql
ora2pg -c ora2pg.conf -t COPY    -o data.sql   # data in COPY format
ora2pg -t SHOW_REPORT --estimate_cost           # migration cost estimate

# Oracle -> (multiple targets) managed/online: AWS DMS or Oracle GoldenGate

Oracle에서의 이기종 마이그레이션(특히 PostgreSQL로)에 가장 널리 쓰이는 오픈소스 도구는 Ora2Pg다. 테이블, 제약 조건, PL/SQL, 데이터를 대상 방언으로 변환하며, --estimate_cost로 마이그레이션 공수를 추정한다. 온라인/저다운타임 마이그레이션에는 AWS DMS나 Oracle GoldenGate(CDC 사용)를 사용한다.

PostgreSQL

# MySQL -> PostgreSQL: pgloader (schema+data+type conversion in one command)
pgloader mysql://app_user:password@source/shop \
         postgresql://app_user:password@target/shop

# Also from SQLite/MSSQL sources: with a pgloader ./migration.load script
# For a managed/online PostgreSQL target: AWS DMS

pgloader는 다른 엔진(MySQL, SQLite, MS SQL)에서 PostgreSQL로 마이그레이션하는 표준 도구다. 연결 문자열을 주면 단일 명령으로 스키마를 생성하고 타입을 매핑하며 데이터를 빠르게 복사한다. 사용자 정의 변환/타입 매핑은 .load 스크립트에 정의한다. 소스가 Oracle이면 Ora2Pg가, 온라인 마이그레이션에는 AWS DMS가 권장된다.

MySQL

# PostgreSQL/Oracle/MSSQL -> MySQL: AWS DMS (managed) is the most common path
# or adapt the source-specific export for MySQL:
#   pg_dump --inserts ... | (type/syntax fixes) | mysql shop

# MySQL <-> MariaDB (compatible): mysqldump output loads directly
mysqldump --single-transaction shop | mysql -h target_mariadb shop

다른 엔진에서 MySQL로 마이그레이션하는 데 지배적인 단일 오픈 도구는 없다. 가장 일반적인 방법은 AWS DMS(관리형, CDC 지원)를 쓰거나 소스 덤프의 구문/타입을 수정해 mysql 클라이언트로 적재하는 것이다. MySQL과 MariaDB는 대부분 호환되므로 mysqldump 출력은 보통 그대로 이전된다.

SQL Server

# SQL Server -> PostgreSQL: with pgloader
pgloader mssql://app_user:password@source/shop \
         postgresql://app_user:password@target/shop

# SQL Server -> PostgreSQL compatibility layer: Babelfish for Aurora PostgreSQL
# (runs T-SQL and the TDS protocol on top of PostgreSQL)
# To other targets: SSMA (SQL Server Migration Assistant) or AWS DMS

SQL Server에서 PostgreSQL로의 마이그레이션에는 pgloader(mssql:// 소스)를 사용한다. 애플리케이션을 바꾸지 않고 T-SQL을 유지하려면 Babelfish for Aurora PostgreSQL이 호환 계층을 제공한다. Microsoft의 SSMA 도구는 다른 엔진(Oracle, MySQL, DB2)에서 SQL Server로의 마이그레이션을 자동화한다. 온라인 마이그레이션에는 AWS DMS를 사용한다.

MongoDB

# Relational <-> MongoDB conversion requires schema mapping (ETL):
#   - Relational Migrator (official MongoDB tool): maps tables to the document model
#   - or generate JSON from the source -> load with mongoimport
mongoexport --db=shop --collection=customer --type=csv --fields=id,name > c.csv
# (To an SQL target: mongoexport CSV -> relational COPY/LOAD DATA)

MongoDB와 SQL 엔진 간 마이그레이션에는 행<->문서 모델 변환(ETL)이 필요하며 자동화된 단일 명령은 없다. SQL에서 MongoDB로는 MongoDB Relational Migrator가 테이블을 문서 스키마로 매핑한다. 단순한 경우에는 소스에서 CSV/JSON을 생성해 mongoimport로 적재한다. 반대 방향에서는 mongoexport 출력을 COPY/LOAD DATA로 대상 관계형 테이블에 적재한다.

Redis

# With RIOT (Redis Input/Output Tools), to/from Redis from other sources:
#   Relational -> Redis:
riot db-import --jdbc-url "jdbc:postgresql://host/shop" \
  --sql "SELECT * FROM customer" hset --keyspace customer --keys id
#   Redis -> another Redis / file:  riot replicate / riot file-export

이기종 마이그레이션에서 Redis는 보통 대상/소스로서의 캐시 계층이다. 관계형 또는 파일 소스에서 Redis로 데이터를 적재하려면 Redis 공식 도구 RIOT를 사용한다(db-import는 SQL 결과를 HSET/SET 구조로 매핑). Redis에서 Redis로 또는 파일로는 riot replicate / file-export 명령이 있다.

Elasticsearch

# Relational/other source -> Elasticsearch: Logstash (JDBC input)
# logstash.conf: input { jdbc { statement => "SELECT * FROM customer" } }
#                output { elasticsearch { index => "customer" } }

# ES -> ES (version/cluster upgrade): reindex from a remote source
POST _reindex
{ "source": { "remote": { "host": "http://old:9200" }, "index": "customer" },
  "dest": { "index": "customer" } }

다른 데이터베이스에서 Elasticsearch로 마이그레이션하는 가장 일반적인 도구는 Logstash(JDBC/file input -> elasticsearch output)이며, Elastic 자체의 connector/Beats도 사용된다. 기존 Elasticsearch 클러스터에서 새 클러스터로 옮길 때는 remote reindex('remote' 소스를 지정한 _reindex)가 일반적이며, 대상에 reindex.remote.whitelist를 정의해야 한다.

DBAtlas에서 열기 →