H2 DB to PostgreSQL migration issues

Hello,

First of all, thanks for a great product! I have used to save all the settings and data in a H2 database file and now decided to migrate everything to PostgreSQL database.

First, I have downloaded last version of metabase (v0.16.1) and completed all the migrations pending on a H2 database file. After completing this step successfully I did shutdown metabase process and started migration process.
Next, I have created an empty database in postgres and configured ENV MB_DB_* variables accordingly.
Finally, I started migration with this command: “java -jar metabase.jar load-from-h2” and it was completed with all OK’s.

Now, I am trying to run metabase on a migratied postgresql database with all information transferred from H2 db file, but I have a lot of issues with it.

  1. This happen when I am trying to access any of my dashboards: 04-09 03:58:18 DEBUG metabase.middleware :: GET /api/dashboard/1 200 (9 ms) 04-09 03:58:18 WARN events.view-log :: Failed to process activity event. :dashboard-read #error { :cause ERROR: duplicate key value violates unique constraint "pk_view_log" Detail: Key (id)=(7) already exists. :via [{:type org.postgresql.util.PSQLException :message ERROR: duplicate key value violates unique constraint "pk_view_log" Detail: Key (id)=(7) already exists. :at [org.postgresql.core.v3.QueryExecutorImpl receiveErrorResponse QueryExecutorImpl.java 2198]}]
  2. While trying to access pulses: 04-09 03:59:44 WARN server.HttpChannel :: /api/pulse java.lang.ClassCastException: java.lang.Integer cannot be cast to clojure.lang.IPersistentMap
  3. While trying to access any of my saved questions: 04-09 04:00:23 DEBUG metabase.middleware :: GET /api/card/135 200 (4 ms) 04-09 04:00:23 WARN events.view-log :: Failed to process activity event. :card-read #error { :cause ERROR: duplicate key value violates unique constraint "pk_view_log" Detail: Key (id)=(8) already exists. :via [{:type org.postgresql.util.PSQLException :message ERROR: duplicate key value violates unique constraint "pk_view_log" Detail: Key (id)=(8) already exists. :at [org.postgresql.core.v3.QueryExecutorImpl receiveErrorResponse QueryExecutorImpl.java 2198]}] :trace
  4. Trying to run “SELECT 1” sql query manually: 04-09 04:00:57 DEBUG db.internal :: DB CALL: Database [:id :engine :details] (where (limit (select* ENTITY32256) 1) {:id database-id}) 04-09 04:00:57 DEBUG driver.generic-sql :: Creating new connection pool for database 14 ... 04-09 04:00:57 ERROR metabase.driver :: {:status :failed, :class java.lang.ClassCastException, :error "java.lang.ClassCastException", :stacktrace [], :query {:type "native", :native {:query "select 1"}, :constraints {:max-results 10000, :max-results-bare-rows 2000}}, :expanded-query nil} 04-09 04:00:57 ERROR metabase.driver :: Query failure: java.lang.ClassCastException 04-09 04:00:57 DEBUG common.internal :: ERROR: duplicate key value violates unique constraint "pk_query_queryexecution" Detail: Key (id)=(7) already exists.

Additionally I would like to mention that postgresql database was virgin clean before I have started migration via load-from-h2.
I was tried to run metabase on a clean postgresql database and it works okay: dashboards, pulses, questions, test manual query – everything works okay. So this is not server/database issue – something related to migration of data from H2.

Please advice!

Best Regards,
Max

Hello, Any updates on this?

Thank you!

Hi Max,

I’m going to spend a little time trying to reproduce this, but somehow it looks like the sequences in the postgres database you migrated to are not aligned properly with the actual values in the data. That’s why there are several errors of the kind ERROR: duplicate key value violates unique constraint where the application is trying to reuse an ID that’s already been used.

My main recommendation would be to try one more time on an empty postgres database and see if you get the same results. It’s important that the postgres database is completely empty (including no tables, etc) when you start the migration so that we can ensure everything is recreated in the proper order.