[英]Painfully slow connection speed from local machine to AWS RDS PostgreSQL database
I've looked everywhere for an answer to this problem.我到处寻找这个问题的答案。 I found a similar (unanswered) question on SO but not related to Java or SSL issues.
我在 SO 上发现了一个类似(未回答)的问题,但与 Java 或 SSL 问题无关。
Important Information:重要信息:
+ "?ssl=true"
parameter at the end of the connection string.+ "?ssl=true"
参数。 I suspect it has something to do with SSL but can't confirm it.我怀疑它与 SSL 有关,但无法确认。
This is my connection (pretty standard):这是我的连接(非常标准):
String dbUriString = ConfigUtils.getEnv("DATABASE_URL");
URI dbUri = new URI(dbUriString);
String username = dbUri.getUserInfo().split(":")[0];
String password = dbUri.getUserInfo().split(":")[1];
String dbUrl = "jdbc:postgresql://" + dbUri.getHost() + ':' + dbUri.getPort() + dbUri.getPath() + "?ssl=true";
ComboPooledDataSource datasource = new ComboPooledDataSource();
datasource.setUser(username);
datasource.setPassword(password);
datasource.setJdbcUrl(dbUrl);
datasource.setDriverClass("org.postgresql.Driver");
datasource.setMaxPoolSize(20);
datasource.setMinPoolSize(5);
datasource.setAcquireIncrement(1);
datasource.setAcquireRetryAttempts(3);
datasource.setInitialPoolSize(5);
datasource.setTestConnectionOnCheckout(true);
return datasource;
A little more information:更多信息:
Any help is deeply appreciated.任何帮助都深表感谢。
Connecting to our Postgres database on AWS took up to a minute or two to estabilish a connection, then it worked fine.连接到我们在 AWS 上的 Postgres 数据库需要一两分钟来建立连接,然后就可以正常工作了。
The reason turned out to be DNS resolution.原因竟然是 DNS 分辨率。
I ran telnet <database host> 5432
and discovered it was trying to connect to an IPv6 connection.我运行
telnet <database host> 5432
并发现它正在尝试连接到 IPv6 连接。 After a minute or so, it would time out and try the IPv4 connection, which worked instantly.大约一分钟后,它会超时并尝试 IPv4 连接,该连接立即生效。
Running dscacheutil -q host -a name <database host>
on my macOS machine indeed showed the database host was resolved to an IPv6 and IPv4 address.在我的 macOS 机器上运行
dscacheutil -q host -a name <database host>
确实显示数据库主机已解析为 IPv6 和 IPv4 地址。
I changed the DNS settings on my machine.我更改了我机器上的 DNS 设置。 Specifically, I told my VPN client to use Google's DNS servers for the amazonaws.com domain.
具体来说,我告诉我的 VPN 客户端将 Google 的 DNS 服务器用于 amazonaws.com 域。 After that, everything worked perfectly.
在那之后,一切都很完美。 Indeed, on rerunning
dscacheutil -q host -a name <database host>
, I only saw the IPv4 address this time.事实上,在重新运行
dscacheutil -q host -a name <database host>
时,我这次只看到了 IPv4 地址。
No idea by the IPv6 connection wasn't working, but the short of it was that DNS was part of the issue.不知道 IPv6 连接不起作用,但不足之处在于 DNS 是问题的一部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.