通过网络连接到 PostgreSQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4729663/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-20 00:30:11  来源:igfitidea点击:

connecting to PostgreSQL over a network

databasepostgresql

提问by Daniel Casserly

I have a pgsql server running on windows 7. I can remotely connect to it within the network using the computer name, so i know that there are no issues with config etc. I have disabled firewall. I have a static ip and have tried to connect to the database from another network but i get the error: server does not listen. What am i doing wrong? I know small amounts about ip addresses so any help will be appreciated. thanks in advance!

我有一个在 Windows 7 上运行的 pgsql 服务器。我可以使用计算机名称在网络内远程连接到它,所以我知道配置等没有问题。我禁用了防火墙。我有一个静态 ip,并试图从另一个网络连接到数据库,但我收到错误:服务器不监听。我究竟做错了什么?我对 ip 地址知之甚少,所以任何帮助将不胜感激。提前致谢!

EDIT: A little more information, i have set up a home network, i have two computers networked together that can both access the pgsql server that resides on one of the computers. I am based in the uk and get my internet from plusnet, config is all done on the thompson gateway. The third computer is a remote computer not on the same network, i was just testing to see whether or not i could "host" a pgsql database for several, not networked computers. Its more of a hobbiest thing really, although would be could if i could do it for work reasons too. Thanks for you help. (sorry if i sound dumb but this really isnt my subject-yet!)

编辑:多一点信息,我已经建立了一个家庭网络,我有两台联网的计算机,它们都可以访问驻留在其中一台计算机上的 pgsql 服务器。我在英国,从 plusnet 获得我的互联网,配置都是在 thompson 网关上完成的。第三台计算机是不在同一网络上的远程计算机,我只是在测试是否可以为几台未联网的计算机“托管”一个 pgsql 数据库。它更像是一件最有趣的事情,尽管如果我也出于工作原因也可以这样做。谢谢你的帮助。(对不起,如果我听起来很笨,但这真的不是我的主题 - 还!)

回答by Elijah Saounkine

Configure the pg_hba.conf file to add the line

配置 pg_hba.conf 文件添加行

host all all 192.168.0.1/24 trust

that IP 192.168.0.1 is just for the sake of example, you'll put there your IP then edit the postgresql.conf to reflect these settings

IP 192.168.0.1 只是为了举例,你将把你的 IP 放在那里,然后编辑 postgresql.conf 以反映这些设置

tcpip_socket = true 

i think this ^^ is only required for older versions, but add it there anyway

我认为只有旧版本才需要这个 ^^,但无论如何添加它

listen_addresses='*'

listen_addresses='*'

by default it's localhost, put * to listen to all addresses, or just your IP to tighten up the security

默认情况下它是本地主机,放 * 来监听所有地址,或者只是你的 IP 来加强安全性