Size JVM heap and RAM for diff-class commands
Last updated: July 8, 2026
Diff-class commands — snapshot, snapshot-reference, diff, diff-changelog, and generate-changelog — can exhaust JVM memory on large schemas, causing OutOfMemoryError failures or long pauses from garbage collection. This happens because each command loads a model of your database objects into memory; diff and diff-changelog load two models at once, one for each side of the comparison. This guidance is based on measurements against Oracle and SQL Server schemas of different sizes, using the default G1GC garbage collector.
Before you begin
Budget your JVM heap using the following rules of thumb:
snapshotandgenerate-changelog: approximately 3 GB of heap per million objects (one schema resident, column-heavy worst case, scales linearly)diffanddiff-changelog: roughly double the per-schema amount (both target and reference schema resident at once)Recommended
-Xmxvalues in the tables below are roughly 1.5× the observed peak heap
Procedure
Count the objects in your schema
Count the total number of objects in your schema: tables, views, indexes, sequences, procedures, and so on. You'll use this count to find the matching row in the sizing table in the next step.
Find your sizing table
snapshot and generate-changelog sizing (one schema resident)
| Objects per schema | Peak heap | Min -Xmx | Recommended -Xmx |
|---|---|---|---|
Up to 100k | ~0.4 GB | 512m-1g | 2g |
~1m | ~3.6 GB | 4g | 6g |
~2m | ~4.4-5.8 GB | 4g (SQL Server) / 6g (Oracle) | 8g |
Up to 100k
~0.4 GB
512m-1g
2g
~1m
~3.6 GB
4g
6g
~2m
~4.4-5.8 GB
4g (SQL Server) / 6g (Oracle)
8g
diff and diff-changelog sizing (target + reference resident)
| Objects per schema | Peak heap | Min -Xmx | Recommended -Xmx |
|---|---|---|---|
Up to 100k | ~1-2 GB | 2g | 4g |
~1m | ~4 GB | 4g | 6g |
~2m | ~6.5-8.6 GB | 6g (Oracle) / 8g (SQL Server) | 12g |
Up to 100k
~1-2 GB
2g
4g
~1m
~4 GB
4g
6g
~2m
~6.5-8.6 GB
6g (Oracle) / 8g (SQL Server)
12g
Convert heap to RAM
Don’t provision machine RAM equal to your -Xmx value. That’s JVM heap only. Size RAM above it: RAM ≈ -Xmx + ~1 GB for metaspace, thread stacks, code cache, and buffers. Add further headroom if your database is co-located on the same machine.
| Recommended -Xmx (heap) | Plan RAM for JVM |
|---|---|
2g | ~3 GB |
6g | ~7 GB |
8g | ~9-10 GB |
12g | ~13-14 GB |
2g
~3 GB
6g
~7 GB
8g
~9-10 GB
12g
~13-14 GB
Understand what affects run time
SQL Server diff runs heavier than Oracle at the same object count, because diff-class commands on SQL Server are metadata-latency-bound rather than heap-bound. Actual run time also depends heavily on network latency between Liquibase and the database, storage performance, and current database load.
Because these factors vary by environment, this guidance doesn't publish expected run times. Run a test invocation against a non-production copy of your schema to establish a baseline before scheduling production runs.
Heap usage is driven primarily by object count, dominated by columns. Stored procedures, packages, and package bodies add comparatively little heap (their bodies are streamed to files) but they do add proportionally more processing overhead.
Note: If any object type in your schema exceeds 100k rows, set -Dliquibase.sql.maxResultSetSize=5000000. Without it, snapshot and diff abort quickly instead of streaming through the large result set.
Run the command
Set -Xmx to the Recommended value from step 2:
Bash
JAVA_OPTS="-Xms512m -Xmxyour_xmx_value" liquibase your_commandBe sure to:
Replace
your_xmx_valuewith the Recommended-Xmxvalue from step 2, including the unit. For example,6g,12gReplace
your_commandwith the command you're running. For example,generate-changelog,diff
For example
Troubleshooting heap errors
A genuine heap exhaustion throws OutOfMemoryError: Java heap space (or GC overhead limit exceeded). Liquibase writes this to the console and to --log-file, and the command exits non-zero, but the output is a raw JVM stack trace rather than a suggestion to raise -Xmx. Use the sizing guidance above to choose the right value up front rather than discovering it after a failure. On large-object schemas, the maxResultSetSize guard described in step 4 usually fails first, with an explicit, actionable message rather than a JVM crash. For example:
Query exceeded maximum result set size of 100000 rows… increase liquibase.sql.maxResultSetSize
Note: Liquibase does not print peak heap usage by default. The peak-heap figures in this guidance came from GC logs and process RSS. To observe peak heap live, add -Xlog:gc*:file=gc.log to JAVA_OPTS.
What to do next
System requirements — general hardware and software requirements for Liquibase Secure 5.2.1
What are the memory limits on inspecting large schemas? — causes,
--snapshot-filters, and other mitigationsgenerate-changelogcommand referencediffcommand reference