Does Liquibase Support a Configurable Timeout for Whole Changeset Execution?
0 reputation · 14 Jun 2021, 13:23 UTC
0 reputation · 14 Jun 2021, 13:23 UTC
The goal is to allow a Liquibase update operation to be halted after a user‑defined duration, ensuring that any partially applied changeset can be rolled back or left in a known state.
Currently Liquibase executes each changeset within a database transaction when supported, but it does not expose a timeout property for the whole update; users must rely on JDBC driver statement timeouts, which only affect individual SQL statements and can leave a changeset partially applied. Interrupting the JVM with Ctrl+C stops further changeset processing, yet already‑executed statements are not rolled back unless the transaction can be rolled back, and external locks or preconditions may ignore the interrupt, leaving side effects.
Can a global timeout be added to the Liquibase update command without requiring changes to each changeset? Would such a timeout need to trigger a rollback of the current transaction, and how would it behave on databases that do not support DDL transactions? How should the timeout interact with external locks, preconditions, and context checks to avoid leaving inconsistent side effects?
34775 reputation · 14 Jun 2021, 16:49 UTC
Yes. Liquibase provides a timeout attribute on the <changeSet> element that aborts the entire change set after the specified number of seconds and marks it as failed.
Thread.join(timeout * 1000).timeout attribute is omitted, the change set runs without a time limit.Liquibase does not expose a command‑line‑level global timeout for update. To achieve a whole‑update timeout without editing each individual change set, you can:
<include> reference to the changelog file (or nest them), and add the timeout attribute to that outer change set.timeout attribute to each change set you want to guard; the attribute is inherited by default when using <includeAll> with a relativeToChangelogFile flag.DATABASECHANGELOG but does not undo the work.liquibase --version (must be ≥ 3.5).<changeSet id="timeout-test" author="test" timeout="5">
<sql>SELECT pg_sleep(10);</sql>
</changeSet>liquibase update and observe that execution stops after ~5 seconds with an exception containing the word “timeout”.DATABASECHANGELOG table; the row for this change set should have EXECUTED = false and ERRORMSG mentioning the timeout.Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 14 Jun 2021, 14:25 UTC
The previous answer describes a timeout attribute on <changeSet> that does not exist in any released Liquibase version (through 4.29.x). The only timeout property in core is liquibase.lockTimeout, which governs how long the migrator waits to acquire the DATABASECHANGELOGLOCK — not how long a changeset or full update may run.
queryTimeout, socketTimeout) apply per-statement; a multi-statement changeset can exceed any wall-clock limit without any single statement timing out.Teams needing a hard deadline typically wrap the liquibase update call in an external supervisor (shell timeout, Kubernetes activeDeadlineSeconds, CI job timeout) and accept that on non-transactional-DDL databases a kill may leave the schema partially applied. Feature requests for a native global timeout (e.g., #2481, #3124) remain open.