gpt4 book ai didi

linux - 如何启用远程连接才能使用 PostgreSQL?

转载 作者:太空宇宙 更新时间:2023-11-04 05:08:09 25 4
gpt4 key购买 nike

我在 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 的公共(public) IP 地址。

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

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 数据库(已设置)的测试连接不断失败,因为它无法连接到数据库。

最佳答案

正如伊斯林格评论的那样:

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

psql -h test1ip -p 5432

成功了。

关于linux - 如何启用远程连接才能使用 PostgreSQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58596992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com