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 Liquibase properties file to establish a database connection to DB2 LUW.

Prerequisites

Before using Liquibase with your database, ensure you have:

Note: Liquibase comes with a pre-installed driver for DB2 in the liquibase/lib directory. For more information, see Adding and Updating Liquibase Drivers.

Tutorial

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

  1. Add the following properties to the Liquibase properties file:
changelog-file: dbchangelog.xml
url: jdbc:db2://192.168.1.15:5432/MYDATABASE
username: user
password: password
driver: com.ibm.db2.jcc.DB2Driver
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 the jar file in the liquibase/lib install directory, you do not need to specify the classpath property in the Liquibase properties file. Otherwise, set the path to the driver as 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 the Liquibase properties file:
liquibaseProLicenseKey: <paste license key>
  1. Create a text file called changelog (.xml, .sql, .json, or .yaml) in your project directory and add a changeset.

  1. Navigate to your project folder in the CLI and run the Liquibase status command to see whether the connection is successful. You can pass arguments in the CLI or keep them in the Liquibase properties file.
  2. liquibase --username=test --password=test --changelog-file=<changelog.xml> status
  3. Run your first update with the update command, which makes changes to your database. You can also run the update-sql command to inspect the SQL before running the update command.
  4. liquibase --changelog-file=<changelog.xml> update-sql
    liquibase --changelog-file=<changelog.xml> update

From a database UI tool, ensure that your database contains the table you added along with the DATABASECHANGELOG table and DATABASECHANGELOGLOCK table.

See also