Help Center/ GaussDB(DWS)/ Troubleshooting/ JDBC/ODBC/ Database Connection Fails
Updated on 2024-01-25 GMT+08:00

Database Connection Fails

Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

Possible cause: The network between the client and server is disconnected, the port is incorrect, or the CN to be connected is abnormal.

Solution:
  • On the client, ping the IP address of the server to check whether the network connection is normal. If the network connection is abnormal, rectify the network fault.
  • Check whether the port for connecting to the CN in the URL is correct. If the port is incorrect, correct it (the default port is 8000).

FATAL: Invalid username/password,login denied.

Possible cause: The username or password is incorrect.

Solution: Use the correct database username and password.

No suitable driver found for XXXX

Possible cause: The format of the URL used for establishing the JDBC connection is wrong.

Solution: Correct the URL format.
  • The URL format of gsjdbc4.jar is jdbc:postgresql://host:port/database.
    • The version is 8.1.x when the pom dependency is used.
  • The URL format of gsjdbc200.jar is jdbc:gaussdb://host:port/database.
    • The version is 8.1.x-200 when the pom dependency is used.

conflict

Possible cause: The JDBC JAR package conflicts with an application. For example, JDBC and an application have classes with the same path and name.

  • gsjdbc4.jar conflicts with the open-source postgresql.jar because they have the same class name.
  • gsjdbc4.jar included other tools, such as fastjson, required for IAM features. This tool conflicts with fastjson in an application.

Solution:

  • For the open-source postgresql.jar file, use gsjdbc200.jar instead and use different URL format and driver path. Change the driver name from org.postgresql.Driver to com.huawei.gauss200.jdbc.Driver, and change the URL format from org:postgresql://host:port/database to jdbc:gaussdb://host:port/database.
  • If the JAR package introduced by JDBC conflicts with that introduced by an application, use the shade of Maven to modify the class path in the JAR package.
  • Check whether the JDBC driver is gsjdbc4.jar or gsjdbc200.jar. If gsjdbc4.jar is used, replace it with gsjdbc200.jar and try to establish a connection.

    For the pom dependency, replace the 8.1.x version with the 8.1.x-200 version.

org.postgresql.util.PSQLException: FATAL: terminating connection due to administrator command Session unused timeout

Possible cause: The connection is disconnected due to session timeout.

Solution: Check the timeout configuration on the CN and the JDBC client. Increase the timeout interval or disable the timeout configuration.

  1. Check the CN logs where the error is reported. If the log contains session unused timeout, there is session timeout.

    Solution:

    1. Log in to the DWS console and click the name of the target cluster.
    2. On the displayed page, click the Parameters tab and search for session_timeout to view the timeout interval.
    3. Set the values of session_timeout on CNs and DNs to 0. For details, see Modifying Database Parameter"Modifying Database Parameters" in the GaussDB(DWS) User Guide.

Connection refused: connect.

Possible cause: The default driver of the third-party tool is incompatible.

Solution: Replace the JDBC driver package and check whether the connection is normal.

Connections could not be acquired from the underlying database!

Possible causes:

  • The driver setting is incorrect.
  • The database connection address is correct.
  • The password or account is incorrect.
  • The database is not started or you do not have the permission to access the database.
  • The required driver JAR package is not imported to the project.

Solution:

  • Check the driver configuration and correct it.
    • gsjdbc4.jar driver=org.postgresql.Driver
    • gsjdbc200.jar driver=com.huawei.gauss200.jdbc.Driver
  • Check the database connection address and correct it.
    • For gsjdbc4.jar, the format is jdbc:postgresql://host:port/database.
    • For gsjdbc200.jar, the format is jdbc:gaussdb://host:port/database.
  • Use the correct database username and password.
  • Check whether the database is started or the access permission has been obtained.
  • Check whether the used JDBC driver is gsjdbc4.jar or gsjdbc200.jar. Use the correct JDBC driver JAR package.

    • gsjdbc4.jar: The gsjdbc4.jar driver package is compatible with PostgreSQL. Its class names and class structures are the same as those of the PostgreSQL driver. PostgreSQL applications can be directly migrated to the current system.
    • gsjdbc200.jar: If a JVM process needs to access PostgreSQL and GaussDB(DWS) at the same time, this driver package must be used. In this package, the main class name is com.huawei.gauss200.jdbc.Driver (replace org.postgresql with com.huawei.gauss200.jdbc). The URL prefix of the database connection is jdbc:gaussdb. Other parameters are the same as those of gsjdbc4.jar.

The JDBC DEV environment is normal. The test environment cannot be connected and a null pointer error or a URI error "uri is not hierarchical" is reported.

Problem analysis: Some virtual environments do not support the function of obtaining extended parameters. Therefore, you need to disable the function

Solution: Add connection configuration connectionExtraInfo=false. For details, seeUsing a JDBC Driver to Connect to a DatabaseUsing a JDBC Driver to Connect to a Database.

1
jdbc:postgresql://host:port/database?connectionExtraInfo=false

An error is reported when the open-source JDBC SSL mode is used to connect to DWS

Possible cause: SSL full verification is not enabled to check whether the URL is completely matched when the open-source JDBC is used.

Solution: Add sslmode=require for the open-source connection.

1
jdbc:postgresql://host:port/database?sslmode=require

Connection cannot be converted to BaseConnection when the connection pool is used to obtain connections in the CopyManager scenario

Possible cause: BaseConnection is a non-public class. The connection pool object needs to be unwrapped to obtain the original PGConnection.

Solution: Unwrap the object and return the original object to allow access to non-public methods.

1
2
3
4
5
// Unwrap
PGConnection unwrap = connection.unwrap(PGConnection.class);
// Convert
BaseConnection baseConnection = (BaseConnection)unwrap;
CopyManager copyManager = new CopyManager(baseConnection);