postgresql Postgres 服务器不听
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31091748/
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
Postgres server not listening
提问by Pablo Pardo
I'm trying to connect with my client (Macbook Pro) to a Postgres Database located in another PC in the same network (Ubuntu) I can see the database from the host with pgAdmin, connecting to localhost, but I can't see from the client.
我正在尝试将我的客户端 (Macbook Pro) 连接到位于同一网络 (Ubuntu) 中另一台 PC 中的 Postgres 数据库,我可以使用 pgAdmin 从主机看到数据库,连接到 localhost,但我看不到客户端。
I've allowed all the connections in pg_hba.conf
and postgresql.conf
我已经允许所有的连接pg_hba.conf
和postgresql.conf
I'm trying to connect from the client through pgAdmin to the IP server where the database is stored (192.168.1.34) and port 5432
我正在尝试通过 pgAdmin 从客户端连接到存储数据库的 IP 服务器 (192.168.1.34) 和端口 5432
And I get this error
What do I'm doing wrong?
我得到这个错误
我做错了什么?
Am I missing something
我是不是错过了什么
After reading suggestions, I can say: On the ubuntu machine (home test server) I have no firewall. Postgres is running.
阅读建议后,我可以说:在ubuntu机器(家庭测试服务器)上我没有防火墙。Postgres 正在运行。
I've tried from the ubuntu console to access to the database:
psql -h 127.0.0.1 mydatabase postgres
and can connect (which means that the server is running and username is ok)
But if I try to access the same database, from the same machine, changing localhost with the IP, I can not connect.
Should not be psql -h 127.0.0.1 mydatabase postgres
the same as psql -h 192.168.1.34 mydatabase postgres
when I connect from the server?
我已经尝试从 ubuntu 控制台访问数据库:
psql -h 127.0.0.1 mydatabase postgres
并且可以连接(这意味着服务器正在运行并且用户名正常)但是如果我尝试从同一台机器访问同一个数据库,使用 IP 更改 localhost ,我无法连接。应该不会psql -h 127.0.0.1 mydatabase postgres
和psql -h 192.168.1.34 mydatabase postgres
我从服务器连接的时候一样吧?
Maybe is in loopback, as Alain suggested?
也许是在环回中,正如阿兰建议的那样?
回答by Alain O'Dea
It's not connecting so it's likely not listening on the right interface or is blocked by the firewall.
它没有连接,所以它可能没有在正确的接口上侦听或被防火墙阻止。
Is postgres running?
postgres 正在运行吗?
sudo service postgresql status
Is postgres listening on tcp/5432 on your LAN IP or 0.0.0.0 (all interfaces)?
postgres 是否在您的 LAN IP 或 0.0.0.0(所有接口)上侦听 tcp/5432?
netstat -anpt | grep LISTEN
It could be listening on 127.0.0.1 (loopback) only which means it can't be reached from the Mac.
它只能在 127.0.0.1(环回)上侦听,这意味着无法从 Mac 访问它。
If it's not listening or is on loopback check postgresql.conf for listen_addresses:
如果它没有监听或在环回检查 postgresql.conf 中的 listen_addresses:
http://www.postgresql.org/docs/9.1/static/runtime-config-connection.html
http://www.postgresql.org/docs/9.1/static/runtime-config-connection.html
Is there a firewall running on the Ubuntu box?
Ubuntu 机器上是否运行了防火墙?
Make sure to allow inbound connections to tcp/5432 from the Mac's IP at minimum.
确保至少允许从 Mac 的 IP 到 tcp/5432 的入站连接。
GUFW makes this easier to configure, but it can be done with iptables as well.
GUFW 使这更容易配置,但也可以使用 iptables 来完成。
Further reference for the Ubuntu setup:
Ubuntu 设置的进一步参考:
回答by Danish Khakwani
You have probably configured following two files
您可能已经配置了以下两个文件
pg_hba.conf:
pg_hba.conf:
host all all 0.0.0.0/0 md5
postgresql.conf
配置文件
listen_addresses='*'
You have to check if the port 5432 is open: http://www.yougetsignal.com/tools/open-ports/
您必须检查端口 5432 是否打开:http: //www.yougetsignal.com/tools/open-ports/
If it's not then add a rule to your iptables:
如果不是,则向您的 iptables 添加规则:
iptables -A INPUT -s 0/0 -p tcp --dport 5432 -j ACCEPT
0/0: If you want anybody to access it.
You can change it to a specific ip address or range of ip addresses.
0/0:如果你想让任何人访问它。
您可以将其更改为特定的 IP 地址或 IP 地址范围。
回答by Dimitris Kougioumtzis
In ubuntu 17.04 default port is 5433 check file postgresql.conf in path /etc/postgresql/9.6/main
在 ubuntu 17.04 默认端口是 5433 检查路径 /etc/postgresql/9.6/main 中的 postgresql.conf 文件
回答by Shalauddin Ahamad Shuza
You have allow postgresql to accept request from outside network. To do that you have to change two files located at /etc/postgresql/{version_code}/main
First one is pg_hba.conf
, open and
您已允许 postgresql 接受来自外部网络的请求。为此,您必须更改位于/etc/postgresql/{version_code}/main
第一个是的两个文件pg_hba.conf
,打开和
change host all all ::1/128 md5
to host all all 0.0.0.0/0 md5
更改host all all ::1/128 md5
为 host all all 0.0.0.0/0 md5
Second one is postgresql.conf
, open and
第二个是postgresql.conf
,打开和
change listen_address = 'localhost'
to listen_address = '*'
更改listen_address = 'localhost'
为 listen_address = '*'
Now restart the postgre server.
现在重新启动 postgre 服务器。