Cannot Connect to Postgres Database using Metabase on Docker (RHEL 8 Linux)

Here are some snips from my Docker logs that show the connection failures I’m geting.

sdavm05[419]$ sudo docker logs -f metabase

Warning: environ value jdk-11.0.8+10 for key :java-version has been overwritten with 11.0.8

09-02 17:33:04 INFO metabase.util :: Loading Metabase…

09-02 17:33:04 INFO metabase.util :: Maximum memory available to JVM: 15.7 GB

WARNING: not-empty already refers to: #'clojure.core/not-empty in namespace: metabase.mbql.schema, being replaced by: #'metabase.mbql.schema/not-empty

09-02 17:33:17 INFO util.encryption :: Saved credentials encryption is DISABLED for this Metabase instance. :unlock:

For more information, see https://metabase.com/docs/latest/operations-guide/encrypting-database-details-at-rest.html

09-02 17:33:23 WARN metabase.core :: WARNING: You have enabled namespace tracing, which could log sensitive information like db passwords.

09-02 17:33:23 INFO metabase.core :: Starting Metabase in STANDALONE mode

09-02 17:33:23 INFO metabase.server :: Launching Embedded Jetty Webserver with config:

{:port 3000, :host “0.0.0.0”}

09-02 17:33:24 INFO metabase.core :: Starting Metabase version v0.36.4 (196c1f6 release-0.36.x) …

09-02 17:33:24 INFO metabase.core :: System info:

{“file.encoding” “UTF-8”,

“java.runtime.name” “OpenJDK Runtime Environment”,

“java.runtime.version” “11.0.8+10”,

“java.vendor” “AdoptOpenJDK”,

“java.vendor.url” “https://adoptopenjdk.net/”,

“java.version” “11.0.8”,

“java.vm.name” “OpenJDK 64-Bit Server VM”,

“java.vm.version” “11.0.8+10”,

“os.name” “Linux”,

“os.version” “4.18.0-147.el8.x86_64”,

“user.language” “en”,

“user.timezone” “GMT”}

09-02 17:33:24 INFO metabase.plugins :: Loading plugins in /plugins…

09-02 17:33:37 INFO metabase.core :: Metabase Initialization COMPLETE

09-02 17:35:59 INFO middleware.misc :: Setting Metabase site URL to sdavm05.unx.sas.com:3000

09-02 17:35:59 INFO i18n.impl :: Reading available locales from locales.clj…

09-02 17:35:59 INFO middleware.exceptions :: Request canceled before finishing.

09-02 17:36:00 DEBUG middleware.log :: GET /api/user/current 401 3.8 ms (0 DB calls)

“Unauthenticated”

09-02 17:36:00 DEBUG middleware.log :: GET /api/session/properties 200 3.1 ms (0 DB calls) App DB connections: 0/10 Jetty threads: 7/50 (0 idle, 0 queued) (47 total active threads) Queries in flight: 0 (0 queued)

09-02 17:36:01 DEBUG middleware.log :: GET /api/session/properties 200 2.9 ms (0 DB calls) App DB connections: 0/10 Jetty threads: 6/50 (1 idle, 0 queued) (48 total active threads) Queries in flight: 0 (0 queued)

09-02 17:36:42 DEBUG middleware.log :: POST /api/util/password_check 200 1.8 ms (0 DB calls) App DB connections: 0/10 Jetty threads: 5/50 (1 idle, 0 queued) (48 total active threads) Queries in flight: 0 (0 queued)

09-02 17:37:07 DEBUG middleware.log :: POST /api/util/password_check 200 919.1 µs (0 DB calls) App DB connections: 0/10 Jetty threads: 5/50 (2 idle, 0 queued) (48 total active threads) Queries in flight: 0 (0 queued)

09-02 17:37:15 DEBUG middleware.log :: POST /api/util/password_check 200 1.0 ms (0 DB calls) App DB connections: 1/10 Jetty threads: 5/50 (2 idle, 0 queued) (48 total active threads) Queries in flight: 0 (0 queued)

09-02 17:37:57 INFO driver.impl :: Initializing driver :postgres…

09-02 17:38:02 ERROR driver.util :: Database connection error

java.util.concurrent.TimeoutException: Timed out after 5.0 s

In the Metabase setup screen, when I enter the connection values for my Postgres database, I always get this failure:

metabase_postgres_connection_failure

09-02 17:36:00 DEBUG middleware.log :: GET /api/session/properties 200 3.1 ms (0 DB calls) App DB connections: 0/10 Jetty threads: 7/50 (0 idle, 0 queued) (47 total active threads) Queries in flight: 0 (0 queued)

09-02 17:36:01 DEBUG middleware.log :: GET /api/session/properties 200 2.9 ms (0 DB calls) App DB connections: 0/10 Jetty threads: 6/50 (1 idle, 0 queued) (48 total active threads) Queries in flight: 0 (0 queued)

09-02 17:36:42 DEBUG middleware.log :: POST /api/util/password_check 200 1.8 ms (0 DB calls) App DB connections: 0/10 Jetty threads: 5/50 (1 idle, 0 queued) (48 total active threads) Queries in flight: 0 (0 queued)

09-02 17:37:07 DEBUG middleware.log :: POST /api/util/password_check 200 919.1 µs (0 DB calls) App DB connections: 0/10 Jetty threads: 5/50 (2 idle, 0 queued) (48 total active threads) Queries in flight: 0 (0 queued)

09-02 17:37:15 DEBUG middleware.log :: POST /api/util/password_check 200 1.0 ms (0 DB calls) App DB connections: 1/10 Jetty threads: 5/50 (2 idle, 0 queued) (48 total active threads) Queries in flight: 0 (0 queued)

09-02 17:37:57 INFO driver.impl :: Initializing driver :postgres…

09-02 17:38:02 ERROR driver.util :: Database connection error

java.util.concurrent.TimeoutException: Timed out after 5.0 s

I am able to connect to this database from the server that is running Metabase using Postgres PSQL.

Hi @sascjm
That is normally caused by incorrect host/port information, problems with DNS, firewall blocking or other network problems.
Make sure that the Metabase container has network access to the Postgres database.

Thank you flamber. I added the ip address of the Postgres server to the /etc/hosts file in the Docker container, then did a Docker commit but that did not fix the problem. I am very new to Docker so I don’t know exactly how to find my way around.

@sascjm Then you should try asking in a forum about Docker or perhaps stackoverflow.com since the problem is not specific to Metabase.
Otherwise don’t use Docker - Metabase is available in JAR: https://www.metabase.com/start/jar.html

I tried the Jar install and everything looked good until it got down to this point in the install. Once it displayed the Sending scheduled pulses, it stayed on this line for about 3 minutes and then got the Exception. Any ideas? Thanks again.

09-02 13:00:00 INFO task.send-pulses :: Sending scheduled pulses…

^CException in thread “Thread-10” org.h2.jdbc.JdbcSQLException: Database is already closed (to disable automatic closing at VM shutdown, add “;DB_CLOSE_ON_EXIT=FALSE” to the db URL) [90121-197]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:357)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.message.DbException.get(DbException.java:144)
at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1526)
at org.h2.jdbc.JdbcConnection.checkClosed(JdbcConnection.java:1502)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:302)
at com.mchange.v2.c3p0.impl.NewProxyConnection.prepareStatement(NewProxyConnection.java:387)
at clojure.java.jdbc$prepare_statement.invokeStatic(jdbc.clj:679)
at clojure.java.jdbc$prepare_statement.invoke(jdbc.clj:626)
at clojure.java.jdbc$db_query_with_resultset_STAR_.invokeStatic(jdbc.clj:1112)
at clojure.java.jdbc$db_query_with_resultset_STAR_.invoke(jdbc.clj:1093)
at clojure.java.jdbc$query.invokeStatic(jdbc.clj:1182)
at clojure.java.jdbc$query.invoke(jdbc.clj:1144)
at toucan.db$query.invokeStatic(db.clj:288)
at toucan.db$query.doInvoke(db.clj:284)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at toucan.db$simple_select.invokeStatic(db.clj:394)
at toucan.db$simple_select.invoke(db.clj:383)
at toucan.db$simple_select_one.invokeStatic(db.clj:420)
at toucan.db$simple_select_one.invoke(db.clj:409)
at toucan.db$select_one.invokeStatic(db.clj:627)
at toucan.db$select_one.doInvoke(db.clj:620)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core$apply.invokeStatic(core.clj:667)
at clojure.core$apply.invoke(core.clj:660)
at toucan.db$select_one_field.invokeStatic(db.clj:636)
at toucan.db$select_one_field.doInvoke(db.clj:629)
at clojure.lang.RestFn.invoke(RestFn.java:442)
at metabase.models.setting.cache$cache_out_of_date_QMARK_.invokeStatic(cache.clj:98)
at metabase.models.setting.cache$cache_out_of_date_QMARK_.invoke(cache.clj:79)
at metabase.models.setting.cache$restore_cache_if_needed_BANG_.invokeStatic(cache.clj:151)
at metabase.models.setting.cache$restore_cache_if_needed_BANG_.invoke(cache.clj:128)
at metabase.models.setting$db_or_cache_value.invokeStatic(setting.clj:175)
at metabase.models.setting$db_or_cache_value.invoke(setting.clj:169)
at metabase.models.setting$get_string.invokeStatic(setting.clj:188)
at metabase.models.setting$get_string.invoke(setting.clj:178)
at clojure.lang.Var.invoke(Var.java:384)
at metabase.util.i18n.impl$fn__7770$f__7771.invoke(impl.clj:156)
at metabase.util.i18n.impl$site_locale_from_setting.invokeStatic(impl.clj:163)
at metabase.util.i18n.impl$site_locale_from_setting.invoke(impl.clj:160)
at metabase.util.i18n$site_locale.invokeStatic(i18n.clj:31)
at metabase.util.i18n$site_locale.invoke(i18n.clj:28)
at metabase.util.i18n$translate_site_locale.invokeStatic(i18n.clj:52)
at metabase.util.i18n$translate_site_locale.doInvoke(i18n.clj:49)
at clojure.lang.RestFn.invoke(RestFn.java:410)
at clojure.lang.AFn.applyToHelper(AFn.java:154)
at clojure.lang.RestFn.applyTo(RestFn.java:132)
at clojure.core$apply.invokeStatic(core.clj:667)
at clojure.core$apply.invoke(core.clj:660)
at metabase.util.i18n.SiteLocalizedString.toString(i18n.clj:75)
at clojure.core$str.invokeStatic(core.clj:553)
at clojure.core$str.invoke(core.clj:544)
at metabase.core$destroy_BANG_.invokeStatic(core.clj:47)
at metabase.core$destroy_BANG_.invoke(core.clj:44)
at clojure.lang.AFn.run(AFn.java:22)
at java.lang.Thread.run(Thread.java:748)

@sascjm Do not use H2 in production:
https://www.metabase.com/docs/latest/operations-guide/migrating-from-h2.html

Hi @flamber: I have been able to get my Metabase running on Docker, however I am having a problem with the firewall. I’m on RHEL 8. If I have firewalld running, I cannot connect to my Postgres database through Metabase. If I disable the firewalld, I can connect to Postgres through Metabase just fine and visualize my data there. I have tried many other ways of accessing my Postgres database from the server where Metabase is installed on Docker (psql and ncat) and they all work just fine. Its just Metabase that cannot connect.

@sascjm Okay, I would recommend that you try figuring out the solution in a forum related to Docker or RHEL, or perhaps stackoverflow.com can be of help, since the problem is not with Metabase.

I was just able to setup the firewall to work with Metabase with the below settings. Thank you @flamber for your help to lead me in the direction of the resolution. I appreciate it very much.

$ sudo firewall-cmd --permanent --zone=trusted --change-interface=docker0
success

$ sudo firewall-cmd --reload
success

]$ sudo systemctl restart docker

1 Like