diff

Last published July 28, 2025

The diff command in Liquibase allows you to compare two databases of the same type, or different types, to one another.

Uses

The diff command is typically used at the completion of a project to verify all expected changes are in the changelog or to detect drift between a model schema and a database's actual schema. The diff command is also helpful for the following tasks:

  • Finding missing objects between one database and another

  • Seeing that a change was made to your database

  • Finding unexpected items in your database

In Liquibase Pro 4.25.0 and later, you can use diff to seamlessly generate a Drift Report for your databases.

Syntax

Running the diff command requires two URLs:

  • reference-url– the source for the comparison. The --reference-url attribute represents your source (reference) database, which is the basis for the database you want to compare.

  • url– the target of the comparison. The --url attribute represents your target database, which you want to compare to the source (reference) database. You typically perform actions and run commands on this database.

To compare two databases:

Option 1

Run the diff command with all necessary attributes in the CLI:

liquibase diff --url="jdbc:oracle:thin:@<IP OR HOSTNAME>:<PORT>:<SERVICE NAME OR SID>" --username=<USERNAME> --password=<PASSWORD> --reference-url="jdbc:oracle:thin:@<IP OR HOSTNAME>:<PORT>:<SERVICE NAME OR SID>" --reference-username=<USERNAME> --reference-password=<PASSWORD>

Note: To run this command with an offline database snapshot, use the following pattern for the reference URL: --reference-url="offline:mysql?snapshot=SNAPSHOT_DEV.json".

Tip: For best results, specify all commands and parameters in the --kebab-case format in the CLI. If your preference is camelCase, it also works in the CLI.

Tip: Liquibase recommends that you place your database's JDBC driver JAR file in the $LIQUIBASE_HOME/lib directory. If you place the driver file in a different directory, specify the path in the properties file: classpath:../<path-to-drivers>/ojdbc<version>.jar. When you run the diff command against two databases, either the drivers for both must be in the $LIQUIBASE_HOME/lib directory or the classpath property must reference both JAR files. Use the appropriate path separator for your operating system: for Windows, use a semicolon; for Mac or Linux, use a colon.

Tip: $LIQUIBASE_HOME is an environment variable that points to the location of the directory where Liquibase is installed on your machine. You can set environment variables using your operating system's shell. The location of $LIQUIBASE_HOME will depend on where Liquibase was installed on your machine.

Example: classpath: ojdbc7.jar:postgresql-42.2.8.jar

Option 2

Configure the Liquibase properties file to include the connection information for both databases. Then, run the following command in the CLI:

liquibase diff

For information, see Create and Configure a liquibase.properties File.

By default, the result is sent to STDOUT, which provides flexibility to use the result in other tools or in a processing pipeline. You can also have your output in a file using the --output-file=<filename> attribute.

liquibase --output-file=myfile.json diff

Note: The username and password attributes are not required for connections and systems which use alternate means of authentication. Also, you can specify database credentials as part of the url attribute.

Example output

Liquibase Version: 4.9.1 Liquibase Pro 4.9.1 by Liquibase licensed to Liquibase Pro Evaluation until Tue Jun 07 18:00:00 MDT 2022 WARNING! Your license will expire in 27 days! To renew Liquibase Pro please contact sales@liquibase.com or go to https://www.liquibase.org/download Diff Results: INFO This command might not yet capture Liquibase Pro additional object types on h2 Reference Database: DBUSER @ jdbc:h2:tcp://localhost:9090/mem:integration (Default Schema: PUBLIC) Comparison Database: DBUSER @ jdbc:h2:tcp://localhost:9090/mem:dev (Default Schema: PUBLIC) Compared Schemas: PUBLIC Product Name: EQUAL Product Version: EQUAL Missing Catalog(s): NONE Unexpected Catalog(s): NONE Changed Catalog(s): INTEGRATION name changed from 'INTEGRATION' to 'DEV' Missing Check Constraint(s): NONE Unexpected Check Constraint(s): NONE Changed Check Constraint(s): NONE Missing Column(s): NONE Unexpected Column(s): PUBLIC.COMPANY.ADDRESS1 PUBLIC.PERSON.ADDRESS1 PUBLIC.COMPANY.ADDRESS2 PUBLIC.PERSON.ADDRESS2 PUBLIC.DATABASECHANGELOG.AUTHOR PUBLIC.COMPANY.CITY PUBLIC.PERSON.CITY PUBLIC.DATABASECHANGELOG.COMMENTS PUBLIC.DATABASECHANGELOG.CONTEXTS PUBLIC.PERSON.COUNTRY PUBLIC.DATABASECHANGELOG.DATEEXECUTED PUBLIC.DATABASECHANGELOG.DEPLOYMENT_ID PUBLIC.DATABASECHANGELOG.DESCRIPTION PUBLIC.DATABASECHANGELOG.EXECTYPE PUBLIC.DATABASECHANGELOG.FILENAME PUBLIC.COMPANY.ID PUBLIC.DATABASECHANGELOG.ID PUBLIC.DATABASECHANGELOGLOCK.ID PUBLIC.PERSON.ID PUBLIC.DATABASECHANGELOG.LABELS PUBLIC.DATABASECHANGELOG.LIQUIBASE PUBLIC.DATABASECHANGELOGLOCK.LOCKED PUBLIC.DATABASECHANGELOGLOCK.LOCKEDBY PUBLIC.DATABASECHANGELOGLOCK.LOCKGRANTED PUBLIC.DATABASECHANGELOG.MD5SUM PUBLIC.COMPANY.NAME PUBLIC.PERSON.NAME PUBLIC.DATABASECHANGELOG.ORDEREXECUTED PUBLIC.DATABASECHANGELOG.TAG Changed Column(s): NONE Missing Database Package(s): NONE Unexpected Database Package(s): NONE Changed Database Package(s): NONE Missing Database Package Body(s): NONE Unexpected Database Package Body(s): NONE Changed Database Package Body(s): NONE Missing Foreign Key(s): NONE Unexpected Foreign Key(s): NONE Changed Foreign Key(s): NONE Missing Function(s): NONE Unexpected Function(s): NONE Changed Function(s): NONE Missing Index(s): NONE Unexpected Index(s): PRIMARY_KEY_5 UNIQUE ON PUBLIC.PERSON(ID) PRIMARY_KEY_6 UNIQUE ON PUBLIC.COMPANY(ID) PRIMARY_KEY_D UNIQUE ON PUBLIC.DATABASECHANGELOGLOCK(ID) Changed Index(s): NONE Missing Primary Key(s): NONE Unexpected Primary Key(s): CONSTRAINT_6 on PUBLIC.COMPANY(ID) CONSTRAINT_8 on PUBLIC.PERSON(ID) PK_DATABASECHANGELOGLOCK on PUBLIC.DATABASECHANGELOGLOCK(ID) Changed Primary Key(s): NONE Missing Schema(s): NONE Unexpected Schema(s): NONE Changed Schema(s): NONE Missing Sequence(s): NONE Unexpected Sequence(s): NONE Changed Sequence(s): NONE Missing Stored Procedure(s): NONE Unexpected Stored Procedure(s): NONE Changed Stored Procedure(s): NONE Missing Synonym(s): NONE Unexpected Synonym(s): NONE Changed Synonym(s): NONE Missing Table(s): NONE Unexpected Table(s): COMPANY DATABASECHANGELOG DATABASECHANGELOGLOCK PERSON Changed Table(s): NONE Missing Trigger(s): NONE Unexpected Trigger(s): NONE Changed Trigger(s): NONE Missing Unique Constraint(s): NONE Unexpected Unique Constraint(s): NONE Changed Unique Constraint(s): NONE Missing View(s): NONE Unexpected View(s): NONE Changed View(s): NONE Liquibase command 'diff' was executed successfully.

The diff command produces a list of diff types, along with one of the following descriptions:

  • Missing: there are objects on your source database (referenceURL) that are not on your target database (URL).

  • Unexpected: there are objects on your target database (URL) that are not on your source database (referenceURL).

  • Changed: the object as it exists on the source database (referenceURL) is different than as it exists in the target database (URL).

Note: The changed description will not specify the type of change applied to your database. Run the diff-changelog command to generate a changelog that will apply the changes to the target database.

Liquibase Open Source diff types:

  • Catalog

  • Column

  • Foreign Key

  • Index

  • Primary Key

  • Schema

  • Sequence

  • Unique Constraints

  • View

Liquibase Pro diff types:

  • Check Constraint

  • Package

  • Package Body

  • Procedure

  • Function

  • Trigger

  • Synonyms

Note: Liquibase does not currently check datatype length.

Filtering diff types

Liquibase allows you to use diff-types attribute to filter the types of objects you want to compare. Multiple filters can be added to the attribute as a comma-separated list. If no diff-types are specified, all objects are considered.

Example: liquibase diff --diff-types=tables,indexes,views

Example of a filtered output

Diff Results: INFO This command might not yet capture Liquibase Pro additional object types on h2 Reference Database: DBUSER @ jdbc:h2:tcp://localhost:9090/mem:integration (Default Schema: PUBLIC) Comparison Database: DBUSER @ jdbc:h2:tcp://localhost:9090/mem:dev (Default Schema: PUBLIC) Compared Schemas: PUBLIC Product Name: EQUAL Product Version: EQUAL Missing Index(s): NONE Unexpected Index(s): PRIMARY_KEY_5 UNIQUE ON PUBLIC.PERSON(ID) PRIMARY_KEY_6 UNIQUE ON PUBLIC.COMPANY(ID) PRIMARY_KEY_D UNIQUE ON PUBLIC.DATABASECHANGELOGLOCK(ID) Changed Index(s): NONE Missing Table(s): NONE Unexpected Table(s): COMPANY DATABASECHANGELOG DATABASECHANGELOGLOCK PERSON Changed Table(s): NONE Missing View(s): NONE Unexpected View(s): NONE Changed View(s): NONE Liquibase command 'diff' was executed successfully.

Command parameters

Attribute

Definition

Requirement

--reference-url=<string>

The JDBC reference database connection URL

Required

--url=<string>

The JDBC database connection URL.

Required

--default-catalog-name=<string>

Name of the default catalog to use for the database connection

Optional

--default-schema-name=<string>

Name of the default schema to use for the database connection. If defaultSchemaName is set, then objects do not have to be fully qualified. This means you can refer to just mytable instead of myschema.mytable.

Note: In the properties file and JAVA_OPTS only: in 4.18.0 and earlier, specify this parameter using the syntax defaultSchemaName. In 4.19.0 and later, use the syntax liquibase.command.defaultSchemaName.

Note: In Liquibase 4.12.0 and later, you can use mixed-case schema names if you set --preserve-schema-case to true. However, in Liquibase 4.12.0–4.22.0, the Liquibase validator still throws a DatabaseException error if you specify a mixed-case value of defaultSchemaName. In 4.23.0 and later, the Liquibase validator accepts any casing.

Optional

--diff-types=<string>

Specifies the types of objects to compare. Specify multiple values as a comma-separated list (without spaces). Valid values are: catalogs, checkconstraints, columns, data, databasepackage, databasepackagebody, foreignkeys, functions, indexes, primarykeys, sequences, storedprocedures, tables, triggers, uniqueconstraints, views.

If null, default types are columns, foreignkeys, indexes, primarykeys, tables, uniqueconstraints, views.

Note: The diff types checkconstraints, databasepackage, databasepackagebody, functions, storedprocedures, and triggers require a valid Liquibase Pro license key to use.

Optional

--drift-severity=<string>

Specifies the severity level of all error types in the drift report (changed, missing, or unexpected content). Valid values are INFO (0), MINOR (1), MAJOR (2), CRITICAL (3), and BLOCKER (4), from least severe to most severe. If both --drift-severity and one of the individual error type arguments are set, the individual error type arguments take priority. Default: INFO.

Optional

--drift-severity-changed=<string>

Specifies the severity level of changed content in the drift report. Valid values are INFO (0), MINOR (1), MAJOR (2), CRITICAL (3), and BLOCKER (4), from least severe to most severe. Overrides the value of --drift-severity for changed content only. Default: INFO.

Optional

--drift-severity-missing=<string>

Specifies the severity level of missing content in the drift report. Valid values are INFO (0), MINOR (1), MAJOR (2), CRITICAL (3), and BLOCKER (4), from least severe to most severe. Overrides the value of --drift-severity for missing content only. Default: INFO.

Optional

--drift-severity-unexpected=<string>

Specifies the severity level of unexpected content in the drift report. Valid values are INFO (0), MINOR (1), MAJOR (2), CRITICAL (3), and BLOCKER (4), from least severe to most severe. Overrides the value of --drift-severity for unexpected content only. Default: INFO.

Optional

--driver=<string>

The JDBC driver class.

Optional

--driver-properties-file=<string>

The JDBC driver properties file.

Optional

--exclude-objects=<string>

Objects to exclude from diff.

Optional

--format=<string>

Option to create JSON output. See diff JSON.

Optional

--include-objects=<string>

Objects to include in diff.

Optional

--report-open=<true|false>

If true, automatically opens the report in your default browser. Default: false.

Note: Prior to Liquibase 4.29.0, this parameter was called --open-report instead of --report-open.

Optional

--output-schemas=<string>

Lets you replace the schemas in the output changelog. This is a CSV list. The parameter size must match --schemas. If you have three items names in --schemas, you must also have three items in --output-schemas.

Example: liquibase generate-changelog --schemas=a,b,c --output-schemas=d,e,f

Optional

--password=<string>

Password to connect to the target database.

Tip: It is best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

--reference-default-catalog-name=<string>

The reference default catalog name to use for the database connection

Optional

--reference-default-schema-name=<string>

The reference default schema name to use for the database connection

Optional

--reference-driver=<string>

The JDBC driver class for the reference database

Optional

--reference-driver-properties-file=<string>

The JDBC driver properties file for the reference database

Optional

--reference-liquibase-catalog-name=<string>

Reference database catalog to use for Liquibase objects. Liquibase 4.24.0+.

Optional

--reference-liquibase-schema-name=<string>

Reference database schema to use for Liquibase objects. Liquibase 4.24.0+.

Optional

--reference-password=<string>

The reference database password.

Tip: It is best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

--reference-schemas=<string>

Schemas names on reference database to use in diff. This is a CSV list.

Optional

--reference-username=<string>

The reference database username.

Tip: It is best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

--report-enabled=<true|false>

Enables a report at the command level. Overrides the global parameter --reports-enabled. Default: true.

Optional

--report-name=<string>

Specifies the name of the report file at the command level. Overrides the global parameter --reports-name. By default, Liquibase generates a new report file labeled with a timestamp (user's local time). If you set a custom name, Liquibase overwrites the existing file every time you generate a new report. Default: report-<DD-Mon-YYYY-HHmmss>.html.

Optional

--report-path=<string>

Specifies the file path to the report file at the command level. Overrides the global parameter --reports-path. Default: ./.

Optional

--report-suppress-exception=<true|false>

Liquibase 4.31.0+. Specifies whether to hide exceptions (which may contain SQL) from the operation report at the command level. Overrides the global parameter --reports-suppress-exception. Default: false. However:

If --report-suppress-exception is not set and --report-suppress-sql=true, Liquibase suppresses all SQL, including exception SQL.

If --report-suppress-exception=false and --report-suppress-sql=true, Liquibase suppresses most SQL but shows exception SQL.

Optional

--report-suppress-sql=<true|false>

Liquibase 4.31.0+. Specifies whether to hide changeset SQL in operation reports at the command level. Overridden by the global parameter --reports-suppress-sql. Default: false.

Optional

--schemas=<string>

Schemas to include in diff.

Optional

--username=<string>

Username to connect to the target database.

Tip: It is best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

Drift report

In Liquibase 4.25.0 and later, you can automatically generate a Drift Report using the diff command. The drift report requires a Liquibase Pro license key.

Drift reports are available for MongoDB with the MongoDB Pro extension starting in version 4.32.