Is there a liquibase lock timeout?

10k views Asked by At

You can see in the issue here: (liquibase-lock-reasons) at situation where the client Liquibase locks when a Liquibase operation has been interrupted, leaving liquibase in a locked state.

I'm wondering if there is a way to configure Liquibase to automatically detect this situation from the date and time in the LOCKGRANTED column. I think if you've held onto the lock for an hour - you should call that an expired lock.

My question is: Is there a liquibase lock timeout?

3

There are 3 answers

0
Nathan Voxland On BEST ANSWER

There is no lock timeout. Liquibase has no idea of how long to expect changeSets to take, and if some are doing DML on large tables they can take hours to run successfully.

There is a releaseLocks command you can use to clear the locks manually, or you could subclass liquibase.lockservice.StandardLockService to add additional logic to override the lock after after a set period of time.

If you have only one machine that would be updating the database, you can consider https://github.com/liquibase/liquibase-nochangeloglock as well, which completely disables the lock support.

I could see it as being a useful feature to have configurable, so I did add https://liquibase.jira.com/browse/CORE-2375 to track the feature.

0
hsiliev On

There are extensions out there that can either add timeout or remove the lock. Unfortunately all of them can be dangerous because they do not check if the original process that obtained the lock is still alive (and working).

The official support for lock removal with Postgres is still not merged: https://github.com/liquibase/liquibase/pull/1417

There are several extensions out there that can also help:

If that does not suffice you can always create Liquibase extension to suit your needs. I did that to support my single instance deployment with https://github.com/hsiliev/liquibase-lock-timeout

1
Alessio Santacroce On

Actually,looking at the code of StandardLockService, it is configurable using the system property "liquibase.changeLogLockWaitTimeInMinutes"...

public class StandardLockService implements LockService {
    ...
    private long changeLogLockWaitTime = 300000L;
    ....
    public StandardLockService() {
        try {
            this.changeLogLockWaitTime = 60000L * Long.parseLong(System.getProperty("liquibase.changeLogLockWaitTimeInMinutes"));
            LogFactory.getLogger().info("lockWaitTime change to: " + this.changeLogLockWaitTime);
        } catch (NumberFormatException var2) {
            ;
        }
    }