documentation/Reference/Database Driver Reference/PostgreSQL Database.md
{% include database-boilerplate.html %}
| Item | Details |
|---|---|
| URL format | <code>jdbc:postgresql://<i>host</i>:<i>port</i>/<i>database</i></code> |
| SSL support | Yes - add ?ssl=true |
| Ships with Flyway Command-line | Yes |
| Maven Central coordinates | org.postgresql:postgresql |
| Supported versions | 9.3-1104-jdbc4 and later |
| Default Java class | org.postgresql.Driver |
PostgreSQL-specific configuration can be found here.
PostgreSQL support is a separate dependency for Flyway and will need to be added to your Java project to access these features.
PostgreSQL is found within the flyway-database-postgresql plugin module.
<dependency>
<groupId>com.redgate.flyway</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
</dependency>
buildscript {
dependencies {
implementation "com.redgate.flyway:flyway-database-postgresql"
}
}
buildscript {
dependencies {
implementation "org.flywaydb:flyway-database-postgresql"
}
}
CREATE FUNCTION with $$ escapes, as generated by pg_dump)COPY ... FROM STDIN (as generated by pg_dump)Flyway supports the following PostgreSQL authentication methods:
The user and password can be provided in the JDBC URL, in the form
jdbc:postgresql://<host>:<port>/<database>?user=myUsername&password=myPassword&<key1>=<value1>&<key2>=<value2>...
In this case, they do not need to be passed separately in configuration and the Flyway commandline will not prompt for them.
SCRAM authentication encryption is supported transparently using the current driver (42.2.14) - note that
.jre6 and .jre7 versions of the driver for older JREs do not support it.
{% include teams.html %}
Authentication can be done with a pgpass file to retrieve the password for a connection, in which case it does not need to be supplied in configuration. If the path to a pgpass file is set in the environment variable PGPASSFILE, it will be read from here. If not, then in Windows the file will be read from the location %APPDATA%\postgresql\pgpass.conf, otherwise it is read from~/.pgpass. You can read more about pgpass files and their structure here.
By default Flyway uses a transactional lock with PostgreSQL, however this can cause issues with certain SQL statements, most notably CREATE INDEX CONCURRENTLY. In this scenario, transactional locks can be replaced with session-level locks by setting flyway.postgresql.transactional.lock=false in your configuration.
\setCREATE EXTENSION IF NOT EXISTS in order to be able to clean and (re-)migrate your schemas at willpg_largeobject (Issue 1934)passfile or hostaddr parameter when using pgpass as there is no JDBC equivalentSupport for the check command on PostgreSQL databases is currently ongoing. Basic support for the following object types has been implemented.