postgresql - 无法连接到服务器:连接被拒绝服务器是否在主机上运行...并接受端口 5432 上的 TCP/IP 连接?
问题描述
我刚刚在 AWS 的 Ubuntu 上部署了 Postgres / timescaleDB。
当我 ssh 我的 postgres VM 时,我可以通过 CLI 连接 pgsql。
ubuntu@ip-172-31-35-57:~$ psql -U julien -h localhost db
Password for user julien:
psql (12.3 (Ubuntu 12.3-1.pgdg20.04+1))
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.
db=>
我还可以看到 postgres 正在听
ubuntu@ip-172-31-35-57:~$ sudo netstat -nlpute
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 101 46086 6152/systemd-resolv
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 0 20033 700/sshd: /usr/sbin
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 113 62083 20332/postgres
tcp6 0 0 :::80 :::* LISTEN 0 68924 23549/apache2
tcp6 0 0 :::22 :::* LISTEN 0 20044 700/sshd: /usr/sbin
udp 0 0 127.0.0.53:53 0.0.0.0:* 101 46085 6152/systemd-resolv
udp 0 0 172.31.35.57:68 0.0.0.0:* 100 651337 6134/systemd-networ
我检查了ufw:
ubuntu@ip-172-31-35-57:~$ sudo ufw status
Status: inactive
我还完全打开了安全组。
但是,我仍然无法从本地连接我的 postgres 数据库。
使用本地 Postgres 数据库,我没有问题(我的应用程序有效)
我忘了什么???
解决方案
检查 postgresql.conf 文件中的 listen_addresses 允许远程连接。它应该是
听地址 = '*'
在 pg_hba.conf 文件中,您需要添加以下条目
托管所有所有 0.0.0.0/0 md5
确保这不是防火墙问题。
推荐阅读
- javascript - 即使在单击播放(和取消静音)后,HTML 自动播放视频仍保持静音
- math - 如何计算两个三角形相交的线段?
- mysql - 替换 SQL 中的关联值?
- java - 尝试使用spring boot将相同的数据保存到firebase
- r - 将逻辑向量中的值替换为因子
- assembly - MASM 指令“mov edx,OFFSET 名称”的语法错误
- laravel - Laravel 7:自定义保护身份验证无法按预期工作
- eclipse-che - 不能使用 chectl auth:login 或 server:shutdown
- python - 从 s3 读取一个 csv 文件,不包括一些值
- apache-camel - 基于表达式处理的事务性 Camel 路由标记交换不起作用