Use PSQL and runWith on PostgreSQL

Prerequisites

  • Use Liquibase 4.13 or later
  • Specify how Liquibase can find PSQL by adding PSQL to your PATH. Alternatively, pass its location in the liquibase.psql.conf file or from the command prompt during runtime. See liquibase.psql.path in PSQL integration arguments.

Note: Liquibase searches the PSQL location in the following order: runtime arguments, .conf file values, your PATH.

Using the PSQL integration

  1. Add the runWith attribute to the needed changesets in the changelog you use:
    • runWith:psql for an SQL changelog
    • runWith="psql" for an XML changelog
    • "runWith": "psql" for a JSON changelog
    • runWith: psql for a YAML changelog

    Note: See runWith and psql examples.

  1. Specify the PSQL integration arguments in one of the following ways:
    • Add the values in liquibase.psql.conf or the Liquibase property file.

    Note: You can use the liquibase.psql.conf file along with the Liquibase properties file. If you use Liquibase Pro and PSQL in automation, set arguments in the liquibase.psql.conf file instead of running them every time at the command prompt.

    • Set the values as environment variables
    • Run the values as Java system properties (JAVA_OPTS) along with any command at the command prompt:
  1. Run a Liquibase command:
  2. Example: liquibase update --changelog-file=psql_script.sql

    Note: If the command fails, you will receive an error message. However, if you add a property that is not used in Liquibase to the liquibase.psql.conf file, no error will occur. Liquibase only ignores it.

PSQL integration arguments

Note: Syntax for each parameter is specified in kebab-case (CLI), camelCase (properties file), and ENVAR_CASE (environment variable).

Syntax (--cli, propertiesFile, ENV_VAR) Type Description
--psql-args
liquibase.psql.args
LIQUIBASE_PSQL_ARGS
String

Defines extra arguments to pass to the psql executable. For more information, see PSQL documentation.

Note: The delimiter for arguments is a space " ". Do not use a comma "," or semicolon ";".

--psql-executor
liquibase.psql.executor
LIQUIBASE_PSQL_EXECUTOR
String

Name of a custom executor you can specify.

--psql-keep-temp
liquibase.psql.keep.temp
LIQUIBASE_PSQL_KEEP_TEMP
Boolean

Indicates whether or not to keep a temporary SQL file after the execution of PSQL. If true, the file is not deleted. Default: false.

--psql-keep-temp-name
liquibase.psql.keep.temp.name
LIQUIBASE_PSQL_KEEP_TEMP_NAME
String

Indicates the name of a temporary SQL file after the execution of PSQL.

--psql-keep-temp-path
liquibase.psql.keep.temp.path
LIQUIBASE_PSQL_KEEP_TEMP_PATH
String

Specify the path in which to store the temporary files after the execution of PSQL. If not specified, the files will be stored in the system's temp directory.

--psql-log-file
liquibase.psql.logFile
LIQUIBASE_PSQL_LOG_FILE
String

Log file for PSQL output.

--psql-path
liquibase.psql.path
LIQUIBASE_PSQL_PATH
String

Path to psql executable.

--psql-timeout
liquibase.psql.timeout
LIQUIBASE_PSQL_TIMEOUT
Integer

Indicates seconds to wait for the psql timeout. -1 disables the timeout. 0 returns an error. Default: 1800 (30 minutes).

PSQL best practices

  • Do not set the endDelimiter or splitStatements=true property on PSQL changesets. PSQL handles delimiters and statement splitting natively.
  • Prevent hanging queries by configuring the PSQL timeout. In your liquibase.psql.config file, add liquibase.psql.timeout=nn, where nn is time in seconds to wait before stopping the process.
  • Save the output of your PSQL spool files to your temp directory by adding liquibase.psql.keep.temp to the liquibase.psql.config file.

Related links