Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

A deployment hangs at startup with 'Waiting for changelog lock....' from Liquibase. What happened and how do you recover?

An earlier Liquibase run was killed while it held the changelog lock, so the single row in DATABASECHANGELOGLOCK still says LOCKED = true and every new instance waits for a release that will never come. We first confirm that no migration is really running, then release the lock with liquibase release-locks (releaseLocks in older versions) or by resetting the row, and we check which changeSets were applied before the crash, because non-transactional DDL may be half done. To make it rarer, we run migrations as a separate job instead of in every instance's startup.

Why this question is asked

A deployment that hangs is worse than one that fails: nothing turns red, the pods just sit there printing the same line every ten seconds, and eventually a timeout rolls the release back without explaining why. With Liquibase, the line is Waiting for changelog lock...., and the cause is almost always a lock left behind by a process that died. Interviewers ask this because the fix is one SQL statement, but doing it safely needs an understanding of what the lock protects. In this answer, we will see how the Liquibase lock works, why it can outlive its owner, how to confirm and release it safely, how to check for a half-applied changeSet, and how to set up deployments so it does not happen again.

1How the Changelog Lock Works

Before applying changes, Liquibase makes sure that only one process is migrating the database at a time. It does this with a table called DATABASECHANGELOGLOCK, which has one row with the columns ID, LOCKED, LOCKGRANTED and LOCKEDBY. Liquibase runs an update that sets LOCKED to true only if it is currently false. If the update succeeds, this process owns the lock; it records the time and its host name, runs the changeSets, and finally sets LOCKED back to false.

If the update finds LOCKED already true, another process is migrating, so Liquibase waits, checks again every few seconds and prints Waiting for changelog lock.... After a configurable wait, five minutes by default, it gives up with an error, which in Spring Boot means the application fails to start. The idea is sound: with ten instances starting at once, nine wait while one migrates.

2Why the Lock Can Outlive Its Owner

The lock is just a value in a normal table. It is not tied to the database session that set it, so if the process dies before its last step, nobody resets it. The database has no idea that the owner is gone.

SQL
SELECT * FROM databasechangeloglock;
-- id | locked | lockgranted | lockedby
-- 1 | t | 2026-11-05 09:12:44 | orders-7f9c4d-xk2lp (10.2.3.17)
-- New pod log, every 10 seconds:
-- Waiting for changelog lock....
Step throughHow a killed pod leaves the lock behind
Pod ADatabasePod BKubernetes
set LOCKED = true (granted)
run a slow changeSet
probe failed: kill pod A
set LOCKED = true?
already locked by pod A
Waiting for changelog lock....
probe failed: kill pod B

7 messages in order. Play them, or step through them one at a time.

The lock is a row in a table, so it stays set after its owner dies.

The usual killer is the platform itself. A migration on a large table takes longer than the startup probe or liveness probe allows, so Kubernetes kills the pod mid-migration and starts a new one. The new pod waits for a lock held by the dead pod, the probe kills it too, and the deployment loops. Out-of-memory kills, a node failure or a developer pressing Ctrl-C during a local run leave the same trace. Notice the LOCKEDBY value: it names a pod that no longer exists, which is our first clue.

3Confirming Nothing Is Really Running

Before releasing the lock, we must be sure it really is stale. If a migration is still running somewhere, for example a separate job or a pod in another deployment, releasing the lock lets a second process apply the same changes at the same time, which can corrupt the schema. So we check three things: whether the host in LOCKEDBY still exists, how long ago LOCKGRANTED was, and whether the database shows any session from the migration user still running statements.

Java
-- PostgreSQL: is anything from the migration user still active?
SELECT pid, application_name, state, query_start, left(query, 60)
FROM pg_stat_activity
WHERE usename = 'migrator' AND state <> 'idle';
-- (0 rows) -> nothing is running
-- MySQL equivalent
SELECT id, user, time, state, info FROM information_schema.processlist WHERE user = 'migrator';

If the pod in LOCKEDBY is gone, the lock was granted an hour ago and no migration session is active, the lock is stale. If a long ALTER TABLE is still running, we wait for it instead, or decide deliberately to cancel it.

4Releasing the Lock

Liquibase provides a command for this. The CLI's release-locks command (called releaseLocks in older versions; check your version) resets the row. We can also do it directly in SQL, which is often quicker in an emergency.

Java
liquibase --url=jdbc:postgresql://db/orders --username=migrator release-locks
# Successfully released all database change log locks for 'migrator@jdbc:postgresql://db/orders'
-- or directly
UPDATE databasechangeloglock SET locked = false, lockgranted = NULL, lockedby = NULL WHERE id = 1;
-- 1 row updated

Once the row is reset, the next instance that starts takes the lock and continues the update from the first changeSet not recorded in DATABASECHANGELOG. But before restarting the deployment, there is one more check to make.

5Checking for a Half-Applied ChangeSet

Liquibase records a changeSet in DATABASECHANGELOG only after it completes. On PostgreSQL, a changeSet runs in a transaction and DDL is transactional, so a killed run rolls the unfinished changeSet back completely; the next run simply repeats it. On MySQL, and on other databases where DDL commits immediately, a changeSet with three statements can stop after the first, leaving that change applied but not recorded. The next run then tries the first statement again and fails, for example with a duplicate column error.

SQL
-- What does Liquibase think ran last?
SELECT id, author, filename, dateexecuted, orderexecuted
FROM databasechangelog ORDER BY orderexecuted DESC LIMIT 3;
-- add-invoice-status | anna | changes/057.yaml | 2026-11-05 09:12:41 | 412
-- Is the next changeSet (058: add column + index) partly there?
SHOW COLUMNS FROM invoice LIKE 'due_date'; -- present: the first statement ran
SHOW INDEX FROM invoice WHERE Key_name = 'idx_invoice_due'; -- empty: the second did not

If the next changeSet is partly applied, we finish or undo it by hand, so the database matches either fully before or fully after it, and then either let Liquibase run it or, if we completed it by hand, mark it as run with the mark-next-changeset-ran command (markNextChangeSetRan in older versions). One statement per changeSet, or a precondition that checks whether the column already exists, makes this recovery much simpler.

6Running Migrations Once, Outside Startup

The underlying problem is that every instance tries to migrate as part of its startup, and startup is subject to health probes and fast restarts. A better setup runs the migration once, as its own step before the new version rolls out: a Kubernetes Job, a pipeline stage or a dedicated container that runs Liquibase update and exits. It can take as long as it needs, nothing kills it for being slow, and its logs are in one place. The application then starts with spring.liquibase.enabled=false, or with Liquibase only validating. If startup migration must stay, the startup probe should allow enough time for the slowest expected migration, and the lock wait time should be set so a stuck lock fails quickly and visibly instead of looping.

7Follow-up questions

Why does Liquibase not use a database session lock that disappears with the connection?

The default lock is a table row because it works the same way on every database Liquibase supports. Some databases offer session-level advisory locks that are released automatically when the connection dies, and extensions or newer versions may use them; check what your version offers before relying on it.

How long does Liquibase wait before giving up?

By default about five minutes, checking every ten seconds, and both values are configurable. In Spring Boot, failing after that time stops startup, so in a rolling deployment the new pods never become ready and the old version keeps serving.

Is it safe to release the lock automatically at startup?

No. An automatic release cannot tell a stale lock from a migration that is still running on another instance, and releasing a live lock lets two processes migrate concurrently. Releasing should be a deliberate step after confirming nothing is running.

8Conclusion

In this answer, we saw that Waiting for changelog lock means DATABASECHANGELOGLOCK still holds LOCKED = true from a run that was killed, often by a health probe during a slow migration. We confirmed the lock was stale by checking LOCKEDBY, LOCKGRANTED and the active sessions, released it with release-locks or an UPDATE, checked DATABASECHANGELOG and the schema for a half-applied changeSet on databases without transactional DDL, and moved migrations into a single job before the rollout so it happens less often.

What to say in the interviewAbout 80 seconds aloud

Open with

That message means the row in DATABASECHANGELOGLOCK still has LOCKED set to true. Liquibase takes that lock by updating a normal table row, so if a process dies while migrating, the lock is never released, and every new instance waits for it and eventually times out.

Then, if they want more

Very often a Kubernetes probe killed a pod during a slow changeSet. First I check that nothing is really running: LOCKEDBY names the host, so I see if that pod still exists, how old LOCKGRANTED is, and whether pg_stat_activity or the MySQL processlist shows any session from the migration user.

If it is stale, I release it with the release-locks command or by updating the row to locked false with lockgranted and lockedby null. Before restarting, I look at the last rows in DATABASECHANGELOG and check whether the next changeSet was partly applied.

On PostgreSQL the changeSet was rolled back with its transaction, but on MySQL DDL commits implicitly, so a column might exist without its index, and I would complete or undo that by hand first.

For the long term, I would run migrations once as a separate Job or pipeline step before the rollout and disable Liquibase in the application's startup, so probes never kill a migration halfway.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "A deployment hangs at startup with 'Waiting for changelog lock....' from Liquibase. What...": https://scrivio-interview-library.netlify.app/databases/schema-migration/ac66e775c7/