Applies to:
- Liquibase Pro
- Liquibase Open Source (Community)
Conditions:
- Any version of Liquibase Pro or Open Source
- Using either
generate-changelog
,diff-changelog
, orsnapshot
Issue Summary:
When using a Liquibase command that captures the current state of the database, such as generate-changelog
, diff
, or diff-changelog
, the structure will be stored in memory. Due to this, it is possible to have a stack overflow error occur when running one of these commands.
Error Message:
java.lang.StackOverflowError
Root Causes:
The potential root cause of the stack overflow error is most likely the number of objects Liquibase is trying to store in memory.
Resolution:
There are two resolutions listed below:
- Increase the Stack/Heap size the JVM has access to
- Restrict objects in generate-changelog/diff/diff-changelog
Both can be used at the same time or used individually.
Increase the Stack/Heap size the JVM has Access to
One way to resolve a stack overflow error is to increase the stack and heap size that the JVM uses. Either argument for modifying the stack or heap size needs to be set in the JAVA_OPTS variable, which can either be set in the environment or passed to Liquibase at runtime.
Set the Stack Size
In order to set the stack size, the argument -Xss
needs to be set in the JAVA_OPTS variable, followed by the size that the stack should use:
For example, the following command sets the stack size to 2 megabytes.
JAVA_OPTS="-Xss2m" liquibase generate-changelog --changelog-file=newChangeLog.xml
Set the Max Heap Size
In order to set the max heap size, the argument -Xmx
needs to be set in the JAVA_OPTS variable, followed by the amount of max memory that can be used.
For example, the following command sets the max heap size to 1 gigabyte
JAVA_OPTS="-Xmx1g" liquibase generate-changelog --changelog-file=newChangeLog.xml
Restrict Objects in generate-changelog/diff/diff-changelog
The following commands generate-changelog, diff, and diff-changelog, all capture objects in the database and store them in memory during runtime. There is an argument, diff-types
, that controls what objects Liquibase captures.
By default, the object types captured are columns, foreign keys, indexes, primary keys, tables, unique constraints, and views. More object types can be added if you have a Liquibase Pro license key.
In the event of a stack overflow error, the diff-types
argument can be used to isolate specific objects to minimize the amount of runtime memory in use, preventing a stack overflow error.
For example, to restrict the generated changelog to just tables, the following command can be used.
liquibase generate-changelog --changelog-file=newChangeLog.xml --diff-types=tables
Comments
0 comments
Article is closed for comments.