2

I'm using liquibase in project and it is working fine so far.
I added a new changeset and it works good locally, once deployed , the container's state hungs with the following statement: "liquibase: Waiting for changelog lock...".

The limit resources of the deployment are not set.
The update of table "databasechangeloglock" is not working, cause the pod keeps locking it.
How can i solve this?

maryam
  • 87
  • 3
  • 13
  • See https://stackoverflow.com/q/61387510/1704634 , you can use the liquibase-sessionlock extension which can recover from an unexpected termination – blagerweij Jan 11 '21 at 23:29
  • Does this answer your question? [Is there a configuration for removing LiquiBase DATABASE CHANGELOGLOCK automatically after a certain time or on app restart?](https://stackoverflow.com/questions/63254808/is-there-a-configuration-for-removing-liquibase-database-changeloglock-automatic) – blagerweij Jan 13 '21 at 10:10

3 Answers3

8

See other question here. If the lock happens and the process exits unexpectedly, then the lock will stay there.

According to this answer, you can remove the lock by running SQL directly:

UPDATE DATABASECHANGELOGLOCK SET LOCKED=0, LOCKGRANTED=null, LOCKEDBY=null where ID=1;

Note: Depending on your DB engine, you may need to use FALSE or 'f' instead of 0 for the LOCKED value.

Per your question, your process itself is creating a new lock and still failing every time, then most likely it is the process that is exiting/failing for a different reason (or checking for the lock in the wrong order.

Another option is to consider the Liquibase No ChangeLog Lock extension.

Note: This is probably a last resort. The extension could be an option if you were having more trouble with the changelog lock than getting any benefit (e.g. only running one instance of the app and don't really need locking). It is likely not the "best" solution, but is certainly an option depending on what you need. The README in the link says this too.

aarowman
  • 153
  • 1
  • 8
2

If you are completely sure that there is no active migration (pod) running, you can manually release the lock:

UPDATE <your table name> (f.e. DATABASECHANGELOG)

SET locked=false, lockgranted=null, lockedby=null

WHERE id=1;

Usually the lock is cleared automatically, you might want to check your isolation level for the database connection as well.

Thomas
  • 11,272
  • 2
  • 24
  • 40
0

There is an extension to handle it using session lock, this supports most of the RDMBS. The way it works is, if the database connection closes, it will release lock https://liquibase.jira.com/wiki/spaces/CONTRIB/pages/2933293057/SessionLock

Jeevan
  • 23
  • 4