diff-changelog
Last published July 28, 2025
The diff-changelog command displays the differences between two databases you are comparing. It also generates a changelog file containing deployable changesets to resolve most of these differences.
Uses
The diff-changelog
command is typically used when you want to create a deployable changelog to synchronize multiple databases. The diff-changelog
command also provides more information about database drift:
Missing objects in your database
Changes made to your database
Unexpected items in your database
In Liquibase Pro 4.25.1 and later, you can use diff-changelog
to seamlessly generate a Drift Report for your databases.
In order to track changes to a database, you can generate a snapshot of the database, make the changes, and create a changelog, which you can use to compare the snapshot with your database.
Running the diff-changelog
command
Running the diff-changelog
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 create a diff changelog:
Option 1
Run the diff-changelog
command with all necessary attributes in the CLI:
liquibase diff-changelog --changelog-file=example-changelog.xml
--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-changelog --changelog-file=example-changelog.xml
Note: If you specify a changelog file name that already exists, Liquibase will append your changes to the existing file.
Output
The diff-changelog
command produces a list of all objects and creates a changelog with a list of changesets.
Liquibase Open Source diff-changelog
categories:
Catalog
Column
Foreign Key
Index
Primary Key
Schema
Sequence
Unique Constraints
View
Console output example
Liquibase Version: 4.9.1
BEST PRACTICE: The changelog generated by diffChangeLog/generateChangeLog should be inspected for correctness and completeness before being deployed. Some database objects and their dependencies cannot be represented automatically, and they may need to be manually updated before being deployed.
Liquibase command 'diff-changelog' was executed successfully.
Filtering diff-changelog
types
You can filter what objects diff-changelog
generates with the --diff-types
attribute:
--diff-types=<catalogs,tables,functions,views,columns,indexes,foreignkeys,primarykeys,uniqueconstraints,storedprocedures,triggers,sequences,databasepackage,databasepackagebody>
You can also filter specific objects by name with the --include-objects
and --exclude-objects
attributes. For example:
--include-objects=table:tableName,column:columnName,view:viewName,index:indexName
--exclude-objects=table:tableName,column:columnName,view:viewName,index:indexName
This way, you can prevent undesired objects from ending in the resulting changelog.
Additional Functionality with Liquibase Pro
While Liquibase Open Source stores all changesets in a changelog, Liquibase Pro creates a directory called Objects
and places the directory at the same level as your changelog. The Objects
directory contains a subdirectory for each of the following Stored Logic types:
checkconstraint
package
packagebody
procedure
function
trigger
synonyms
Note: Not all database platforms support all stored logic types that are listed.
The diff-changelog
command structures stored logic files into timestamped directories every time you run the command.
Note: Liquibase does not currently check data type length.
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.
Liquibase Pro diff-changelog example file
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
http://www.liquibase.org/xml/ns/pro
http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">
<changeSet author="Administrator (generated)" id="1571345362466-8">
<pro:createTrigger disabled="false" path="objects/trigger/TS_T_EXEMPLAR_SEQEXEMPLAR.sql" relativeToChangelogFile="true" tableName="T_EXEMPLAR" triggerName="TS_T_EXEMPLAR_SEQEXEMPLAR"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-9">
<pro:createTrigger disabled="false" path="objects/trigger/ORDERS_BEFORE_INSERT4.sql" relativeToChangelogFile="true" tableName="orders" triggerName="ORDERS_BEFORE_INSERT4"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-10">
<pro:createTrigger disabled="false" path="objects/trigger/ORDERS_BEFORE_INSERT2.sql" relativeToChangelogFile="true" tableName="orders" triggerName="ORDERS_BEFORE_INSERT2"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-11">
<pro:createTrigger disabled="false" path="objects/trigger/ORDERS_BEFORE_INSERT.sql" relativeToChangelogFile="true" tableName="orders" triggerName="ORDERS_BEFORE_INSERT"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-12">
<createView fullDefinition="true" path="objects/view/OREDERS_VIEW.sql" relativeToChangelogFile="true" viewName="OREDERS_VIEW"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-13">
<pro:createTrigger disabled="false" path="objects/trigger/ORDERS_BEFORE_INSERT3.sql" relativeToChangelogFile="true" tableName="orders" triggerName="ORDERS_BEFORE_INSERT3"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-14">
<createProcedure path="objects/storedprocedure/P_CUSTOMER_HAS_NUM_FILM.sql" procedureName="P_CUSTOMER_HAS_NUM_FILM" relativeToChangelogFile="true"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-15">
<createView fullDefinition="true" path="objects/view/V_CUSTOMER_HAS_FILM.sql" relativeToChangelogFile="true" viewName="V_CUSTOMER_HAS_FILM"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-16">
<createProcedure path="objects/storedprocedure/SP_CUSTOMER_SOCIAL_ACCTS.sql" procedureName="SP_CUSTOMER_SOCIAL_ACCTS" relativeToChangelogFile="true"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-17">
<pro:createTrigger disabled="false" path="objects/trigger/TRI_BORROWING.sql" relativeToChangelogFile="true" tableName="T_BORROWING" triggerName="TRI_BORROWING"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-18">
<pro:createTrigger disabled="false" path="objects/trigger/TRU_BORROWING.sql" relativeToChangelogFile="true" tableName="T_BORROWING" triggerName="TRU_BORROWING"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-19">
<pro:createTrigger disabled="false" path="objects/trigger/TSU_T_EXEMPLAR_SEQEXEMPLAR.sql" relativeToChangelogFile="true" tableName="T_EXEMPLAR" triggerName="TSU_T_EXEMPLAR_SEQEXEMPLAR"/>
</changeSet>
<changeSet author="Administrator (generated)" id="1571345362466-20">
<pro:createFunction functionName="F_CUSTOMER_HAS_NUM_FILM" path="objects/function/F_CUSTOMER_HAS_NUM_FILM.sql" relativeToChangelogFile="true"/>
</changeSet>
</databaseChangeLog>
Command parameters
Attribute | Definition | Requirement |
| The root changelog | Required |
| The JDBC reference database connection URL | Required |
| Specifies a directory to send the loadData output to a CSV file which is generated by running the | Optional |
| The JDBC database connection URL. | Required |
| Specifies the author for changesets in the generated changelog. | Optional |
| Specifies the context filter to generate and apply to all changesets in your changelog. Useful to set many contexts quickly. Similar to the set-contexts command. Available in Liquibase 4.24.0 and later. Contexts are tags you can add to changesets to control which changesets will be executed in any particular migration run. After generating changesets with contexts, to deploy specific changes according to these contexts, you must run a command that specifies a context filter. For example, | Optional |
| Name of the default catalog to use for the database connection | Optional |
| Name of the default schema to use for the database connection. If Note: In the properties file and Note: In Liquibase 4.12.0 and later, you can use mixed-case schema names if you set | Optional |
| Specifies the types of objects to compare. Specify multiple values as a comma-separated list (without spaces). Valid values are: If null, default types are Note: The diff types | Optional |
| Specifies the severity level of all error types in the drift report (changed, missing, or unexpected content). Valid values are | Optional |
| Specifies the severity level of changed content in the drift report. Valid values are | Optional |
| Specifies the severity level of missing content in the drift report. Valid values are | Optional |
| Specifies the severity level of unexpected content in the drift report. Valid values are | Optional |
| The JDBC driver class | Optional |
| The JDBC driver properties file | Optional |
| Objects to exclude from diff | Optional |
| If | Optional |
| Objects to include in diff | Optional |
| If | Optional |
| Include the tablespace attribute in the changelog. Default: | Optional |
| Specifies the label filter to generate and apply to all changesets in your changelog. Useful to set many labels quickly. Similar to the set-labels command. Available in Liquibase 4.24.0 and later. Labels are tags you can add to changesets to control which changeset will be executed in any migration run. After generating changesets with labels, to deploy specific changes according to these labels, you must run a command that specifies a label filter. For example, | Optional |
| If Note: Prior to Liquibase 4.29.0, this parameter was called | Optional |
| Lets you replace the schemas in the output changelog. This is a CSV list. The parameter size must match Example: | Optional |
| Password to connect to the target database. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. | Optional |
| If
If
| Optional |
| The reference default catalog name to use for the database connection | Optional |
| The reference default schema name to use for the database connection | Optional |
| The JDBC driver class for the reference database | Optional |
| The JDBC driver properties file for the reference database | Optional |
| Reference database catalog to use for Liquibase objects. Liquibase 4.24.0+. | Optional |
| Reference database schema to use for Liquibase objects. Liquibase 4.24.0+. | Optional |
| The reference database password. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. | Optional |
| Schemas names on reference database to use in diff. This is a CSV list. | Optional |
| The reference database username. Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro. | Optional |
| Specify Change Types you want to target. Liquibase sets | Optional |
| Enables a report at the command level. Overrides the global parameter | Optional |
| Specifies the name of the report file at the command level. Overrides the global parameter | Optional |
| Specifies the file path to the report file at the command level. Overrides the global parameter | Optional |
| 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 |
| Liquibase 4.31.0+. Specifies whether to hide changeset SQL in operation reports at the command level. Overridden by the global parameter | Optional |
| Specify Change Types you want to target. Liquibase sets | Optional |
| Schemas to include in diff | Optional |
| Liquibase 4.27.0+. Specifies how Liquibase sorts a list of objects in your database to generate a changelog. When Note: If you set this parameter to | Optional |
| 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.1 and later, you can automatically generate a Drift Report using the diff-changelog
command. The drift report requires a Liquibase Pro license key.