Cyberithub

How to manually remove Liquibase lock from Database

Advertisements

In this article, we will see how to manually remove liquibase lock from database using few simple steps. liquibase is a free and open source database version control tool which keeps track of all database modifications and allow us to undo a change just like git tool in case we would like to rollback from some problematic change. It is used widely in large and complex production database environment where the chances of ruining a database due to some mistake is higher. liquibase makes database administrators and developers life quite easier.

While there are multiple benefits of using liquibase tool in your databases, there are also few minor downside which sometimes you have to handle manually. One of the such downside is the liquibase lock which sometimes does not get removed automatically after completion of a process and tends to cause problem in connecting your application to databases. If you encounter such situation then here I am going to tell you how to deal with this situation.

 

How does Liquibase work

Liquibase uses a table called DATABASECHANGELOGLOCK which contains information about the process currently running to perform the database modifications. When a liquibase process starts, it sets LOCKED, LOCKGRANTED and LOCKEDBY as below:-

  • LOCKED = <1> or <TRUE>
  • LOCKGRANTED = <timestamp>
  • LOCKEDBY = <hostname/ip>

Once the liquibase process gets completed, it will be automatically set as below which means liquibase lock is released:-

  • LOCKED = <0> or <FALSE>
  • LOCKGRANTED = NULL
  • LOCKEDBY = NULL

 

How to manually remove Liquibase lock from Database

How to manually remove Liquibase lock from Database

Also Read: Solved "pg_restore: error: input file appears to be a text format dump"

If you are using liquibase in your database then some times you might have observed that your applications either unable to start or connect to database due to an active liquibase lock. You might see error like below:-

...........................
{"@timestamp":2025-04-05TO21:23:56.417+00:00","@version":"1","message":"SELECT `LOCKED` FROM
cyberithub_db.DATABASECHANGELOGLOCK WHERE ID=1","logger_name":"liquibase.executor.jvm.JdbcExecutor",
"thread_name":"main","level":"INFO","level_value":15000,"tags":["READ_SQL"]}
{"@timestamp":2025-04-05TO21:23:56.421+00:00","@version":"1","message":"Waiting for changelog lock...",
"logger_name":"liquibase.lockservice.StandardLockService","thread_name":"main","level":"INFO",
"level_value":15000,"tags":["LOG"]}
...........................

If you observe error like above then you probably have to remove the lock manually to allow your applications to connect to database. You can remove the lock by running below sql query:-

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

In few instances, you may have to replace LOCKED=0 with LOCKED=FALSE. After running above sql query, liquibase lock would be removed and now you will notice that your application is getting connected to the database. Before removing, you can also verify if the lock is active using below sql query:-

SELECT * FROM DATABASECHANGELOGLOCK;

If you see locked column set as true on output then liquibase lock is active and process is running. In some of the rarest cases where you will see liquibase process got killed and lock is still active then in that case you can simply drop the DATABASECHANGELOGLOCK table using below sql query. It will then be recreated automatically.

DROP TABLE DATABASECHANGELOGLOCK;

But a word of caution here, if you don't do it properly, removing liquibase lock can sometimes cause data corruption or incomplete database modifications.

Leave a Comment