我按照如下说明进行操作:https://ubuntu.com/server/docs/databases-postgresql 这是我做的:
Postgresql-server(在我的 Ubuntu 台式电脑上)
# Installed the Postgresql server
# Went to the sudo nano /etc/postgresql/14/main/pg_hba.conf
# entered following line at end:
# My understanding of below line is allow the connection to the
# this ubuntu computer (10.1.2.3) from a
# remote device with ip 10.1.2.4 with user postgres
hostssl template1 postgres 10.1.2.4 scram-sha-256
# This device ip on which Postgresql server is sitting: 10.1.2.3
Postgresql-client(在远程 Raspberry PI 设备上)(ip:10.1.2.4):这是我所做的:
# Install Postgresql-client
# access the Postgresql-server as
psql --host 10.1.2.3 --username postgres --password --dbname template1
在 Postgresql-client 上显示输出:
psql error: could not connect to server: connection refused
Is the server running on host 10.1.2.3 and accepting
TCP/IP connections on port 5432?
我第一次听说这个端口 5432。我想知道什么地方出了问题以及如何纠正它?
更新:
答案1
我们尝试复制您的 pg_hba.conf 条目:
hostssl template1 postgres 10.1.2.4 scram-sha-256
我们在 /var/log/syslog 中重启时遇到了 postgresql 服务器错误,如下行:
LOG: invalid IP mask "scram-sha-256": Name or service not known
这提醒我们,“AP 地址”后面缺少“IP 掩码”。请在 10.1.2.4 地址末尾添加“/32”掩码,如下所示:
hostssl template1 postgres 10.1.2.4/32 scram-sha-256
并且postgresql服务器可以成功重新启动。