두 스키마/환경 비교(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에는 단일 명령으로 스키마를 비교하는 기본 기능이 없다. 일반적인 방법은 두 환경에서 DBMS_METADATA.GET_DDL로(STORAGE/세그먼트 속성을 끈 상태로) 결정적인 DDL을 생성한 뒤 텍스트 diff를 하는 것이다. 시각적/자동 비교에는 SQL Developer의 Database Diff 마법사나 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 diffChangeLog가장 간단한 방법은 두 환경에서 pg_dump --schema-only 출력을 받아 diff로 비교하는 것이다. apgdiff와 migra는 차이를 바로 실행 가능한 ALTER 문으로 변환하는 도구다. 결정적인 출력을 위해 --no-owner --no-privileges를 추가한다.
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)MySQL Utilities의 mysqldbcompare 도구는 두 서버 간 객체/스키마 차이를 보고한다(difftype=sql이면 적용 가능한 문으로 출력). 도구 없이 하는 방법은 두 환경에서 mysqldump --no-data(스키마만) 또는 SHOW CREATE TABLE 출력을 받아 diff로 비교하는 것이다. mysqldbcompare는 현재 deprecated이며, MariaDB/8.x에는 Liquibase나 Skeema가 권장된다.
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 customer스키마 차이는 SqlPackage /Action:DeployReport가 대상에 적용될 변경 사항을 XML 보고서로 반환하고, /Action:Script는 실행 가능한 diff 스크립트를 생성한다. Visual Studio / Azure Data Studio의 'Schema Compare'도 같은 엔진을 사용한다. 행 수준 데이터 차이에는 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는 스키마리스이므로 고정 DDL이 없다. 비교는 두 가지 방법으로 한다. 컬렉션에 정의된 $jsonSchema 검증 규칙을 비교하거나(getCollectionInfos 사용), mongodb-schema / Compass로 데이터에서 추론한 스키마를 생성해 필드와 타입 분포를 비교한다. 인덱스는 db.collection.getIndexes() 출력을 diff한다.
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.txt해당 없음: Redis에는 스키마 개념(테이블/컬럼/DDL)이 없으므로 고전적인 schema diff가 적용되지 않는다. 구조 비교가 필요하면 SCAN으로 키 명명 패턴(namespace)만 나열해 비교할 수 있다.
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/_mappingElasticsearch에서 스키마에 해당하는 것은 인덱스 mapping이다. 표준 방법은 두 클러스터에서 GET <index>/_mapping 출력(필요하면 _settings도)을 받아 diff로 비교하는 것이다. mapping 필드는 대부분 변경할 수 없으므로 차이가 발견되면 새 인덱스 + _reindex가 필요할 수 있다.