Postgresql Postgres JDBC客户端无法从套接字读取
我有一个PostGIS数据库和一个构建在HikariCP之上的客户端,用于从数据库读取数据。我的客户可以在某些机器上读取数据而不会出现任何问题。然而,在其他一些机器上,客户端被卡住,无法读取任何抛出套接字超时异常的数据Postgresql Postgres JDBC客户端无法从套接字读取,postgresql,jdbc,postgis,hikaricp,Postgresql,Jdbc,Postgis,Hikaricp,我有一个PostGIS数据库和一个构建在HikariCP之上的客户端,用于从数据库读取数据。我的客户可以在某些机器上读取数据而不会出现任何问题。然而,在其他一些机器上,客户端被卡住,无法读取任何抛出套接字超时异常的数据 MyClass:120 - Failed to execute HikariProxyPreparedStatement@2091541230 wrapping <my-query>. org.postgresql.util.PSQLException: An I/O
MyClass:120 - Failed to execute HikariProxyPreparedStatement@2091541230 wrapping <my-query>.
org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:332)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:118)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
...
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:140)
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:109)
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:67)
at org.postgresql.core.PGStream.receiveChar(PGStream.java:293)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1947)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306)
... 32 more
ProxyConnection:161 - HikariPool-1 - Connection org.postgresql.jdbc.PgConnection@1aafd32f marked as broken because of SQLSTATE(08006), ErrorCode(0)
org.postgresql.util.PSQLException: An I/O error occurred while sending to the backend.
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:332)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:441)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:365)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:155)
at org.postgresql.jdbc.PgPreparedStatement.executeQuery(PgPreparedStatement.java:118)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
...
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:140)
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:109)
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:67)
at org.postgresql.core.PGStream.receiveChar(PGStream.java:293)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1947)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:306)
... 31 more
版本
PostGIS jdbc:2.2.1 postgresql jdbc:9.4.1208.jre7
HikariCP:3.1.0
Postgres服务器:10.3
PostGIS服务器:2.4.4
若我不通过jdbc连接字符串设置socketTimeout,那个么连接将永远被卡住。一旦连接达到其最大使用寿命,它将被丢弃并重新连接。但是,它仍然无法读取数据。当我设置socketTimeout时,就会抛出异常
更新
如果未设置socketTimeout,则pg_stat_activity表中的连接行将具有以下值:state=idle in transaction、wait_event_type=Client和wait_event=clientrad
我的猜测是某种网络设置正在阻止客户端服务器的读取。如何进一步调试并找到根本原因 我们发现这是由数据库服务器的MTU设置引起的。默认情况下,MTU设置为9000,导致数据包丢失。将其更改为1500解决了问题。两端的网络跟踪应该会有所帮助。看起来客户端和服务器都在等待另一个。可能是防火墙删除了PostgreSQL server的响应。您可能想尝试使用较新版本的JDBC驱动程序,42.2.2是最新的驱动程序版本。@MarkrotVeel切换到42.2.2,但没有区别。
LOG: unexpected EOF on client connection with an open transaction
LOG: could not send data to client: Connection timed out
FATAL: connection to client lost