postgresql 使用 psql 命令远程连接到 Postgres 实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32824388/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remotely connecting to Postgres instance using psql command
提问by Hardik Kamdar
I want to remotely connect to a Postgres instance. I know we can do this using the psql command passing the hostname
我想远程连接到 Postgres 实例。我知道我们可以使用传递主机名的 psql 命令来做到这一点
I tried the following:
我尝试了以下方法:
psql -U postgres -p 5432 -h hostname
I modified the /etc/postgresql/9.3/main/pg_hba.conf file on the target machine to allow remote connections by default
我修改了目标机器上的/etc/postgresql/9.3/main/pg_hba.conf文件,默认允许远程连接
I added the following line to the file
我将以下行添加到文件中
host all all source_ip/32 trust
I restarted the cluster using
我使用重新启动了集群
pg_ctlcluster 9.2 mycluster stop
pg_ctlcluster 9.2 mycluster start
However, when I try to connect from the source_ip, I still get the error
但是,当我尝试从 source_ip 连接时,我仍然收到错误
Is the server running on host "" and accepting TCP/IP connections on port 5432?
服务器是否在主机“”上运行并接受端口 5432 上的 TCP/IP 连接?
What am I doing wrong here?
我在这里做错了什么?
采纳答案by Hardik Kamdar
I figured it out.
我想到了。
Had to set listen_addresses='*'
in postgresql.conf
to allow for incoming connections from any ip / all ip
必须设置listen_addresses='*'
在postgresql.conf
允许从任何IP传入的连接/全IP