为了能够从另一台机器连接到我的postgresql数据库,我必须像这样配置我的postgresql.conf文件:
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '10.14.4.4' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
我尝试使用127.0.0.1但是没有用。也没有“localhost”。我能做的唯一方法就是使用服务器的实际IP地址。我检查以确保在我的“主机”文件中,localhost已定义....
在任何情况下,我现在都可以通过执行以下操作从其他服务器进行连接:
psql -U test test -h 10.14.4.4
但现在我注意到我无法使用以下语法登录本地:
psql -U test test -h 127.0.0.1
本地登录的唯一方法是
psql -U test test
我尝试将我的postgresql.conf文件更改为使用“*”...并且让我远程登录,但在本地,我仍然无法使用127.0.0.1或“localhost”进行连接。
如何设置此选项以便我的远程登录和本地登录都能正常工作?
感谢。
编辑1
这是我的pg_hba.conf文件的样子:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres trust
#host replication postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 trust
host all all 10.14.4.0/24 trust
host replication postgres 10.14.0.0/16 trust
答案 0 :(得分:1)
您需要修改pg_hba.conf文件,请参阅:http://www.postgresql.org/docs/8.2/static/auth-pg-hba-conf.html
答案 1 :(得分:1)
我必须编辑pg_hba.conf文件才能使用MD5,而不是信任。 这是最终文件的样子:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local replication postgres trust
#host replication postgres 127.0.0.1/32 trust
#host replication postgres ::1/128 trust
host all all 10.14.4.0/24 md5
host replication postgres 10.14.0.0/16 trust
现在我可以远程登录指定IP地址,并使用IP地址在本地登录。