PostgreSQL:连接被拒绝.检查主机名和端口是否正确以及邮局主管正在接受TCP/IP连接

编程入门 行业动态 更新时间:2024-10-25 14:31:38
本文介绍了PostgreSQL:连接被拒绝.检查主机名和端口是否正确以及邮局主管正在接受TCP/IP连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试连接postgresql,但出现此错误.

I am trying to connect postgresql but I am getting this error.

org.postgresql.util.PSQLException: Connection refused. Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections.

我的pg_hba.conf文件就是这样.

My pg_hba.conf file is like this.

TYPE DATABASE USER CIDR-ADDRESS METHOD # IPv4 local connections: host all all 127.0.0.1/32 md5 # IPv6 local connections: host all all ::1/128 md5

如果有人请我足够友好地解释这里发生的事情以及我应该如何纠正它,我将非常有责任.

I would be much obliged if anyone please be so kind enough to explain whats hoing on here and how should I correct it.

推荐答案

您引用的错误与pg_hba.conf无关;它无法连接,而不是未授权连接.

The error you quote has nothing to do with pg_hba.conf; it's failing to connect, not failing to authorize the connection.

执行错误消息显示的内容:

Do what the error message says:

检查主机名和端口是否正确以及邮局主管正在接受TCP/IP连接

Check that the hostname and port are correct and that the postmaster is accepting TCP/IP connections

您尚未显示产生错误的命令.假设您正在localhost端口5432(标准PostgreSQL安装的默认设置)上进行连接,则可以:

You haven't shown the command that produces the error. Assuming you're connecting on localhost port 5432 (the defaults for a standard PostgreSQL install), then either:

  • PostgreSQL未运行

  • PostgreSQL isn't running

PostgreSQL没有监听TCP/IP连接(postgresql.conf中的listen_addresses)

PostgreSQL isn't listening for TCP/IP connections (listen_addresses in postgresql.conf)

PostgreSQL仅侦听IPv4(0.0.0.0或127.0.0.1),而您正在侦听IPv6(::1),反之亦然.在某些具有怪异的IPv6套接字行为的Mac OS X较旧版本以及Windows的某些较旧版本中,这似乎是一个问题.

PostgreSQL is only listening on IPv4 (0.0.0.0 or 127.0.0.1) and you're connecting on IPv6 (::1) or vice versa. This seems to be an issue on some older Mac OS X versions that have weird IPv6 socket behaviour, and on some older Windows versions.

PostgreSQL正在监听的端口与您正在连接的端口不同

PostgreSQL is listening on a different port to the one you're connecting on

(不太可能)有一个iptables规则阻止回送连接

(unlikely) there's an iptables rule blocking loopback connections

(如果您不是在localhost上连接 ,则它也可能是阻止TCP/IP连接的网络防火墙,但我猜您正在使用默认值,因为您没有说).

(If you are not connecting on localhost, it may also be a network firewall that's blocking TCP/IP connections, but I'm guessing you're using the defaults since you didn't say).

所以...检查那些:

  • ps -f -u postgres应该列出postgres进程

sudo lsof -n -u postgres |grep LISTEN或sudo netstat -ltnp | grep postgres应该显示PostgreSQL正在侦听的TCP/IP地址和端口

sudo lsof -n -u postgres |grep LISTEN or sudo netstat -ltnp | grep postgres should show the TCP/IP addresses and ports PostgreSQL is listening on

顺便说一句,我认为您必须使用旧版本.在我的9.3安装中,该错误更为详细:

BTW, I think you must be on an old version. On my 9.3 install, the error is rather more detailed:

$ psql -h localhost -p 12345 psql: could not connect to server: Connection refused Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 12345?

更多推荐

PostgreSQL:连接被拒绝.检查主机名和端口是否正确以及邮局主管正在接受TCP/IP连接

本文发布于:2023-10-15 00:52:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1492752.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   是否正确   被拒   主机名   邮局

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!