Using Liquibase with DB2 LUW

The purpose of this document is to guide you through the process of creating a new Liquibase project with DB2 LUW. In this tutorial, you will learn how to install the required database drivers and configure the file to establish a database connection to DB2 LUW.


Note: Place your jdbc jar driver file in the Liquibase/lib install directory or in any other known directory so you can locate it easily. Place the extension jar file in the Liquibase/lib install directory.


To create a Liquibase project with DB2 LUW, perform the following steps:

  1. Create a new project folder and name it LiquibaseDB2LUW.
  2. In your LiquibaseDB2LUW folder, create a new text file and name it

Note: For more information about the file, see Creating and configuring a file.

  1. Edit the file to add the following properties:
changeLogFile: dbchangelog.xml
url: jdbc:db2://
username: user
password: password
classpath: ../../Liquibase_Drivers/db2jcc4.jar

Note: Specifying your password, take into account that Liquibase supports only the following special characters: ~ # $ % * ( ) - _ + [ ] { } . ?. Unsupported special characters are as follows: @ & / : < > " ' ` | ^ ! = , \ <spaces>.

Use the following format for the url property:

url: jdbc:db2://<servername>:<port>/<dbname>
  • If you placed your jar file in the Liquibase/lib install directory, there is no need to specify the classpath property in the file. Otherwise, put the path to your driver as it is shown in the preceding example.
  • If you already have a Liquibase Pro key and want to apply it to your project, add the following property to your file:
liquibaseProLicenseKey: <paste license key>
  1. Create a changelog file. The changelog files contain a sequence of changesets, each of which makes small changes to the structure of your database. For more information, see changelog. Liquibase provides a changelog template located at $LIQUIBASE_HOME/examples/xml/blank.changelog.xml. Copy the blank.changelog.xml file to your LiquibaseDB2LUW folder and rename it to dbchangelog.xml. Each version of Liquibase will have an updated XML schema, so use the one that matches the version of Liquibase you have installed. The contents of the changelog will be similar to the following:
<?xml version="1.0"  encoding="UTF-8"?>

Note: The preceding changelog is XML format. The corresponding SQL changelog statement looks like the following:

--liquibase formatted sql
  1. Verify the project configuration. Run the status command to verify that the configuration is complete. Open a command prompt and navigate to the project folder LiquibaseDB2LUW. Run the command as follows:
liquibase status
  1. Verify that the DATABASECHANGELOG and DATABASECHANGELOGLOCK tables were created. From a database UI Tool, check your new Liquibase tables.

DATABASECHANGELOG tracking table. This table keeps a record of all the changesets that were deployed. When you add changesets to your changelog and run the update command, the changesets in the changelog will be compared with the DATABASECHANGELOG tracking table, and only the new changesets that were not found in the DATABASECHANGELOG will be deployed.

DATABASECHANGELOGLOCK tracking table. This table is used internally by Liquibase to manage access to the changelog table during deployment.


You have successfully configured your project and can begin creating changesets to migrate changes to your database. For more information on how to create changesets, see changeset.

See also