Using JDBC URL in Liquibase
A JDBC URL is a database connection URL that identifies a database so that the appropriate driver recognizes it and connects to it. Liquibase requires a JDBC driver to establish a connection between Liquibase and your database.
Syntax
All JDBC URLs begin with jdbc:
. The format of other string elements depends on the JDBC driver. In most cases, the format of the database connection URL resembles the following example:
jdbc:<database>://<host>:<port>/<database_name>;<URL_attributes>
database name | Name of the database to which you want to connect. Can also be the file system path to the database. |
URL attributes | Supported attributes of the database connection URL, such as upgrade=true and create=true . Attributes are usually separated by ; , or by ? and & . |
host | Name or address of the machine on which the server is running. |
port | Port number that the server framework uses. |
Example: jdbc:postgresql://myinstance.123456789012.us-east-1.rds.amazonaws.com:5432/postgresql?user=user&password=password
Specify a JDBC URL
You can specify a JDBC URL in your command line (CLI), as an environment variable, or in your liquibase.properties
file (defaults file):
- CLI: specify the
--url
parameter in the CLI at runtime:
--url=jdbc:<database>://<host>:<port>/<database_name>;<URL_attributes>
Tip: If your database requires an &
in the URL, you may have to wrap the URL in double quotes when you specify it on the command line. For example: --url="jdbc:snowflake://otter-enthusiasts.com/?db=TEST&schema=PUBLIC&warehouse=COMPUTE_WH&role=ACCOUNTADMIN"
.
LIQUIBASE_COMMAND_URL
as an environment variable to set it once and pass connection information to Liquibase and your database:LIQUIBASE_COMMAND_URL=jdbc:<database>://<host>:<port>/<database_name>;<URL_attributes>
liquibase.command.url
to set it once and pass connection information to Liquibase and your database:url: jdbc:<database>://<host>:<port>/<database_name>;<URL_attributes>
Note: Command-line arguments override environment variables and the Liquibase properties file data. Environment variables override the properties file data. The properties file does not override any values.
For a list of JDBC examples for different databases, see Liquibase Database Tutorials.