【发布时间】:2019-08-15 01:05:08
【问题描述】:
我对 PostgreSQL 有一个错误:
SQLSTATE[08006] [7] 无法连接到服务器:连接被拒绝 服务器是否在主机“localhost”(::1) 上运行并且 接受端口 5432 上的 TCP/IP 连接?无法连接到服务器:连接被拒绝 服务器是否在主机“localhost”(127.0.0.1) 上运行并接受端口 5432 上的 TCP/IP 连接?
以下命令未显示 5432 端口已打开:
sudo netstat -plunt |grep postgres
我猜问题出在 5432 端口,所以我在 netstat 没有看到它。
如何为 PostgreSQL 打开端口?
-
postgresql.conf和pg_hba.conf文件正常(见下文)。 -
postgres服务器正在运行 - 我的
postgresql.conf文件:
listen_addresses = '*'
port = 5432
- 我的
pg_hba.conf文件:
local all postgres md5
local all all md5
host all all 0.0.0.0/0 trust
host all all 127.0.0.1/32 trust
host all all ::1/128 trust
local replication all peer
host replication all 127.0.0.1/32 md5
host replication all ::1/128 md5
- 我运行了命令:
$ netstat -atu
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:6379 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:http 0.0.0.0:* LISTEN
tcp 0 0 localhost:domain 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:https 0.0.0.0:* LISTEN
tcp 0 0 30secondboomer.com:ssh 109-252-90-59.nat:11807 ESTABLISHED
tcp 0 0 30secondboomer.com:ssh 109-252-90-59.nat:11258 ESTABLISHED
tcp 0 0 30secondboomer.com:ssh 109-252-90-59.nat:11797 ESTABLISHED
tcp6 0 0 localhost:6379 [::]:* LISTEN
tcp6 0 0 [::]:http [::]:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
tcp6 0 0 [::]:https [::]:* LISTEN
udp 0 0 localhost:domain 0.0.0.0:*
udp 0 0 30secondboomer.c:bootpc 0.0.0.0:*
【问题讨论】:
-
请检查日志。 PostgreSQL 服务器显然(netstat 输出)没有运行。
-
我使用命令“sudo service postgresql status” ● postgresql.service - PostgreSQL RDBMS 已加载:已加载(/lib/systemd/system/postgresql.service;已启用;供应商预设:已启用) 活动:活动(已退出)自 2019 年 3 月 24 日星期日 21:01:12 MSK 起; 6 分钟前进程:24974 ExecStart=/bin/true (code=exited, status=0/SUCCESS) Main PID: 24974 (code=exited, status=0/SUCCESS) Mar 24 21:01:12 cs451508 systemd[1]:正在启动 PostgreSQL RDBMS... 3 月 24 日 21:01:12 cs451508 systemd[1]: 启动 PostgreSQL RDBMS。
-
本地主机应该对自己开放。您是否要在该端口上的服务器之间跳转?还是您在同一台服务器上连接到数据库?
-
在同一台服务器上
-
服务器似乎没有运行。以下是 PostgreSQL 日志: 致命:pg_hba.conf 拒绝主机“109.252.90.59”的连接 LOG:收到快速关闭请求 LOG:中止任何活动事务 LOG:后台工作人员“逻辑复制启动器”(PID 421)退出,退出代码为 1 LOG : 关闭
标签: postgresql database-connection database-server