我在 Digital Ocean 的 ubuntu 18 主机上运行 postgresql 10。
这是我的 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 peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
local all postgres peer
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all peer
# IPv4 local connections:
host all all 127.0.0.1/32 md5
host all all 0.0.0.0/0 md5
#host all postgres 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
host all all 0.0.0.0/0 md5
这是重启后的日志文件
2019-09-06 02:49:05.213 UTC [3334] LOG: database system is ready to accept connections
2019-09-06 02:49:05.743 UTC [3342] [unknown]@[unknown] LOG: incomplete startup packet
2019-09-06 02:49:17.164 UTC [3367] postgres@postgres FATAL: pg_hba.conf rejects connection for host "192.X.X.2", user "postgres", database "postgres", SSL on
2019-09-06 02:49:17.232 UTC [3368] postgres@postgres FATAL: pg_hba.conf rejects connection for host "192.X.X.2", user "postgres", database "postgres", SSL off
我的 postgres.conf 文件
data_directory = '/var/lib/postgresql/10/main'
hba_file = '/etc/postgresql/10/main/pg_hba.conf'
listen_addresses = '*'
我尝试了 postgresql 重启、重新加载和系统重启。它不会根据 pg_hba.conf 文件反映出来。
在上面的设置中,我也尝试使用 localhost
psql -c 'SELECT version()' -h 127.0.0.1 -U postgres
它仍然无法连接
它只适用于
PSQL: