DBAtlas · Atlas für Datenbankbetrieb

Migration auf eine andere Datenbank (heterogen)

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

Für die heterogene Migration von Oracle (vor allem nach PostgreSQL) ist Ora2Pg das verbreitetste Open-Source-Tool: Es konvertiert Tabellen, Constraints, PL/SQL und Daten in den Zieldialekt; --estimate_cost schätzt den Migrationsaufwand. Für Online-Migration bzw. Migration mit geringer Ausfallzeit werden AWS DMS oder Oracle GoldenGate (mit CDC) eingesetzt.

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 ist das Standardtool für die Migration aus anderen Engines (MySQL, SQLite, MS SQL) nach PostgreSQL: Mit Verbindungsstrings legt es das Schema mit einem einzigen Befehl an, bildet Typen ab und kopiert Daten schnell; eigene Transformationen/Typzuordnungen werden in einem .load-Skript definiert. Ist die Quelle Oracle, wird Ora2Pg bevorzugt; für Online-Migration 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

Für die Migration aus anderen Engines nach MySQL gibt es kein einzelnes dominierendes offenes Tool; am verbreitetsten ist AWS DMS (verwaltet, CDC-fähig) oder den Quelldump an Syntax/Typen anzupassen und mit dem mysql-Client zu laden. MySQL und MariaDB sind weitgehend kompatibel; mysqldump-Ausgaben lassen sich meist direkt übernehmen.

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

Für die Migration von SQL Server nach PostgreSQL wird pgloader (Quelle mssql://) genutzt; wer T-SQL ohne Anwendungsänderung behalten will, bekommt mit Babelfish for Aurora PostgreSQL eine Kompatibilitätsschicht. Microsofts Tool SSMA automatisiert die Migration aus anderen Engines (Oracle, MySQL, DB2) nach SQL Server. Für Online-Migration 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)

Die Migration zwischen MongoDB und SQL-Engines erfordert eine Umwandlung zwischen Zeilen- und Dokumentmodell (ETL); einen automatischen Einzelbefehl gibt es nicht. Von SQL nach MongoDB bildet MongoDB Relational Migrator Tabellen auf ein Dokumentschema ab; in einfachen Fällen aus der Quelle CSV/JSON erzeugen und mit mongoimport laden. In umgekehrter Richtung wird die Ausgabe von mongoexport mit COPY/LOAD DATA in die relationale Zieltabelle geladen.

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

Bei heterogener Migration ist Redis meist die Cache-Schicht als Ziel/Quelle; um Daten aus relationalen oder Dateiquellen in Redis zu laden, wird das offizielle Redis-Tool RIOT genutzt (db-import bildet ein SQL-Ergebnis auf HSET/SET-Strukturen ab). Für Redis zu Redis oder in eine Datei gibt es die Befehle 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" } }

Das verbreitetste Tool für die Migration aus anderen Datenbanken nach Elasticsearch ist Logstash (JDBC-/Datei-Input -> elasticsearch-Output); auch Elastics eigene Connectors/Beats werden genutzt. Beim Umzug von einem alten auf einen neuen Elasticsearch-Cluster ist Remote Reindex (_reindex mit Quelle 'remote') üblich; auf dem Ziel muss reindex.remote.whitelist definiert sein.

In DBAtlas öffnen →