JDBC Error: Cannot connect: connection refused: ... The connection attempt failed

  • 4 November 2020
  • 0 replies
  • 412 views

Userlevel 3

This database connection error is often difficult to troubleshoot, given how non-descriptive and vague it is. Generally, this specific error is almost always caused by networking issues. The key to troubleshooting is determining what part of the network is causing the problem:  

  1. Verify the database credentials: Try connecting to the database with the same credentials specified in the Looker connection settings, from a different application. Note: The database may say “invalid credentials” for the first few attempts - be sure to try multiple times.
     

  2. Verify the host URL, port, and database name: If you are able to connect to the database with the same credentials, next compare the connection’s settings in Looker with the connection details of the application that could successfully connect.
     

  3. Test the connectivity between the Looker client and the database host: The steps for this will vary depending on your infrastructure. If you are using an SSH tunnel or other proxy, follow the first two points below; if you are not using an SSH tunnel or other proxy, skip to the last point.

    • SSH from Looker host to the tunnel server (for example: ssh -v -i ~/.ssh/key_name looker_user_name@tunnel_host_address)

    • Telnet from the tunnel server to the database host (for example: telnet db_host_address port)

    • Telnet from the Looker host to the database host directly (if not using an SSH tunnel or other proxy).

The step that fails in step 3 will determine the next troubleshooting steps. If the first point fails, then there may be a problem with the tunnel configuration in Looker, or the configuration of the tunnel server. If the second or third points fail, then there is a problem with the configuration of the database host. 

There are two common configuration problems:

  • Ports: The database port is not open on the database side. 

  • IP Allowlist: The Looker Server's IPs are not allow-listed on the database host, or not allow-listed for the correct type of traffic. If you are using an SSH tunnel, the tunnel host's IPs are incorrectly allow-listed. Synonym: Security Groups

If you host your own Looker instance, either of the above could also be true on the Looker host.

In the case none of the troubleshooting steps above resolve the error, it can also be helpful to move forward with troubleshooting step 4:

  1. Database connection logs. Databases often keep internal logs of connection attempts to the database. Where the logs are kept, what they track, and how to enable connection logging are often dialect specific. However, as an example, in MySQL the instructions here would have connection attempts added to MySQL’s error log. What can this tell us? Some examples:

    1. If nothing shows up in error logs, that means we are not reaching the database at all.

    2. If something shows up, there should be a more descriptive error message that will illuminate what's wrong.


0 replies

Be the first to reply!

Reply