diff command

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


The diff command is typically used at the completion of a project, because it allows you to verify all expected changes are in the changelog. The diff command is also useful for the following tasks:

  • Finding missing objects in your database
  • Seeing that a change was made to your database
  • Finding unexpected items in your database

Running the diff command

To compare two databases:

  • The first option is to run the diff command and pass the parameters needed for your source database and target database. You can do this by running the following:
--url="jdbc:oracle:thin:@<IP OR HOSTNAME>:<PORT>:<SERVICE NAME OR SID>"
--referenceUrl="jdbc:oracle:thin:@<IP OR HOSTNAME>:<PORT>:<SERVICE NAME OR SID>"

See the snapshot command documentation for an example of using a snapshot file as one of the databases being used in the command.

Note: When running diff against two different databases, the class path property should reference both .jar files. Use the path separator that is correct for your operating system (a semicolon on Windows, a colon on Mac or Linux).

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

  • Alternatively, configure the liquibase.properties file to include your driver class path, URL, and user authentication information for both databases. Run the following command:
liquibase --outputFile=mydiff.txt diff

Note: For information on how to configure your liquibase.properties file, view the Creating & Configuring your liquibase.properties file topic.

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

  • Missing: The object is not on your comparison database (source database).
  • Unexpected: There are objects on your comparison database (source database) that are not on your reference database (target database).
  • Changed: The object as it exists on the source database is different than as it exists in the target database.

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

Liquibase Community diff categories:

  • Catalog
  • Column
  • Foreign Key
  • Index
  • Primary Key
  • Schema
  • Sequence
  • Procedure
  • Unique Constraints
  • View

Liquibase Pro diff categories:

  • Check Constraint
  • Package
  • Package Body
  • Function
  • Trigger
  • Synonyms

Note: Liquibase does not currently check datatype length.

Filtering diff types

Liquibase allows you to use diffType attributes 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 diffTypes are specified, all objects are considered.

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