无法连接到 VM 的 Postgresql 服务器?

问题描述 投票:0回答:1

基本上我正在尝试连接到托管在 GCP 虚拟机上的 postgresql 服务器。我已经在那里创建了数据库,我已经更改了我的防火墙以允许在端口 5432 上进行连接,将此 --> " listen_addresses = '*' " 添加到我的 postgresql.config 文件中,并将我本地机器的外部 IP 地址添加到pg_hba.conf 文件中使用信任方法接受的 IP 列表。有没有人知道这里可能出了什么问题?我一直收到这个错误

postgres@LAPTOP-14QDEC1P:/mnt/d/random path $ psql -U postgres -p 5432 -h xx.xxx.xxx.xxx api_fp
psql: error: could not connect to server: Connection refused
        Is the server running on host "xx.xxx.xxx.xxx" and accepting
        TCP/IP connections on port 5432? 
   

监听的端口也设置为 5432.

database postgresql google-cloud-platform virtual-machine remote-access
1个回答
1
投票

您还必须在 VPC 上允许 Google Cloud Firewall 规则才能使其工作。您可以从项目中的控制台打开您的 Google Cloud Shell 并运行以下 gcloud 命令以允许 vpc 网络中所有实例的防火墙规则:

gcloud compute firewall-rules create allow-postgres \
--allow tcp:5432 \
--direction INGRESS \
--source-ranges <yourhomeipaddress> \
--network <your-vpc-name>

有关这方面的文档,您可以阅读: https://cloud.google.com/vpc/docs/firewalls

© www.soinside.com 2019 - 2024. All rights reserved.