[Solved] Question about migrating from H2 to Postgres

Hello, how are you? I have a beginner question ...

How do I know if Metabase is using H2 or Postgres?

I installed Postgres and made the H2 bank migration command for it. I saw that the whole table structure was created in Postgres. The next day, when I started Metabase with the java -jar metabase.jar command, I saw that the H2 bank file was today's modified date. I closed everything and deleted the files from H2, and when I opened Metabase they were created again.

How do I know if my Metabase is using Postgres or H2?

Hi @juliozillo
You need to continue to set the environment variables when starting Metabase after you’ve migrated.
https://metabase.com/docs/latest/operations-guide/start.html#postgres
So on Windows, you would do something like:

java -DMB_DB_CONNECTION_URI="postgres://<hostname-or-ip>:<port>/<database>?user=<username>&password=<password>" -jar metabase.jar

Whenever I do a migration from H2, I move the old H2 files into a subfolder for backup. Then, if they’re recreated in the main folder, I know that the environment variables haven’t been set correctly.
You can also see what’s in use in the logs, but easier to just move the files.

Thanks for the reply :grinning: I will try it and after i post here if works.

Hi,

I came back to register that after your help I can always open my Metabase with Postgre database.

Now I created a script so that you don’t always have to type all the commands:

#! /bin/bash

cd /home/user_folder/metabase_jar_folder

export MB_DB_TYPE=postgres
export MB_DB_DBNAME=db_metabase
export MB_DB_PORT=5432
export MB_DB_USER=user
export MB_DB_PASS=password
export MB_DB_HOST=your_host

java -jar metabase.jar

You must give permissions to execute the script (only once):

chmod +x script.sh

Thank you!

1 Like