Provides session-level (vs. transaction-level)
LockService
implementations. Session-level locks get automatically released if the database
connection drops, and overcome the shortcoming of the
StandardLockService
:
If Liquibase does not exit cleanly, the lock row may be left as locked. You can clear out the current lock by running
liquibase releaseLocks
which runsUPDATE DATABASECHANGELOGLOCK SET LOCKED=0
.
Running liquibase releaseLocks
in a micro-service production environment
may not be really feasible.
- MySQL
- MariaDB
- PostgreSQL
- Oracle
Support for other databases may be conveniently added by extending SessionLockService
.
The MySQL and MariaDB implementation rely on user locks: get_lock
and is_used_lock
are builtin functions for MySQL and MariaDB. The lock is automatically released when the connection is dropped unexpectedly.
The Postgres implementation used pg_try_advisory_lock
and pg_try_advisory_unlock
The Oracle implementation relies on DBMS_LOCK
.
The user that executes liquibase must have EXECUTE
privilege on DBMS_LOCK
.
grant execute on SYS.DBMS_LOCK to <user>;
To read lock information, the user needs permissions to read from GV$LOCK
and GV$SESSION
.
grant select on SYS.GV_$LOCK to <user>;
grant select on SYS.GV_$SESSION to <user>;
The MSSQL implementation used application resources locks with sp_getapplock
and sp_releaseapplock
To use the new lockservice, simply add a dependency to the library. In Liquibase v4.x, because the priority is higher than the StandardLockService, it will automatically be used (provided the database is supported).
In Liquibase v3.7.x and above, especially when used standalone or integrated with Dropwizard framework, com.github.blagerweij.sessionlock
string needs to be added to Liquibase classpath scanner's whitelist of packages to scan, by either system property liquibase.scan.packages
or Liquibase-Package
entry in MANIFEST.mf, as described here . Please note that unit tests are performed for a few versions of Liquibase, starting from v3.5, but other versions might work as well.
<dependency>
<groupId>com.github.blagerweij</groupId>
<artifactId>liquibase-sessionlock</artifactId>
<version>1.6.9</version>
</dependency>
implementation 'com.github.blagerweij:liquibase-sessionlock:1.6.9'
with Kotlin DSL
implementation("com.github.blagerweij:liquibase-sessionlock:1.6.9")
This module is using the Apache Software License, version 2.0. See https://www.apache.org/licenses/LICENSE-2.0.txt