简体   繁体   English

PostgreSQL远程连接

[英]Postgresql Remote Connection

I'm stumped. 我很沮丧 We have a postgres 9.2 database that we have been using for some time. 我们有一个已经使用了一段时间的postgres 9.2数据库。 Now we have a need to be able to connect to it from outside our network. 现在,我们需要能够从网络外部连接到它。

So we setup an External IP, and tested that we can connect to port 5432 from the remote host via telnet. 因此,我们设置了一个外部IP,并测试了可以通过telnet从远程主机连接到端口5432。 So this proves that the network connection is working, firewalls, etc all good. 因此,这证明网络连接正常,防火墙等都正常。

When I try to connect using: 当我尝试使用以下方式进行连接时:
psql -h db.host.com -d dbname -p 5432 -U user psql -h db.host.com -d dbname -p 5432 -U用户

I get back psql: server closed the connection unexpectedly. 我回到psql:服务器意外关闭了连接。

I've verified that 我已经证实
listen_addresses = '*' is set in postgresql.conf 在postgresql.conf中设置了listen_addresses ='*'

And in pg_hba.conf we have a line that reads (just for testing) 在pg_hba.conf中,我们有一行读取内容(仅用于测试)
host all all 0.0.0.0/0 md5 托管所有0.0.0.0/0 md5

And I've reloaded the database to verify its picked up the changes. 而且我已经重新加载了数据库以验证其是否接受了更改。
So this should allow connections from any source. 因此,这应允许来自任何来源的连接。

The psql version on DB server is 9.2.14 and on client is 9.2.13. DB服务器上的psql版本是9.2.14,客户端上的是9.2.13。

Any suggestions or ideas? 有什么建议或想法吗?

I would try a few things to get some more information: 我将尝试一些事情以获取更多信息:

  • Tail the postgres log on the server to see what is going on there when you connect. 在服务器上尾注postgres日志,以查看连接时那里发生了什么。

  • Run psql --version to make sure it more or less matches the server version. 运行psql --version以确保它或多或少与服务器版本匹配。 (Ah I see you've already done this, but I'll leave it here for posterity.) (啊,我看到您已经完成了此操作,但我将其留在这里供后人参考。)

  • Run strace psql .... to see how far things get before the failure. 运行strace psql ....以查看故障发生前的工作。

This still sounds like a network issue to me. 在我看来,这仍然是网络问题。 What is the telnet command you're running? 您正在运行的telnet命令是什么? "External IP" sounds a bit like you're on AWS. “外部IP”听起来有点像您在AWS上。 Setting up remote access to a VPC takes a lot of steps. 设置对VPC的远程访问需要很多步骤。 Do you have any other services open that you can reach from the outside, that are actually working? 您是否还有其他可以打开的,可以正常使用的服务?

You could also do some troubleshooting by shutting down the Postgres server and using nc to listen on 5432 . 您也可以通过关闭Postgres服务器并使用nc侦听5432进行一些故障排除。 Then connect with telnet and see if you can send data back and forth. 然后连接telnet ,看看是否可以来回发送数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM