【问题标题】:How do I enable a remote connection in order to use PostgreSQL?如何启用远程连接以使用 PostgreSQL?
【发布时间】:2019-10-28 19:08:37
【问题描述】:

我在 Azure 上有两个虚拟机,我们称它们为 test1 和 test2。

postgresql-server 已安装并在 test1(服务器,postgres 用户所在的位置)上运行,但我希望能够在 test2(目标)上使用 psql。

到目前为止,我已经编辑了 pg_hba.conf,将目标的 IP 地址包含在它的主机列表中:


# 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
host    all             all             XX.XXX.XX.XXX/32        trust

其中 XX.XXX.XX.XXX 是我的目标机器 test2 的公共 IP 地址。

然后,我编辑了 postgresql.conf 文件,以监听所有地址,而不仅仅是 localhost:

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 

我在我的主机服务器机器上重新加载服务器以获取更改:

pg_ctl -D /path/to/data/ -l logfile reload

据我研究,现在我应该能够在 test2 上,并且只需运行类似的东西:

psql -h 127.0.0.1 -U postgres -p 5432

但每当我这样做时,我都会得到:

-bash: psql: command not found

这是怎么回事???此外,与 Hive db(已设置)的测试连接由于无法连接到数据库而不断失败。

【问题讨论】:

  • 您现在可能能够连接到您的服务器,但您仍然需要机器 test2 上的客户端(在您的情况下为 psql)。安装并重试
  • 谢谢!在 test2 上安装 postgresql(不是 postgresql-server),让我可以运行 psql -h test1ip -p 5432

标签: linux postgresql networking ambari


【解决方案1】:

正如伊斯林格所说:

在目标(test2)上安装 postgresql,允许我运行:

psql -h test1ip -p 5432

成功了。

【讨论】:

    猜你喜欢
    • 2015-01-10
    • 2016-07-13
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-17
    相关资源
    最近更新 更多