PostgreSQL database support module for Flyway migration tool with specialized implementations for PostgreSQL and CockroachDB databases
—
PostgreSQL-specific configuration extension providing additional settings for transactional behavior and environment variable mapping.
Configuration extension that adds PostgreSQL-specific settings to Flyway's configuration system.
/**
* PostgreSQL configuration extension
*/
public class PostgreSQLConfigurationExtension implements ConfigurationExtension {
/**
* Gets the transactional lock setting
* @return true if transactional locking is enabled (default), false otherwise
*/
public boolean isTransactionalLock();
/**
* Sets the transactional lock setting
* @param transactionalLock Whether to use transactional locking
*/
public void setTransactionalLock(boolean transactionalLock);
/**
* Maps environment variables to configuration parameters
* @param environmentVariable Environment variable name
* @return Configuration parameter name, or null if not mapped
*/
public String getConfigurationParameterFromEnvironmentVariable(String environmentVariable);
/**
* Gets the configuration namespace for PostgreSQL settings
* @return "postgresql"
*/
public String getNamespace();
}Usage Examples:
import org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension;
import org.flywaydb.core.api.configuration.ClassicConfiguration;
// Configuration is typically managed through Flyway's configuration system
Configuration config = Flyway.configure()
.configuration(Map.of("flyway.postgresql.transactional.lock", "false"))
.load()
.getConfiguration();
// Access PostgreSQL-specific configuration
PostgreSQLConfigurationExtension pgConfig =
config.getPluginRegister().getPlugin(PostgreSQLConfigurationExtension.class);
boolean usesTransactionalLock = pgConfig.isTransactionalLock();
System.out.println("Transactional lock enabled: " + usesTransactionalLock);Data model for transactional configuration settings.
/**
* Configuration model for transactional settings
*/
public class TransactionalModel {
private Boolean lock;
/**
* Gets the lock setting
* @return Lock setting (null for default)
*/
public Boolean getLock();
/**
* Sets the lock setting
* @param lock Lock setting
*/
public void setLock(Boolean lock);
}Controls whether PostgreSQL uses transactional advisory locks during migrations.
Property: flyway.postgresql.transactional.lock
Environment Variable: FLYWAY_POSTGRESQL_TRANSACTIONAL_LOCK
Default: true
Type: boolean
// Enable transactional locking (default)
Flyway flyway = Flyway.configure()
.configuration(Map.of("flyway.postgresql.transactional.lock", "true"))
.dataSource("jdbc:postgresql://localhost:5432/mydb", "user", "password")
.load();
// Disable transactional locking
Flyway flyway = Flyway.configure()
.configuration(Map.of("flyway.postgresql.transactional.lock", "false"))
.dataSource("jdbc:postgresql://localhost:5432/mydb", "user", "password")
.load();Impact on Connection Usage:
// When transactional.lock = true (default)
boolean useSingleConnection = database.useSingleConnection(); // returns false
// Uses separate connections for locking and migration execution
// When transactional.lock = false
boolean useSingleConnection = database.useSingleConnection(); // returns true
// Uses single connection for all operationsThe configuration extension maps environment variables to Flyway properties:
| Environment Variable | Configuration Property |
|---|---|
FLYWAY_POSTGRESQL_TRANSACTIONAL_LOCK | flyway.postgresql.transactional.lock |
Usage Examples:
# Set via environment variable
export FLYWAY_POSTGRESQL_TRANSACTIONAL_LOCK=false
# Flyway will automatically map this to flyway.postgresql.transactional.lock
flyway migrate// Programmatic environment variable handling
PostgreSQLConfigurationExtension extension = new PostgreSQLConfigurationExtension();
String configParam = extension.getConfigurationParameterFromEnvironmentVariable(
"FLYWAY_POSTGRESQL_TRANSACTIONAL_LOCK");
// Returns: "flyway.postgresql.transactional.lock"
String unmappedParam = extension.getConfigurationParameterFromEnvironmentVariable(
"SOME_OTHER_VAR");
// Returns: nullThe configuration extension is automatically registered via the service provider interface:
META-INF/services/org.flywaydb.core.extensibility.Plugin
└── org.flywaydb.database.postgresql.PostgreSQLConfigurationExtensionimport org.flywaydb.core.api.configuration.Configuration;
// Get PostgreSQL configuration from Flyway
Configuration flywayConfig = flyway.getConfiguration();
PostgreSQLConfigurationExtension pgConfig =
flywayConfig.getPluginRegister().getPlugin(PostgreSQLConfigurationExtension.class);
// Check current settings
if (pgConfig != null) {
boolean transactionalLock = pgConfig.isTransactionalLock();
System.out.println("PostgreSQL transactional lock: " + transactionalLock);
}// Using Flyway's configuration builder
Flyway flyway = Flyway.configure()
// Standard Flyway configuration
.dataSource("jdbc:postgresql://localhost:5432/mydb", "user", "password")
.locations("classpath:db/migration")
// PostgreSQL-specific configuration
.configuration(Map.of(
"flyway.postgresql.transactional.lock", "false"
))
.load();
// Migrate with custom PostgreSQL settings
flyway.migrate();import org.flywaydb.database.postgresql.PostgreSQLConfigurationExtension;
import org.flywaydb.database.postgresql.TransactionalModel;
// Create configuration extension
PostgreSQLConfigurationExtension pgConfig = new PostgreSQLConfigurationExtension();
// Configure transactional settings
pgConfig.setTransactionalLock(false);
// Check configuration state
boolean isTransactional = pgConfig.isTransactionalLock(); // returns false
// Access internal model
TransactionalModel model = pgConfig.getTransactional();
if (model != null) {
Boolean lockSetting = model.getLock(); // returns false
}// Default configuration behavior
PostgreSQLConfigurationExtension defaultConfig = new PostgreSQLConfigurationExtension();
// Default transactional setting
boolean defaultLock = defaultConfig.isTransactionalLock(); // returns true
// Namespace identification
String namespace = defaultConfig.getNamespace(); // returns "postgresql"// Validate configuration settings
try {
PostgreSQLConfigurationExtension pgConfig =
config.getPluginRegister().getPlugin(PostgreSQLConfigurationExtension.class);
if (pgConfig == null) {
System.err.println("PostgreSQL configuration extension not found");
} else {
boolean transactionalLock = pgConfig.isTransactionalLock();
System.out.println("Transactional lock configured: " + transactionalLock);
}
} catch (Exception e) {
System.err.println("Configuration validation failed: " + e.getMessage());
}The configuration settings affect how the PostgreSQL database implementation behaves:
PostgreSQLDatabase database = (PostgreSQLDatabase) flyway.getConfiguration()
.getDataSource()
.getConnection();
// Configuration affects connection usage strategy
boolean singleConnection = database.useSingleConnection();
if (singleConnection) {
System.out.println("Using single connection mode (transactional.lock = false)");
} else {
System.out.println("Using multiple connection mode (transactional.lock = true)");
}PostgreSQLConnection connection = (PostgreSQLConnection) database.getConnection();
// Locking behavior depends on configuration
Table migrationTable = database.getTable("flyway_schema_history");
connection.lock(migrationTable, () -> {
// Lock implementation varies based on transactional.lock setting
return "Migration operation completed";
});Install with Tessl CLI
npx tessl i tessl/maven-org-flywaydb--flyway-database-postgresql