Running Metabase using Java on Server 2019. Having issues converting from H2 app db to Postgres. Error references the file being locked.
Caused by: org.h2.jdbc.JdbcSQLNonTransientConnectionException: Database may be already in use: "C:/metabase/metabase.db.mv.db". Possible solutions: close all other connection(s); use the server mode [90020-214]
Caused by: org.h2.mvstore.MVStoreException: The file is locked: C:/metabase/metabase.db.mv.db [2.1.214/7]
Either Metabase is already running, the account you're using doesn't have rights to the file/folder, or the file/foldername is incorrect.
Thanks for the reply @AndrewMBaines,
I have adjusted my entry as follows:
java -DMB_DB_TYPE=Postgres -DMB_DB_CONNECTION_URI="jdbc:postgres://localhost:5432/metabaseappdb?user=&password=" -jar metabase.jar load-from-h2 metabase.db
Error: Caused by: java.lang.IllegalArgumentException: No method in multimethod 'env-defaults' for dispatch value: :Postgres
Use lower caps for the db type
Thanks @Luiggi ,
Changing from Postgres to postgres throws 10x the errors starting here.
2025-03-01 12:13:35,898 INFO db.setup :: Verifying postgres Database Connection ...
2025-03-01 12:14:06,047 ERROR cmd.copy :: [FAIL]
clojure.lang.ExceptionInfo: ERROR Set up postgres target database and run migrations...: Unable to connect to Metabase postgres DB. {}
That’s progress: your db parameters are wrong then
Help me understand what is incorrect, run in an admin cmd, from the folder containing metabase.db.mv.db.
java -DMB_DB_TYPE=postgres -DMB_DB_CONNECTION_URI="jdbc:postgres://localhost:5432/metabaseappdb?user=&password=" -jar metabase.jar load-from-h2 metabase.db
Double quotes on user and password is wrong
@Luiggi
Sorry, those were there to get the words to show up in the post. Just trying to show that I am using the metabase user and password in my string. I had it listed as MB User, with the greater than and less than characters and without the quotes, and it gets taken out of the post.
I would check if you can connect via a postgres client from the same container
Take a step back. Remove all references to migration and just try to start Metabase with a connection to an empty Postgres database.
That will confirm if the problem is connecting to Postgres.
Then try the migration.
This is one of the reasons I no longer start with H2. I just leap straight into Postgres.
I can connect to PostgreSQL via pgAdmin or cmd line with no issues using the same credentials I am using trying to migrate. I can create a new DB via both also with no issues. I am able to start Metabase via the cmd line and access the Metabase admin in a browser.
can you connect to postgres from your machine? or can you connect to postgres from inside the container? those are 2 different networking setups
I can connect to Postgres from the cmd line on the local machine. I do not have a container installed.
And you're running Metabase from a JAR in that same machine?
Yes, Metabase from a JAR on the same machine as PostgreSQL is installed. I can open Metabase in the webpage and see the databases.
can you try removing the "jdbc:" section there? I don't remember if that's fine
Here is the string with the JDBC: removed.
java -DMB_DB_TYPE=postgres -DMB_DB_CONNECTION_URI="postgres://localhost:5432/metabaseappdb?user=PG User&password=PG Password" -jar metabase.jar load-from-h2 metabase.db
Errors start here, JDBC error repeats about 40 times. I can post the full output if that would help.
2025-03-05 09:11:54,369 INFO db.setup :: Verifying postgres Database Connection ...
2025-03-05 09:11:54,414 WARN postgresql.Driver :: JDBC URL must contain a / at the end of the host or port: jdbc:postgresql://LQnt