Error Migrating from H2 to Postgres

I am attempting to migrate from H2 to Postgres on my locally installed Metabase instance following the instructions here

I have followed through all the instructions and when I go to set my environment variables and run the following command:

java -jar metabase.jar load-from-h2 /path/to/metabase.db #using my own path to my .db file

I get the following error:

Command failed with exception: Wrong number of args (2) passed to: metabase.cmd/load-from-h2

I am literally just coping and pasting the commands and pasting them into my terminal, so I am not sure why I am encountering the error.

For reference, I am running:

  • Metabase v0.40.1
  • Java 11.0.7
  • Postgres 13.4.2
  • Windows 10 laptop

Hi @rossi45
You are encountering that error because you are "literally just coping and pasting the commands".
If you're in the same directory as both the JAR and the H2 database, then you can use this:

java -jar metabase.jar load-from-h2 metabase.db

Latest release is 0.40.5:

Thanks Flamber. I've updated my Metabase version to the latest. I do have the JAR and HR files in the same directory so I ran the command. I've been getting an different error now.

FATAL: database "metabase" does not exist

I am not sure if that means it can't find the metabase.db file (h2) or if it's looking for a a Postgres database called 'Metabase'?

Maybe i'll explain what I have done since I started the migration:

  1. Downloaded and installed Postgres onto my computer (just a windows 10 laptop)
  2. Created a .bat file contianing the following information:

set MB_DB_TYPE=postgres
set MB_DB_DBNAME=metabase
set MB_DB_PORT=5432
set MB_DB_USER= 'postgres username'
set MB_DB_PASS= 'postgres password'
set MB_DB_HOST=localhost
java -jar metabase.jar load-from-h2 metabase.db

  1. Ran the .bat file from my Metabase install location (i.e. C:\Program Files\Metabase)
  2. Error occured

I've read around to make sure my Postgres database is empty. It should be as all I did was download and install it. It's installed under C:\Program Files\PostgreSQL\13

I'm sure I'm doing something silly, but this would be my first crack at doing a migration. Do you see anything I am doing wrong?

Here's the full error message from the console:

Warning: environ value C:\Program Files\Java for key :java-home has been overwritten with C:\Program Files (x86)\Java\jre1.8.0_301
2021-10-04 10:58:13,637 INFO metabase.util :: Maximum memory available to JVM: 247.5 MB
2021-10-04 10:58:29,640 INFO util.encryption :: Saved credentials encryption is DISABLED for this Metabase instance.
For more information, see
2021-10-04 10:58:38,701 INFO metabase.core ::
Metabase v0.40.5 (042a36e release-x.40.x)

Copyright ⌐ 2021 Metabase, Inc.

Metabase Enterprise Edition extensions are NOT PRESENT.
2021-10-04 10:58:38,713 WARN metabase.core :: WARNING: You have enabled namespace tracing, which could log sensitive information like db passwords.
2021-10-04 10:58:38,777 INFO cmd.copy :: Set up h2 source database and run migrations...
2021-10-04 10:58:38,780 INFO db.setup :: Verifying h2 Database Connection ...
2021-10-04 10:58:39,229 INFO db.setup :: Successfully verified H2 1.4.197 (2018-03-18) application database connection.
2021-10-04 10:58:39,230 INFO db.setup :: Running Database Migrations...
2021-10-04 10:58:39,235 INFO db.setup :: Setting up Liquibase...
2021-10-04 10:58:39,282 INFO db.setup :: Liquibase is ready.
2021-10-04 10:58:39,283 INFO db.liquibase :: Checking if Database has unrun migrations...
2021-10-04 10:58:40,748 INFO db.setup :: Database Migrations Current ...
2021-10-04 10:58:40,749 INFO :: Running all necessary data migrations, this may take a minute.
2021-10-04 10:58:40,761 INFO :: Finished running data migrations.
Database setup took 2.0 s
2021-10-04 10:58:40,762 INFO cmd.copy :: [OK]
2021-10-04 10:58:40,763 INFO cmd.copy :: Set up postgres target database and run migrations...
2021-10-04 10:58:40,764 INFO db.setup :: Verifying postgres Database Connection ...
2021-10-04 10:58:41,046 ERROR cmd.copy :: [FAIL]

clojure.lang.ExceptionInfo: ERROR Set up postgres target database and run migrations... {}
at metabase.cmd.copy$do_step$fn__77871.invoke(copy.clj:33)
at metabase.cmd.copy$do_step.invokeStatic(copy.clj:29)
at metabase.cmd.copy$do_step.invoke(copy.clj:27)
at metabase.cmd.copy$fn__78032$copy_BANG___78037$fn__78038.invoke(copy.clj:268)
at metabase.cmd.copy$fn__78032$copy_BANG___78037.invoke(copy.clj:256)
at metabase.cmd.load_from_h2$load_from_h2_BANG_.invokeStatic(load_from_h2.clj:35)
at metabase.cmd.load_from_h2$load_from_h2_BANG_.invoke(load_from_h2.clj:25)
at clojure.lang.Var.invoke(
at metabase.cmd$load_from_h2.invokeStatic(cmd.clj:45)
at metabase.cmd$load_from_h2.invoke(cmd.clj:39)
at clojure.lang.AFn.applyToHelper(
at clojure.lang.AFn.applyTo(
at clojure.core$apply.invokeStatic(core.clj:665)
at clojure.core$apply.invoke(core.clj:660)
at metabase.cmd$run_cmd$fn__77589.invoke(cmd.clj:191)
at metabase.cmd$run_cmd.invokeStatic(cmd.clj:191)
at metabase.cmd$run_cmd.invoke(cmd.clj:187)
at clojure.lang.Var.invoke(
at metabase.core$run_cmd.invokeStatic(core.clj:141)
at metabase.core$run_cmd.invoke(core.clj:139)
at metabase.core$main.invokeStatic(core.clj:163)
at metabase.core$main.doInvoke(core.clj:158)
at clojure.lang.RestFn.applyTo(
at metabase.core.main(Unknown Source)
Caused by: clojure.lang.ExceptionInfo: Unable to connect to Metabase postgres DB. {}
at metabase.db.setup$fn__35708$verify_db_connection__35713$fn__35714$fn__35715.invoke(setup.clj:102)
at metabase.db.setup$fn__35708$verify_db_connection__35713$fn__35714.invoke(setup.clj:100)
at metabase.db.setup$fn__35708$verify_db_connection__35713.invoke(setup.clj:94)
at metabase.db.setup$setup_db_BANG
at metabase.util$do_with_us_locale.invokeStatic(util.clj:685)
at metabase.util$do_with_us_locale.invoke(util.clj:671)
at metabase.db.setup$setup_db_BANG
at metabase.db.setup$setup_db_BANG_.invokeStatic(setup.clj:140)
at metabase.db.setup$setup_db_BANG_.invoke(setup.clj:136)
at metabase.cmd.copy$fn__78032$copy_BANG___78037$fn__78038$fn__78041.invoke(copy.clj:270)
at metabase.cmd.copy$do_step$fn__77871.invoke(copy.clj:30)
... 23 more
Caused by: org.postgresql.util.PSQLException: FATAL: database "metabase" does not exist
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(
at org.postgresql.core.v3.QueryExecutorImpl.readStartupMessages(
at org.postgresql.core.v3.QueryExecutorImpl.(
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(
at org.postgresql.core.ConnectionFactory.openConnection(
at org.postgresql.jdbc.PgConnection.(
at org.postgresql.Driver.makeConnection(
at org.postgresql.Driver.connect(
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at metabase.driver.sql_jdbc.connection$can_connect_with_spec_QMARK_.invokeStatic(connection.clj:201)
at metabase.driver.sql_jdbc.connection$can_connect_with_spec_QMARK_.invoke(connection.clj:198)
at metabase.db.setup$fn__35708$verify_db_connection__35713$fn__35714$fn__35715.invoke(setup.clj:100)
... 33 more
Command failed with exception: ERROR Set up postgres target database and run migrations...

Hi! the error seems to be saying that there's no "metabase" database inside the postgreSQL server you are using. Try creating the database only so Metabase server can get into that database and create the table it needs

1 Like

Thanks @Luiggi that solved my problem!