与 PostgreSQL 数据库的 Talend 连接失败

Talend Connection to PostgreSQL Database fails

我正在尝试使用 Talend Open Studio for Big Data v7.3.1 连接到位于远程服务器中的 PostgreSQL 数据库 问题是服务器需要 SSL 证书。我尝试了很多方法,但仍然失败。 这是我尝试过的连接字符串和 TOS BD

中的日志错误

1)禁用ssl模式jdbc:postgresql://xx.xx.xx.xx:5432/dbName?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory&sslmode=disable

Exception in component tDBConnection_1 (DB_Connection)
org.postgresql.util.PSQLException: FATAL: pg_hba.conf rejects connection for host "my.ip.address.here", user "user", database "databasename", SSL off

2)不指定ssl模式(表示采用默认模式)jdbc:postgresql://xx.xx.xx.xx:5432/dbName?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory

org.postgresql.ssl.PGjdbcHostnameVerifier verify
GRAVE: Server name validation failed: hostname xx.xx.xx.xx does not match common name xxxxx
Exception in component tDBConnection_1 (DB_Connection)
org.postgresql.util.PSQLException: The hostname xx.xx.xx.xx could not be verified by 
hostnameverifier PgjdbcHostnameVerifier

3) 如果我在这样的连接中省略 SSL 参数部分 jdbc:postgresql://xx.xx.xx.xx:5432/dbName? 它会询问以获得有效的客户端证书。

注意:我可以使用 pgadmin 连接到数据库问题是 Talend open Studio

解决方案是将证书位置放在指定 ssl 模式的连接字符串中:

ssl=true&sslmode=prefer&sslcert=DirectoryToSslCertificates/client.crt&sslkey=DirectoryToSslCertificates/clientkey.pk8&sslrootcert=DirectoryToSslCertificates/root.crt

(不要忘记用 openssl 命令更改证书格式,我有 .pem 文件)