【发布时间】:2018-02-02 19:11:02
【问题描述】:
这可能看起来微不足道,但我如何将一台机器 ('A') 连接到另一台机器 ('B') 以便始终同步 'A' 和 'B' 中的数据库。两台机器都在 macOS High Sierra 上运行,并且 PostgreSQL v10 安装了 homebrew。基本上,我希望“A”成为“B”的客户端 - 它充当服务器,“A”应该能够修改“B”中的数据库,并且两者都可以看到更改。我在“B”上启用了 ssh 连接。我根据“B”中的几个在线修复修改了 postgresql.conf 和 pg_hba.conf。
但是,我在“A”中的 shell 中总是遇到同样的错误:
$ psql -h [ip 'B'] -p 5432 -U devil -W test_db
psql: FATAL: no pg_hba.conf entry for host "ip 'A'", user "devil", database "test_db", SSL off
'B' 中的 PostgreSQL 文件(目录:/usr/local/var/postgres):
在 postgresql.conf [摘录]:
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
listen_addresses = '*' # 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)
在 pg_hba.conf [摘录] - 我从同一文件夹中名为 pg_hba.conf.sample 的文件中复制:
# TYPE DATABASE USER ADDRESS METHOD
@remove-line-for-nolocal@ # "local" is for Unix domain socket
connections only
@remove-line-for-nolocal@
local all all
@authmethodlocal@
# IPv4 local connections:
host all all 127.0.0.1/32
@authmethodlocal@
# IPv6 local connections:
host all all ::1/128
@authmethodlocal@
# Allow replication connections from localhost, by a user with the
# replication privilege.
@remove-line-for-nolocal@local replication all
@authmethodlocal@
host replication all 127.0.0.1/32 trust
host replication all ::1/128 trust
host all all 0.0.0.0/0 md5#ipv4 range
我重新启动了服务器:
$ brew services restart postgresql
【问题讨论】:
标签: macos postgresql shell homebrew pg-hba.conf