我使用TCP连接到远程PostgreSQL:
DriverManager.getConnection("jdbc:postgresql://remotehost.com/test_psql", "admin", "password");
它成功地工作了。
但是我不能使用UNIX套接字连接
我添加到pom依赖项:
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>no.fiken.oss.junixsocket</groupId>
<artifactId>junixsocket-common</artifactId>
<version>1.0.2</version>
</dependency>
并将网址更改为:
jdbc:postgresql:test_psql?socketFactory=org.newsclub.net.unix.socketfactory.PostgresqlAFUNIXSocketFactory&socketFactoryArg" +
"=/var/run/postgresql/.s.PGSQL.5432
我现在收到堆栈:
org.newsclub.net.unix.AFUNIXSocketException: No such file or directory (socket: /run/postgresql/.s.PGSQL.5432)
但是这个目录和文件是存在的。因为当我运行"netstat -nlp |grep 5432',我收到:
tcp 0 0 0.0.0.0:5432 0.0.0.0:*
LISTEN 14174/postgres
tcp6 0 0 :::54320 :::*
LISTEN 15824/docker-proxy
tcp6 0 0 :::5432 :::*
LISTEN 14174/postgres
unix 2 [ ACC ] STREAM LISTENING 1260991417
14174/postgres /var/run/postgresql/.s.PGSQL.5432
但是,上表中的 5432 标记为红色。
异常提到了socket: /run/postgresql/.s.PGSQL.5432
(不是/var/run/postgresql/.s.PGSQL.5432(,所以也许存在与该字符串中的&
字符相关的命令行解析问题?
但也许/var/run
是指向/run
的符号链接。您可以通过其他方式访问/run/postgresql/.s.PGSQL.5432
吗?
由于no.fiken.oss.junixsocket
变体是 junixsocket 的一个相当古老的分支,因此也请使用最新的原始 junixsocket 2.5.2 重试。
有关使用的详细信息,请参阅此处:https://kohlschutter.github.io/junixsocket/dependency.html