Database has unrun migrations

Our self-hosted Metabase (docker image on a DigitalOcean droplet) site hasn't been activley used lately. We just realiased it has stopped running recently so decided to give it a upgrade whilst fixing it up. Pulled the latest image on Docker and did the following:

docker run -d -p 3000:3000 \
-v ~/metabase-data:/metabase-data \
-e "MB_DB_FILE=/metabase-data/metabase.db" \
--name metabase metabase/metabase

Metabase then initialise for a minute (we could see the initialising screen), stuck there, then shuts itself down (back to 502 error).

Logs:

2023-12-04 20:00:00,500 INFO driver.impl :: Registered abstract driver :sql  🚚
2023-12-04 20:00:00,518 INFO driver.impl :: Registered abstract driver :sql-jdbc (parents: [:sql]) 🚚
2023-12-04 20:00:00,524 INFO metabase.util :: Load driver :sql-jdbc took 119.8 ms
2023-12-04 20:00:00,525 INFO driver.impl :: Registered driver :h2 (parents: [:sql-jdbc]) 🚚
2023-12-04 20:00:00,584 INFO driver.impl :: Registered driver :mysql (parents: [:sql-jdbc]) 🚚
2023-12-04 20:00:00,623 INFO driver.impl :: Registered driver :postgres (parents: [:sql-jdbc]) 🚚
2023-12-04 20:00:04,337 INFO metabase.core ::
Metabase v0.47.9 (d05b06e ?)

Copyright © 2023 Metabase, Inc.

Metabase Enterprise Edition extensions are NOT PRESENT.
2023-12-04 20:00:04,355 INFO metabase.core :: Starting Metabase in STANDALONE mode
2023-12-04 20:00:04,473 INFO metabase.server :: Launching Embedded Jetty Webserver with config:
 {:port 3000, :host "0.0.0.0"}

2023-12-04 20:00:04,579 INFO metabase.core :: Starting Metabase version v0.47.9 (d05b06e ?) ...
2023-12-04 20:00:04,621 INFO metabase.core :: System info:
 {"file.encoding" "UTF-8",
 "java.runtime.name" "OpenJDK Runtime Environment",
 "java.runtime.version" "11.0.21+9",
 "java.vendor" "Eclipse Adoptium",
 "java.vendor.url" "https://adoptium.net/",
 "java.version" "11.0.21",
 "java.vm.name" "OpenJDK 64-Bit Server VM",
 "java.vm.version" "11.0.21+9",
 "os.name" "Linux",
 "os.version" "3.10.0-693.11.6.el7.x86_64",
 "user.language" "en",
 "user.timezone" "GMT"}

2023-12-04 20:00:04,624 INFO metabase.plugins :: Loading plugins in /plugins...
2023-12-04 20:00:05,207 INFO plugins.dependencies :: Metabase cannot initialize plugin Metabase Oracle Driver due to required dependencies. Metabase requires the Oracle JDBC driver in order to connect to Oracle databases, but we can't ship it as part of Metabase due to licensing restrictions. See https://metabase.com/docs/latest/administration-guide/databases/oracle.html for more details.

2023-12-04 20:00:05,209 INFO plugins.dependencies :: Metabase Oracle Driver dependency {:class oracle.jdbc.OracleDriver} satisfied? false
2023-12-04 20:00:05,210 INFO plugins.dependencies :: Plugins with unsatisfied deps: ["Metabase Oracle Driver"]
2023-12-04 20:00:05,228 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :druid...
2023-12-04 20:00:05,230 INFO driver.impl :: Registered driver :druid  🚚
2023-12-04 20:00:05,242 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :googleanalytics...
2023-12-04 20:00:05,243 INFO driver.impl :: Registered driver :googleanalytics  🚚
2023-12-04 20:00:05,255 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :sqlite...
2023-12-04 20:00:05,259 INFO driver.impl :: Registered driver :sqlite (parents: [:sql-jdbc]) 🚚
2023-12-04 20:00:05,271 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :sqlserver...
2023-12-04 20:00:05,272 INFO driver.impl :: Registered driver :sqlserver (parents: [:sql-jdbc]) 🚚
2023-12-04 20:00:05,343 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :bigquery-cloud-sdk...
2023-12-04 20:00:05,344 INFO driver.impl :: Registered driver :bigquery-cloud-sdk (parents: [:sql]) 🚚
2023-12-04 20:00:05,366 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :mongo...
2023-12-04 20:00:05,367 INFO driver.impl :: Registered driver :mongo  🚚
2023-12-04 20:00:05,379 INFO plugins.dependencies :: Metabase cannot initialize plugin Metabase Vertica Driver due to required dependencies. Metabase requires the Vertica JDBC driver in order to connect to Vertica databases, but we can't ship it as part of Metabase due to licensing restrictions. See https://metabase.com/docs/latest/administration-guide/databases/vertica.html for more details.

2023-12-04 20:00:05,380 INFO plugins.dependencies :: Metabase Vertica Driver dependency {:class com.vertica.jdbc.Driver} satisfied? false
2023-12-04 20:00:05,380 INFO plugins.dependencies :: Plugins with unsatisfied deps: ["Metabase Oracle Driver" "Metabase Vertica Driver"]
2023-12-04 20:00:05,442 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :snowflake...
2023-12-04 20:00:05,443 INFO driver.impl :: Registered driver :snowflake (parents: [:sql-jdbc]) 🚚
2023-12-04 20:00:05,459 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :redshift...
2023-12-04 20:00:05,460 INFO driver.impl :: Registered driver :redshift (parents: [:postgres]) 🚚
2023-12-04 20:00:05,491 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :athena...
2023-12-04 20:00:05,495 INFO driver.impl :: Registered driver :athena (parents: [:sql-jdbc]) 🚚
2023-12-04 20:00:05,517 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :hive-like...
2023-12-04 20:00:05,518 INFO driver.impl :: Registered abstract driver :hive-like (parents: [:sql-jdbc]) 🚚
2023-12-04 20:00:05,522 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :sparksql...
2023-12-04 20:00:05,523 INFO driver.impl :: Registered driver :sparksql (parents: [:hive-like]) 🚚
2023-12-04 20:00:05,567 DEBUG plugins.lazy-loaded-driver :: Registering lazy loading driver :presto-jdbc...
2023-12-04 20:00:05,568 INFO driver.impl :: Registered driver :presto-jdbc (parents: [:sql-jdbc]) 🚚
2023-12-04 20:00:05,570 INFO metabase.core :: Setting up and migrating Metabase DB. Please sit tight, this may take a minute...
2023-12-04 20:00:05,579 INFO db.setup :: Verifying h2 Database Connection ...
2023-12-04 20:00:06,466 INFO db.setup :: Successfully verified H2 2.1.214 (2022-06-13) application database connection. ✅
2023-12-04 20:00:06,468 INFO db.setup :: Running Database Migrations...
2023-12-04 20:00:06,471 INFO db.setup :: Setting up Liquibase...
2023-12-04 20:00:06,970 INFO db.setup :: Liquibase is ready.
2023-12-04 20:00:06,971 INFO db.liquibase :: Checking if Database has unrun migrations...
2023-12-04 20:00:09,132 INFO db.liquibase :: Database has unrun migrations. Waiting for migration lock to be cleared...
2023-12-04 20:00:11,147 WARN util.jvm :: auto-retry metabase.db.liquibase$wait_for_migration_lock_to_be_cleared$fn__51781@2570df20: Database has migration lock; cannot run migrations. You can force-release these locks by running `java -jar metabase.jar migrate release-locks`.
2023-12-04 20:00:13,161 WARN util.jvm :: auto-retry metabase.db.liquibase$wait_for_migration_lock_to_be_cleared$fn__51781@2570df20: Database has migration lock; cannot run migrations. You can force-release these locks by running `java -jar metabase.jar migrate release-locks`.
2023-12-04 20:00:15,169 WARN util.jvm :: auto-retry metabase.db.liquibase$wait_for_migration_lock_to_be_cleared$fn__51781@2570df20: Database has migration lock; cannot run migrations. You can force-release these locks by running `java -jar metabase.jar migrate release-locks`.
2023-12-04 20:00:17,176 WARN util.jvm :: auto-retry metabase.db.liquibase$wait_for_migration_lock_to_be_cleared$fn__51781@2570df20: Database has migration lock; cannot run migrations. You can force-release these locks by running `java -jar metabase.jar migrate release-locks`.
2023-12-04 20:00:19,191 WARN util.jvm :: auto-retry metabase.db.liquibase$wait_for_migration_lock_to_be_cleared$fn__51781@2570df20: Database has migration lock; cannot run migrations. You can force-release these locks by running `java -jar metabase.jar migrate release-locks`.
2023-12-04 20:00:21,198 ERROR metabase.core :: Metabase Initialization FAILED
liquibase.exception.LockException: Database has migration lock; cannot run migrations. You can force-release these locks by running `java -jar metabase.jar migrate release-locks`.
	at metabase.db.liquibase$wait_for_migration_lock_to_be_cleared$fn__51781.invoke(liquibase.clj:139)
	at metabase.util.jvm$do_with_auto_retries.invokeStatic(jvm.clj:176)
	at metabase.util.jvm$do_with_auto_retries.invoke(jvm.clj:165)
	at metabase.util.jvm$do_with_auto_retries.invokeStatic(jvm.clj:183)
	at metabase.util.jvm$do_with_auto_retries.invoke(jvm.clj:165)
	at metabase.util.jvm$do_with_auto_retries.invokeStatic(jvm.clj:183)
	at metabase.util.jvm$do_with_auto_retries.invoke(jvm.clj:165)
	at metabase.util.jvm$do_with_auto_retries.invokeStatic(jvm.clj:183)
	at metabase.util.jvm$do_with_auto_retries.invoke(jvm.clj:165)
	at metabase.util.jvm$do_with_auto_retries.invokeStatic(jvm.clj:183)
	at metabase.util.jvm$do_with_auto_retries.invoke(jvm.clj:165)
	at metabase.util.jvm$do_with_auto_retries.invokeStatic(jvm.clj:183)
	at metabase.util.jvm$do_with_auto_retries.invoke(jvm.clj:165)
	at metabase.db.liquibase$wait_for_migration_lock_to_be_cleared.invokeStatic(liquibase.clj:134)
	at metabase.db.liquibase$wait_for_migration_lock_to_be_cleared.invoke(liquibase.clj:130)
	at metabase.db.liquibase$migrate_up_if_needed_BANG_.invokeStatic(liquibase.clj:150)
	at metabase.db.liquibase$migrate_up_if_needed_BANG_.invoke(liquibase.clj:144)
	at metabase.db.setup$fn__52148$migrate_BANG___52153$fn__52154$fn__52155.invoke(setup.clj:78)
	at metabase.db.liquibase$fn__51745$do_with_liquibase__51750$fn__51751.invoke(liquibase.clj:66)
	at metabase.db.liquibase$fn__51745$do_with_liquibase__51750.invoke(liquibase.clj:59)
	at metabase.db.setup$fn__52148$migrate_BANG___52153$fn__52154.invoke(setup.clj:73)
	at metabase.db.setup$fn__52148$migrate_BANG___52153.doInvoke(setup.clj:52)
	at clojure.lang.RestFn.invoke(RestFn.java:445)
	at metabase.db.setup$fn__52212$run_schema_migrations_BANG___52217$fn__52218.invoke(setup.clj:131)
	at metabase.db.setup$fn__52212$run_schema_migrations_BANG___52217.invoke(setup.clj:125)
	at metabase.db.setup$fn__52265$setup_db_BANG___52270$fn__52271$fn__52274$fn__52275.invoke(setup.clj:156)
	at metabase.util.jvm$do_with_us_locale.invokeStatic(jvm.clj:239)
	at metabase.util.jvm$do_with_us_locale.invoke(jvm.clj:225)
	at metabase.db.setup$fn__52265$setup_db_BANG___52270$fn__52271$fn__52274.invoke(setup.clj:152)
	at metabase.db.setup$fn__52265$setup_db_BANG___52270$fn__52271.invoke(setup.clj:151)
	at metabase.db.setup$fn__52265$setup_db_BANG___52270.invoke(setup.clj:145)
	at metabase.db$setup_db_BANG_$fn__52298.invoke(db.clj:69)
	at metabase.db$setup_db_BANG_.invokeStatic(db.clj:64)
	at metabase.db$setup_db_BANG_.invoke(db.clj:55)
	at metabase.core$init_BANG__STAR_.invokeStatic(core.clj:113)
	at metabase.core$init_BANG__STAR_.invoke(core.clj:99)
	at metabase.core$init_BANG_.invokeStatic(core.clj:159)
	at metabase.core$init_BANG_.invoke(core.clj:154)
	at metabase.core$start_normally.invokeStatic(core.clj:171)
	at metabase.core$start_normally.invoke(core.clj:165)
	at metabase.core$_main.invokeStatic(core.clj:204)
	at metabase.core$_main.doInvoke(core.clj:198)
	at clojure.lang.RestFn.invoke(RestFn.java:397)
	at clojure.lang.AFn.applyToHelper(AFn.java:152)
	at clojure.lang.RestFn.applyTo(RestFn.java:132)
	at clojure.lang.Var.applyTo(Var.java:705)
	at clojure.core$apply.invokeStatic(core.clj:667)
	at clojure.core$apply.invoke(core.clj:662)
	at metabase.bootstrap$_main.invokeStatic(bootstrap.clj:31)
	at metabase.bootstrap$_main.doInvoke(bootstrap.clj:28)
	at clojure.lang.RestFn.invoke(RestFn.java:397)
	at clojure.lang.AFn.applyToHelper(AFn.java:152)
	at clojure.lang.RestFn.applyTo(RestFn.java:132)
	at metabase.bootstrap.main(Unknown Source)
2023-12-04 20:00:21,211 INFO metabase.core :: Metabase Shutting Down ...
2023-12-04 20:00:21,215 INFO metabase.server :: Shutting Down Embedded Jetty Webserver
2023-12-04 20:00:21,225 INFO metabase.core :: Metabase Shutdown COMPLETE

Any idea please? Thanks!

Please follow what the log says and release the locks

Thank you, and really sorry I’m not sure how this can be done? I’ve tried to access the shell of the container but no luck.

you need to have a metabase jar on the server and then run "java -jar metabase.jar release-locks" while having the correct environment variables set up

I have followed the guidance to release the lock and restart my metabase jar, but it is getting locked again. I've tried this multiple times but it ends up with the getting the same lock.. I have reboot my server and restart nginx and upgrade metabase to the latest version but it is still having this lock. pls advise what to do

I followed the guidance from this ticket and have this issue resolved: Docker container fails with migration lock

The idea is to get into the application database to update a record. In my case of mysql as my application database, this is the line I use:

UPDATE DATABASECHANGELOGLOCK SET LOCKED=0, LOCKGRANTED=null, LOCKEDBY=null WHERE ID=1;