无法连接到服务器上的Postgresql

在数字海洋我能够连接到Postgresql:

psql -d my_db -U my_name 

为此我要求一个密码,并且我成功地进入了。 但从我的本地计算机,我无法:

 psql -d my_db -U my_name -h xxxx 

什么也没有发生。 这是我的/etc/postgresql/9.4/main/pg_hba.conf

 # Database administrative login by Unix domain socket local all postgres peer # TYPE DATABASE USER ADDRESS METHOD # "local" is for Unix domain socket connections only local all all md5 # IPv4 local connections: host all all 0.0.0.0/0 md5 # IPv6 local connections: host all all ::1/128 md5 # Allow replication connections from localhost, by a user with the # replication privilege. #local replication postgres peer #host replication postgres 127.0.0.1/32 md5 #host replication postgres ::1/128 md5 

检查并确保postregsql监听你的接口IP(不仅仅是127.0.0.1)。

 ss -ltn 

如果没有,请将listen_addresses修改为*或您想要的IP。 这些设置应该位于postgresql.conf文件中,通常位于postgresql数据目录中。

https://www.postgresql.org/docs/9.4/static/runtime-config-connection.html