Why a Metabase H2 database locks or corrupts and when to fix it first
When a Metabase instance will not start, hangs on load, or fails right after a version change, and it runs on the embedded H2 application database, the fix depends on first preserving the H2 file, then moving the application database off H2. Metabase ships H2 so that demos and evaluations work out of the box, and its documentation recommends PostgreSQL for production. H2 is a file-based store, so it can lock when a second process touches the same file, for example when a container restarts while an old instance still holds the file, or when two copies of Metabase are pointed at one volume. A damaged file can follow an unclean shutdown or a full disk. Before you restart anything, copy the whole data directory and the file so that you have a point you can return to.
This page is for teams whose application database is H2 and who now need to recover it, or who need to get off it. Confirm first which application database your instance uses and which Metabase version last wrote the file, because the migration tool must run with that same version. Check the exact file name and location in your deployment and your environment variables, not in a generic example. Expect that recovery work may need a version change or a rollback, which is covered in the upgrade and backup sections of this group.
This page does not solve problems that sit outside the application database. A failing connection to a data warehouse, slow queries against your sources, single sign-on errors, and email delivery failures have their own troubleshooting pages, and a clean move to PostgreSQL will not fix them. Treat those as separate investigations so that a database fix does not hide a login or mail problem that is still open.
Recovery paths for a locked or corrupted H2 instance
This table compares four ways to recover a Metabase instance running on H2: restoring a known good backup, repairing in place, rebuilding on PostgreSQL, and rolling forward after a failed downgrade. Read each row for when the path fits, what data it puts at risk and what must be true before you start. The main takeaway is that every path depends on a preserved copy of the H2 file and on the Metabase version that last wrote it.
| Path | When it fits | Data at risk | Before you start |
|---|---|---|---|
| Restore a known good backup | The live H2 file is corrupted or unrecoverable and a recent copy exists | Changes made after the backup was taken, including saved questions, dashboards and user changes | Confirm the backup's date, stop Metabase, and keep the damaged file untouched for later inspection |
| Repair in place, then migrate | The file is locked or damaged but the original copy is intact and you can run the same version | Low if you work on a copy, high if you work on the only file | Match the Metabase version that last wrote the file, stop all processes, and copy the file first |
| Rebuild on PostgreSQL from a fresh instance | You need a production database and the H2 file can be read with the version that wrote it | Anything the migration step does not carry over, so check content after the move | Provision PostgreSQL, run load-from-h2 with the matching version, and verify collections, users and permissions |
| Roll forward after a failed downgrade | A downgrade left the H2 file in a state an older version cannot read | Data written by the newer version may be incompatible with the older JAR | Identify the newer version that wrote the file, reinstall it, and stop before any further schema changes |
| Load-from-h2 with a mismatched version | Generally not a recovery path, only a last resort after confirming the version | Migration may fail or write an incomplete application database | Confirm the version that last updated the file, since the migration must use that same version |
Recovering the H2 file and moving to PostgreSQL in order
This sequence stops writes to the H2 file, preserves a copy, and moves the application database to PostgreSQL with the Metabase version that last wrote the file. The result is a verified instance whose users, groups, saved questions and data source connections match what existed before the move.
Stop every Metabase process
Stop all Metabase application processes and containers that point at the H2 file, including any second node in a cluster, so nothing writes to the file while you work. Confirm nothing still holds the file by checking that the process list and container list show no running Metabase instance for that data directory. Do not start the instance again until the copy in the next step is verified. This step is done when no process is writing to the directory.
Copy the H2 file and its directory
Copy the entire H2 data directory, including the database file and any companion files, to separate storage before you change anything. Record the file size and a checksum for both the original and the copy, and confirm they match. Keep the original untouched as your rollback point, because every later step can be repeated from this copy. The step is complete when the checksums match and you can list the copy from a different host or path.
Identify the version that last wrote the file
Determine which Metabase version last wrote the H2 file. Check the version recorded in your deployment records, the image tag or JAR name used by the last running instance, and the Metabase logs if they are still available. Metabase documents that load-from-h2 must run with that same version, so write the exact version string down and keep it with the backup. If you cannot confirm it, ask whoever ran the instance last, and do not guess a newer or older release.
Prepare the PostgreSQL application database
Create an empty PostgreSQL database and a dedicated role for Metabase's application data, following the guidance in the Metabase application database documentation. Confirm that you can connect with that role from the host that will run Metabase and that the database is empty. Keep the PostgreSQL credentials in your secrets store rather than in shell history. The step is done when a test connection succeeds and the target database has no existing Metabase tables.
Run load-from-h2 with the matching version
Run the load-from-h2 command using the exact Metabase version identified earlier, pointing it at the copied H2 file and the new PostgreSQL target. Keep the command output and exit status in your change record. Do not run this step against the original file, and do not use a different version to try again without restoring the copy first. The step is done when the command exits successfully and the output reports the load completed without errors.
Point Metabase at PostgreSQL and start it
Configure the same Metabase version to use the PostgreSQL application database through its environment or configuration settings, then start a single instance. Watch the startup logs for database connection errors and for any migration messages. Keep the instance on the same version for now, and do not upgrade during this step. The step is complete when the application starts and reports healthy on its status endpoint.
Verify users, groups, questions and connections
Sign in and compare the restored instance with your inventory from before the failure: user accounts and their roles, groups and their permissions, a sample of saved questions and dashboards, and each data source connection with a test query. Record each check as pass or fail. If a check fails, stop and compare it with the H2 copy rather than re-editing content in place. The step is done when every sampled item matches and the results are saved with the change record.
Keep rollback points until verification signs off
Keep the original H2 directory, the copied H2 file, the PostgreSQL database snapshot taken after load, and the version record until users confirm their content is correct. If the PostgreSQL move fails verification, return to the original H2 directory and the same version, and restart from the copy. Plan any later Metabase upgrade only after a fresh application database backup on PostgreSQL. The step is done when the business owner signs off and the rollback materials are archived with a stated retention owner.
How the H2 file moves to PostgreSQL during recovery
The flow starts with a stopped Metabase instance and a backup copy of the H2 application database file, so the original is never the only copy. The team confirms it runs the same Metabase version that last wrote that file, then runs the load-from-h2 command to load the data into PostgreSQL. Before the instance is pointed at PostgreSQL and restarted, a failed copy or a version mismatch sends the team back to the backup, and the restarted instance is verified against the migrated data.
Recovery path from a stopped H2 instance to a verified PostgreSQL application database, with the rollback decision point.
Protecting data and access during H2 recovery
An H2 file holds everything Metabase stores about itself, including user accounts, connection details and settings that depend on the encryption key. The cards below cover the controls that keep that data protected while you copy, migrate and verify it, so recovery does not create a new exposure.
Keep copies under the same access controls
Every copy of the H2 file is as sensitive as the live instance, because it contains application data, hashed credentials and stored database connection details. Store working copies, backups and scratch files in locations with the same restrictions as production, and limit read access to the people doing the recovery. Confirm that copies on laptops, shared drives or ticket attachments are removed once the migration is verified.
Back up the file with its encryption key
If Metabase encryption is configured, the stored connection details can only be read with the matching encryption key, so a backup of the H2 file without that key is incomplete. Record where the key lives, and keep the key and the backup in separate but controlled locations so that a restore can be completed later. Check that the key you hold matches the instance that wrote the file before you rely on the copy.
Limit who can run the migration
The load-from-h2 step writes your application data into a new PostgreSQL or MySQL database, so it should be run by a small named group, not by whoever happens to have shell access. Use a dedicated service account or a named administrator, and confirm that the target database credentials are scoped to the Metabase application database only. Review who held that access after the cutover.
Keep the recovery instance off the network
A Metabase started from a recovered or temporary copy still holds live data and may still answer sign-ins and run queries against your connected databases. Run it on an isolated host or network segment, disable public routing and do not point it at production data sources until the copy has been checked. Remove or disable any test instance once the recovery is signed off.
Log each recovery step
Recovery work often happens under time pressure, and the steps taken are hard to reconstruct later. Keep a dated record of who copied the file, which Metabase version wrote it, which command ran, where the output went and who approved the cutover. This record supports change review and helps answer questions from your security or compliance team after an incident.
Match the version before migrating
The documented migration must be run with the same Metabase version that last wrote the H2 file, or it may fail or copy data incorrectly. Before any control above matters, confirm that version from the file's history or your change records, and record it in the log. Treat a mismatch as a stop condition and escalate it rather than trying a different version at random.
Migrating from H2 docsWhat changes after moving off H2, by team role
Platform administrators own the change itself. Once the application database moves, the Metabase process points at an external database through its connection settings rather than a file on the local disk, so the deployment is no longer a single self-contained unit. The backup and upgrade routines that used to copy one H2 file now have to cover the external database, and the Metabase version used for the load must match the one that last wrote the H2 file.
- Connection settings: Replace the embedded H2 setup with the environment variables or configuration for your chosen database, and confirm the Metabase process can reach it from every node that will run.
- Backups: Schedule backups of the new application database before the first upgrade, and test a restore rather than assuming the dump is usable.
- Upgrades: Plan upgrades against the new database, since the pre-upgrade backup now lives in that system.
- Encryption key: Keep the encryption key recorded with the backup so restored connection credentials can be read.
- Retired H2 files: Archive the old H2 file under your retention rules instead of deleting it on day one.
Confirm each step against the application database documentation for your Metabase version before you cut over.
Security reviewers care about who can reach the application database, what gets logged, and whether the access model survived the move. Moving off H2 changes the trust boundary: the application database now sits on a network service with its own accounts, TLS settings and audit trail, and those controls become part of the review. The permission records themselves are migrated, but reviewers should verify that rather than trust that the move was clean.
- Database accounts: Create a dedicated application database user with the rights Metabase needs and nothing more, and document who else holds access.
- Network path: Restrict the route from the Metabase nodes to the database and confirm that TLS is enabled where your policy requires it.
- Group and permission records: Compare groups, collection permissions and data permissions before and after the migration, using a sample of users with known access.
- Logging: Confirm that the new database and Metabase logs are retained and reach the same SIEM or log store as before.
- Sign-in paths: Recheck SSO, LDAP and admin accounts, since login behavior should be unchanged but has to be verified on the new instance.
Record the results as evidence, because an auditor will ask how you know the permissions carried over.
Analysts and content owners rely on saved questions, dashboards, and subscriptions. In most cases this content comes across with the application database, so the day-to-day experience should match what they had before. The risk is in the details: scheduled subscriptions and alerts depend on working email delivery, and any content that referenced a local file path or an embedded data source needs a check. Analysts are also the first to notice slow loading or missing items, so their checks catch problems the administrators may miss.
- Saved questions: Open a representative set of questions from each main collection and confirm the results and filters still match what they showed before the move.
- Dashboards: Load the most-used dashboards and compare the cards, parameters and filters against the old instance.
- Subscriptions and alerts: Send a test subscription to a known mailbox, since delivery depends on the mail settings being correct on the new instance.
- Loading time: Note how long key dashboards take to load and report slow pages to the platform team with the page name.
- Personal collections: Confirm that personal content for each owner is present and that nothing has moved into an unexpected collection.
Ask the content owners to sign off on their key dashboards before the old H2 file is archived.
Limits to confirm before you start the recovery
A locked or corrupted H2 file can be recovered only under a few conditions, and most failed recoveries trace back to one of them being assumed rather than checked. The cards below cover the facts to pin down in your own environment before you run any migration command.
Exact Metabase version that wrote the file
The load-from-h2 command must run with the same Metabase version that last wrote the H2 file, so the first step is identifying that version, not the version you plan to end on. Check the version in your deployment manifest, container image tag, or JAR filename, and compare it with what the running instance reports. If an upgrade ran partially, the file may have been written by a newer build than the one you think is installed.
Migration docsIntegrity of the H2 file
Decide whether the file is intact before choosing a path. Take a copy of the entire data directory first, including any write-ahead or lock files, so that every later attempt starts from the same bytes. A file that will not open may be locked by a stale process rather than damaged, so confirm that no Metabase process still holds it before you assume corruption.
Target PostgreSQL version
Confirm the PostgreSQL major version you will run and that the Metabase release you are migrating to supports it. Ask the platform team who will own the database, how it will be backed up, and whether it is sized for the application database alone. The migrated Metabase instance will depend on this database for all its configuration, so it should exist and be reachable before the load starts.
Application database docsCharacter set if MySQL or MariaDB is the target
If you choose MySQL or MariaDB instead of PostgreSQL, confirm the server version against the minimums Metabase documents and that the database and connection use utf8mb4. Without utf8mb4, characters outside the basic set can be stored incorrectly or cause errors on load. Check the collation and connection settings in the same review, since they are easy to miss in a default server install.
- MySQL minimum version
- 8.4.0
Downgrade and rollback path
Decide in advance how you will return to a known state if the migration fails. Metabase documents restoring a pre-upgrade application database backup as the recommended rollback, and running the migrate down command with the newer JAR as an alternative. Make sure you hold a verified copy of the H2 file and a dated backup of the target database before any change is made.
Upgrade docsIntermediate releases and LTS window
If the H2 file was written by a release older than the one you are targeting, confirm whether upgrades must step through intermediate versions first. Metabase advises upgrading release by release from versions older than 40, so check the version history for your starting point. Also confirm which release line you will run afterward: LTS releases are supported for 14 months, while non-LTS releases usually reach end of life after 2 months.
Version support pageQuestions teams ask before fixing a Metabase H2 database
How long does recovering a locked or corrupted Metabase H2 database take?
No duration is fixed for every case, and the answer depends on what is wrong and what you have to work with. The main drivers are the size of the H2 file, whether a clean recent copy exists, how many steps the recovery needs (stopping the instance, copying files, moving the application database, verifying), and how much testing you run before you trust the result. A lock caused by a stale process is usually quick to clear. A corrupted file that needs a restore from backup, plus a verified move to PostgreSQL, takes longer. Ask any provider to walk through the steps for your file and your environment before agreeing to a timeline.
Can our own team fix a locked or corrupted Metabase H2 database?
Often yes, if you have an engineer who is comfortable with the Metabase host, Java processes and file-level backups, and if you have a known-good backup. Metabase documents the move off H2 as a one-time load-from-h2 command that must be run with the same Metabase version that last wrote the H2 file, so version matching is the step most likely to go wrong. Teams without that experience, or with no verified backup, usually gain more from bringing in help for the recovery and then keeping the fix in their own runbook.
What do we need to provide before recovery work starts?
You need access to the host running Metabase and its data directory, the exact Metabase version that last wrote the H2 file, and any Java or container configuration that starts it. You also need an agreed maintenance window, because the instance must be stopped while files are copied and the database is moved. Make sure a copy of the H2 files exists before anything changes, and name one person on your side who can approve decisions, confirm users are out of the tool and sign off on the result. Confirm the details with your own environment owner before work begins.
What does a partner's fixed-scope engagement for an H2 recovery cover?
A fixed-scope engagement covers what is written in the agreed statement of work, usually the diagnosis of the lock or corruption, the recovery steps for the affected files, the move to a supported application database, verification that users, saved questions and dashboards work, and documentation of what was done. DeployOpen implements, hardens, backs up and documents self-hosted open-source platforms in your own infrastructure, and its work is scoped and agreed in writing before it starts. Scope, deliverables and timelines are set in that document, so ask for the exclusions in writing too, such as data source changes or a wider upgrade.
Is our Metabase data at risk during an H2 recovery?
Data is at risk mainly when the only copy of the H2 files is the damaged one, or when someone tries a fix without a backup and the file is overwritten. Before changing anything, copy the entire data directory, record the Metabase version, and check that the copy opens in a test environment if you can. Recovery steps should be run against copies first. Be aware that the encryption key used by Metabase is needed alongside the database, so keep it with the backup.
What drives the cost of an H2 recovery, and what should we ask for in a quote?
Cost follows effort, and effort follows the number of unknowns: the state of the file, how many environments need the change, whether a restore is needed, how much verification your team wants, and whether the move to PostgreSQL includes new infrastructure. You pay for diagnosis, recovery work, the migration itself, testing and documentation, and some of that is one-time while ongoing support is recurring. Ask a quote to separate those phases, list the assumptions about your file and version, name the exclusions and state who provides the database host. DeployOpen does not publish prices, and a quote follows from the written scope.
How do we avoid a locked or corrupted H2 database in the future?
Move the application database off H2 before it becomes a production dependency. Metabase ships H2 for demos and recommends PostgreSQL for production, and supports MySQL 8.4.0 or MariaDB 10.6.0 and later with utf8mb4 as alternatives. Once you are on a server database, schedule backups of the application database, test restores on a regular basis, and keep a written record of the Metabase version and encryption key location. Review the Metabase application database documentation when you plan the target setup.
Official Metabase guidance for H2 recovery
Start with Metabase's own documentation before you touch the H2 files. Metabase publishes two pages that matter here: the migration guide for the H2 application database, which covers the load-from-h2 command, and a troubleshooting guide for using or migrating from H2. Read both in full, then confirm the exact Metabase version currently running against the H2 file, because the documentation's recovery steps depend on it. The most important version fact is that load-from-h2 must be run with the same Metabase version that last wrote the H2 file. Running it with a newer or older JAR can fail or leave the target database in a state that is hard to reason about, so record the version from the running instance or its logs before you plan any step.
Treat the version-specific notes as part of the procedure, not background reading. The migration page and troubleshooting guide describe what each step expects, including which JAR to use, which Java runtime applies, and what the target PostgreSQL or MySQL database must look like before the load. Check the target engine against the supported versions listed in Metabase's application database documentation, and confirm the character set for MySQL or MariaDB. Where the documentation does not state a requirement you need, such as the exact Java version for your release, confirm it with Metabase's documentation for that version or with Metabase support rather than inferring it from a newer release. Keep a copy of the H2 files untouched before any attempt, so every step can be repeated from the same starting point.
How DeployOpen scopes and delivers an H2 recovery
DeployOpen approaches an H2 recovery as a fixed-scope piece of work inside your own infrastructure. We start by establishing what state the H2 application database is in, which Metabase version last wrote it, and what has to be preserved before anything is changed. The recovery then moves the application database to PostgreSQL in a controlled, documented way.
How we scope
- Confirm the Metabase version currently running and the exact version that last wrote the H2 file.
- Inventory the H2 file location, backups, host access and any users depending on the instance.
- Agree in writing whether the work is recovery only, a PostgreSQL move, or both, with deliverables and timelines.
How we build
- Take a copy of the H2 files and verify it opens before any repair or migration step begins.
- Run the documented load-from-h2 step with the matching Metabase version on a staging copy first.
- Test logins, saved questions, dashboards and database connections against the migrated application database.
How we hand over
- Deliver a runbook recording versions, file paths, commands run, and the rollback path taken.
- Provide a PostgreSQL backup routine for the new application database and a restore test record.
- Walk your platform and admin team through the cutover so they can reproduce the steps later.
How we support
- Offer ongoing support, upgrades and continuous testing as a retainer after the recovery is complete.
- Plan future Metabase upgrades around a fresh application database backup and a tested rollback.
- Confirm support boundaries and response expectations in the written scope before work starts.

