SSH tunnel failure

I am using Metabase with a PostgreSQL database on a host that only allows local database access, but I can SSH to the database server. Before Metabase supported SSH tunnels natively, I would manually create one before launching Metabase. For example:

  1. Metabase running on data.example.com
  2. Postgresql running on remotehost.com:5432 (only allows connections from localhost)
  3. I run ssh william@remotehost.com -p 2234 -L 5432:127.0.0.1:5432 to open the tunnel
  4. I launch Metabase and configure a PostgreSQL database at localhost:5432
  5. Everything works great.

I am now trying to use Metabase's native SSH tunnel feature. I shut down my manual SSH tunnel and reconfigure the database like so:

  • Database type: PostgreSQL
  • Host: 127.0.0.1
  • Port: 5432
  • SSH tunnel host: remotehost.com
  • SSH tunnel port: 2234

All usernames and passwords are correct. When I try to save the database configuration, I get this error:

org.postgresql.util.PSQLException: Connection to remotehost.com:36683 refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

It seems like after creating the tunnel, Metabase is trying to open the connection to the remote host when it should be opening a local connection (that then gets forwarded through the tunnel). Am I configuring this wrong?

1 Like

@arthur Any ideas?

I observe here the with a MySQL database. I see the following error message:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

Which means essentially the same thing as you get with Postgresql. I see also in the log that a tunnel could be established:

creating ssh tunnel metabase@91.250.113.29:22 -L 46784:91.250.113.29:3306

1 Like

same issue, looks like its trying to connect direct to the postgres DB server address than localhost.

using docker, with following version:
Starting Metabase version v0.27.2 (35acf6e release-0.27.0)

Is there a previous version that we should downgrade to that worked?

I opened an issue for this.

1 Like

Could somebody please help us with a workaround?

I’m running metabase as docker image inside a Synology Disk Station.

I think I figured out how to set up a ssh tunnel on the host (Synology).
How do I get the metabase docker instance to use this ssh tunnel?

Or any other way to do this?

I just came across this in the Admin Guide: What if The Built in SSH Tunnels Don’t Fit My Needs?

See also https://github.com/metabase/metabase/issues/6114

1 Like