Zwei Schemas/Umgebungen vergleichen (Schema-Diff)
Oracle
-- Extract the schema DDL from both environments and take a text diff
-- (generate deterministic DDL with DBMS_METADATA)
EXEC DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'SQLTERMINATOR',TRUE);
EXEC DBMS_METADATA.SET_TRANSFORM_PARAM(DBMS_METADATA.SESSION_TRANSFORM,'STORAGE',FALSE);
SELECT DBMS_METADATA.GET_DDL('TABLE', table_name) FROM user_tables ORDER BY table_name;
-- Spool the output to a file in both environments and compare with diff/fc.
-- Export the schema as a changelog with SQLcl's Liquibase integration:
-- SQL> lb generate-schema
-- Commercial: the Oracle SQL Developer 'Database Diff' tool is also used.Oracle hat keinen eingebauten Schema-Diff per Einzelbefehl. Üblich ist, in beiden Umgebungen mit DBMS_METADATA.GET_DDL deterministische DDL zu erzeugen (STORAGE-/Segmentattribute deaktiviert) und einen Text-Diff zu bilden. Für visuellen/automatisierten Vergleich nutze den Database-Diff-Assistenten von SQL Developer oder SQLcl.
PostgreSQL
# Dump only the schema from both databases and diff them
pg_dump --schema-only --no-owner --no-privileges sourcedb > source_schema.sql
pg_dump --schema-only --no-owner --no-privileges targetdb > target_schema.sql
diff -u source_schema.sql target_schema.sql
# Tool that generates applicable ALTERs: apgdiff (Another PostgreSQL Diff Tool)
# apgdiff source_schema.sql target_schema.sql > migration.sql
# Alternatives: migra, Liquibase diffChangeLogAm einfachsten erstellst du in beiden Umgebungen eine Ausgabe mit pg_dump --schema-only und vergleichst sie mit diff. apgdiff und migra sind Tools, die die Differenz direkt in ausführbare ALTER-Anweisungen umsetzen. Ergänze --no-owner --no-privileges für deterministische Ausgabe.
MySQL
# Schema/object comparison with MySQL Utilities (5.x):
mysqldbcompare --server1=root:password@host1 --server2=root:password@host2 \
shop:shop --difftype=sql --run-all-tests
# Built-in method: take CREATE statements from both environments and diff them
mysqldump --no-data --skip-comments shop > source_schema.sql
# SHOW CREATE TABLE customer; (to see a single table definition)Das Tool mysqldbcompare aus den MySQL Utilities meldet Objekt-/Schemaunterschiede zwischen zwei Servern (mit difftype=sql als anwendbare Anweisungen). Ohne Tool erstellst du in beiden Umgebungen eine Ausgabe mit mysqldump --no-data (nur Schema) oder SHOW CREATE TABLE und vergleichst mit diff. mysqldbcompare ist inzwischen veraltet; für MariaDB/8.x werden Liquibase oder Skeema bevorzugt.
SQL Server
-- Schema comparison/deploy report with SqlPackage (what will change before applying):
sqlpackage /Action:DeployReport /SourceFile:source.dacpac \
/TargetConnectionString:"Server=target;Database=shop;Integrated Security=true" \
/OutputPath:diff_report.xml
-- For data differences (row level), the tablediff utility:
tablediff -sourceserver S1 -sourcedatabase shop -sourcetable customer \
-destinationserver S2 -destinationdatabase shop -destinationtable customerFür Schemaunterschiede liefert SqlPackage /Action:DeployReport die auf das Ziel anzuwendenden Änderungen als XML-Bericht; /Action:Script erzeugt ein ausführbares Diff-Skript. 'Schema Compare' in Visual Studio / Azure Data Studio nutzt dieselbe Engine. Für Datenunterschiede auf Zeilenebene gibt es das Kommandozeilentool tablediff.
MongoDB
// The schema is implicit; extract and compare the field structure of both environments.
// Read the $jsonSchema validator definition (collection rules):
db.getCollectionInfos({ name: "customer" })[0].options.validator
// External tools for inferred schema comparison by sampling:
// mongodb-schema (npm) or the Compass 'Schema' tab
// Take samples with mongoexport and diff the field/type distribution of both environments.MongoDB ist schemalos; es gibt keine feste DDL. Verglichen wird auf zwei Wegen: die auf der Collection definierten $jsonSchema-Validierungsregeln vergleichen (über getCollectionInfos) oder mit mongodb-schema / Compass ein aus den Daten abgeleitetes Schema erzeugen und Feld- und Typverteilungen vergleichen. Für Indizes die Ausgabe von db.collection.getIndexes() per Diff vergleichen.
Redis
# Not applicable: Redis is a schemaless key-value store; there are no
# table/column definitions (DDL) to compare.
# Closest equivalent: compare the key space (namespace) structure
# redis-cli --scan --pattern 'customer:*' | sort > source_keys.txtNicht anwendbar: Redis kennt kein Schemakonzept (Tabelle/Spalte/DDL), ein klassischer Schema-Diff entfällt daher. Wird ein struktureller Vergleich benötigt, lässt sich nur das Namensmuster der Schlüssel (Namespace) mit SCAN auflisten und vergleichen.
Elasticsearch
# Fetch the index mapping from both clusters and compare
curl -s 'http://source:9200/customer/_mapping?pretty' > source_mapping.json
curl -s 'http://target:9200/customer/_mapping?pretty' > target_mapping.json
diff -u source_mapping.json target_mapping.json
# To compare settings as well:
# GET customer/_settings and GET customer/_mappingIn Elasticsearch entspricht das Index-Mapping dem Schema. Standard ist, die Ausgabe von GET <index>/_mapping (bei Bedarf auch _settings) aus beiden Clustern zu holen und mit diff zu vergleichen. Da Mapping-Felder größtenteils unveränderlich sind, kann ein gefundener Unterschied einen neuen Index + _reindex erfordern.