diff-changelog
The diff-changelog
command allows you to receive information on differences between two databases you are comparing and creates a changelog file containing deployable changesets.
The diff-changelog
command points out the differences in general and generates changes to resolve most of them.
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:
- Missing objects in your database
- Changes made to your database
- Unexpected items in your database
Running the diff-changelog
command
Running the diff-changelog
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 and against this database.
To create a diff changelog:
- The first option is to run the
diff-changelog
command and pass the attributes needed for your source (reference) database and target database.
Tip: All Commands and Parameters use the --kabob-case format in the CLI environment.
As an example, you can run the following:
liquibase
--changelog-file=dbchangelog.xml
--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>
diff-changelog
Tip: If you want to create an SQL changelog file, add your database type name when specifying the changelog file: liquibase --changelog-file=mychangelog.oracle.sql diff-changelog
. Replace .oracle.sql
with your database type. When in doubt about your database type name, check Supported Databases.
See the snapshot command topic 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
- Alternatively, configure the Liquibase properties file to include the connection information for both databases. Run the following command:
liquibase --changelog-file=file_name.xml diff-changelog
Note: Replace file_name.xml
with your filename and extension format. If you specify a file name that already exists, Liquibase will append your changes to the existing file.
For information about configuring the Liquibase properties file, see Specifying Properties in a Connection Profile.
Output
The diff-changelog
command produces a list of all Objects and creates a changelog with a list of changesets.
Liquibase Community diff-changelog
categories:
- Catalog
- Column
- Foreign Key
- Index
- Primary Key
- Schema
- Sequence
- Procedure
- Unique Constraints
- View

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 diffTypes
attribute:
--diffTypes=<catalogs,tables,functions,views,columns,indexes,foreignkeys,primarykeys,uniqueconstraints,storedprocedures,triggers,sequences,databasepackage,databasepackagebody>
You can also filter specific objects by name with the includeObjects
and excludeObjects
attributes. For example:
--includeObjects=table:tableName,column:columnName,view:viewName,index:indexName
--excludeObjects=table:tableName,column:columnName,view:viewName,index:indexName
This way, you can prevent any undesired objects from ending up in the resulting changelog.
Additional Functionality with Liquibase Pro
While Liquibase Community 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
- 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.

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>
Note: Liquibase does not currently check data type length.