diff
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 useful 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
Running the diff
command
Running the diff command requires two URLs:
-
referenceURL – the source for the comparison. The referenceURL attribute represents your source (reference) database which is the starting point and the basis for the database you want to compare.
-
url – the target of the comparison. The URL attribute stands for your target database which you want to compare to the source (reference) database. You typically perform actions and run the commands against this database
To compare two databases:
- The first option is to run the
diff
command and pass the parameters needed for your source (reference) database and target database. You can do this by running the following:
liquibase diff
--url="jdbc:oracle:thin:@<IP OR HOSTNAME>:<PORT>:<SERVICE NAME OR SID>"
--username=<USERNAME>
--password=<PASSWORD>
--referenceUrl="jdbc:oracle:thin:@<IP OR HOSTNAME>:<PORT>:<SERVICE NAME OR SID>"
--referenceUsername=<USERNAME>
--referencePassword=<PASSWORD>
See the snapshot command documentation for an example of using a snapshot
file as one of the databases being used in the command.
Tip: Liquibase recommends placing the 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, as follows: classpath:../<path-to-drivers>/ojdbc<version>.jar
. For more information, see Specifying Properties in a Connection Profile.
When running the diff
command against two databases, either the drivers for both must reside in the LIQUIBASE_HOME/lib
directory or the classpath
property must reference both .jar
files. Use the appropriate path separator for your operating system, as follows: for Windows, use a semicolon; for Mac or Linux, use a colon.
Example: classpath: ojdbc7.jar:postgresql-42.2.8.jar
Note: The username
and password
attributes are not required for connections and systems which use alternate means of authentication.
- Alternatively, you can configure the Liquibase properties file to include your connection information for both databases. Run the following command:
liquibase diff
Note: For information about configuring the Liquibase properties file, see Specifying Properties in a Connection Profile.

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 categories 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 Community diff
categories:
- Catalog
- Column
- Foreign Key
- Index
- Primary Key
- Schema
- Sequence
- Unique Constraints
- View
Liquibase Pro diff
categories:
- 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 diffTypes
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 diffTypes
are specified, all objects are considered.
Example: liquibase --diffTypes=tables,indexes,views diff

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.