The metabase.jar binary, on CLI, refers to H2 despite of postgres connection in .env file

We have a Metabase instance configured to use PostgreSQL as its application database, and the metabase.env file contains the connection details as Linux environment variables. However, when calling the metabase.jar binary on CLI, e.g., by command java -jar metabase.jar version, it always refers to the default H2 database.

We wonder if there is a command-line option to let the binary run with configurations in the metabase.env file.

We are new to this part of Metabase usage, so we highly appreciate any hints and suggestions.

The screenshot of command-line call:

[root@metabasev metabase]# java -jar metabase.jar version
2024-06-12 14:41:41,547 INFO metabase.util :: Maximum memory available to JVM: 916.4 MB
2024-06-12 14:41:45,626 INFO util.encryption :: Saved credentials encryption is DISABLED for this Metabase instance. 🔓
 For more information, see https://metabase.com/docs/latest/operations-guide/encrypting-database-details-at-rest.html
2024-06-12 14:41:46,813 WARN db.env :: WARNING: Using Metabase with an H2 application database is not recommended for production deployments. For production deployments, we highly recommend using Postgres, MySQL, or MariaDB instead. If you decide to continue to use H2, please be sure to back up the database file regularly. For more information, see https://metabase.com/docs/latest/operations-guide/migrating-from-h2.html
2024-06-12 14:41:53,279 INFO driver.impl :: Registered abstract driver :sql  🚚
2024-06-12 14:41:53,290 INFO driver.impl :: Registered abstract driver :sql-jdbc (parents: [:sql]) 🚚
2024-06-12 14:41:53,296 INFO metabase.util :: Load driver :sql-jdbc took 62.9 ms
2024-06-12 14:41:53,296 INFO driver.impl :: Registered driver :h2 (parents: [:sql-jdbc]) 🚚
2024-06-12 14:41:53,502 INFO driver.impl :: Registered driver :mysql (parents: [:sql-jdbc]) 🚚
2024-06-12 14:41:53,531 INFO driver.impl :: Registered driver :postgres (parents: [:sql-jdbc]) 🚚
2024-06-12 14:41:57,472 INFO metabase.core ::
Metabase v1.50.0 (4fe42d3)

Copyright © 2024 Metabase, Inc.

Metabase Enterprise Edition extensions are PRESENT.

Usage of Metabase Enterprise Edition features are subject to the Metabase Commercial License.See https://www.metabase.com/license/commercial/ for details.
Metabase version: {:date 2024-06-10, :tag v1.50.0, :hash 4fe42d3}

OS: Linux 3.10.0-1160.108.1.el7.x86_64 amd64

Java version: OpenJDK 64-Bit Server VM 11.0.23

Country: US
System timezone: America/Edmonton
Language: en
File encoding: UTF-8
[root@metabasev metabase]#

.env files are files that can be called from the code or from a container orchestrator. I would suggest you set the values in the env file as environment variables in the server rather than on a file.

BTW: are you a paid customer or trialing Metabase? if so, you have priority support via email and we can help you on this matter

1 Like

Yes, @Luiggi, we made it work following your advice.

To make it work as Linux environment variables, we need to call the command export, e.g., export MB_DB_TYPE="postgres", and we will call source on the script file. On the other hand, the original metabase.env contains items without export, like MB_DB_TYPE="postgres". See more details in the screenshot below.

Also, we are trying to get familiar with the system before proceeding to a trial of the PRO version. In this case, not sure if we have the priority support.

Again, thank you so much for your prompt help.

Screenshot of command-line testing:

[root@metabasev metabase]# cat metabase.env.export
export MB_DB_TYPE="postgres"
export MB_DB_DBNAME="Metabasev"
export MB_DB_PORT=5432
export MB_DB_USER="metabasev_user"
export MB_DB_PASS="metabasev_user"
export MB_DB_HOST="localhost"
# MB_DB_CONNECTION_URI="postgres://$MB_DB_HOST:$MB_DB_PORT/$MB_DB_DBNAME?user=$MB_DB_USER&password=$MB_DB_PASS&prepareThreshold=0"

[root@metabasev metabase]# source metabase.env.export
[root@metabasev metabase]# java -jar metabase.jar version
2024-06-13 15:29:30,889 INFO metabase.util :: Maximum memory available to JVM: 916.4 MB
2024-06-13 15:29:34,266 INFO util.encryption :: Saved credentials encryption is DISABLED for this Metabase instance. 🔓
 For more information, see https://metabase.com/docs/latest/operations-guide/encrypting-database-details-at-rest.html
2024-06-13 15:29:40,377 INFO driver.impl :: Registered abstract driver :sql  🚚
2024-06-13 15:29:40,382 INFO driver.impl :: Registered abstract driver :sql-jdbc (parents: [:sql]) 🚚
2024-06-13 15:29:40,388 INFO metabase.util :: Load driver :sql-jdbc took 44.6 ms
2024-06-13 15:29:40,388 INFO driver.impl :: Registered driver :h2 (parents: [:sql-jdbc]) 🚚
2024-06-13 15:29:40,593 INFO driver.impl :: Registered driver :mysql (parents: [:sql-jdbc]) 🚚
2024-06-13 15:29:40,652 INFO driver.impl :: Registered driver :postgres (parents: [:sql-jdbc]) 🚚
2024-06-13 15:29:44,761 INFO metabase.core ::
Metabase v1.50.0 (4fe42d3)

Copyright © 2024 Metabase, Inc.

Metabase Enterprise Edition extensions are PRESENT.

Usage of Metabase Enterprise Edition features are subject to the Metabase Commercial License.See https://www.metabase.com/license/commercial/ for details.
Metabase version: {:date 2024-06-10, :tag v1.50.0, :hash 4fe42d3}

OS: Linux 3.10.0-1160.108.1.el7.x86_64 amd64

Java version: OpenJDK 64-Bit Server VM 11.0.23

Country: US
System timezone: America/Edmonton
Language: en
File encoding: UTF-8
[root@metabasev metabase]#