別のデータベースへ移行(異種間)
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 GoldenGateOracle からの異種間移行(特に 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 DMSpgloader は他のエンジン(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 DMSSQL 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 入力 -> elasticsearch 出力)。Elastic 独自のコネクタ/Beats も使用される。古い Elasticsearch クラスタから新しいクラスタへの移行では、リモート reindex('remote' ソースを指定した _reindex)が一般的。ターゲットに reindex.remote.whitelist を定義する必要がある。