大网数据广告活动
服务器运维问答

Postgresql Connection Timed out

· 52CE 我爱测

when I am connecting to psql on remote server >psql -h {hostname} psql: could not connect to server: Connection timed out (0x0000274C/10060). Is the server running on host "{hostname}" (194.58.98.133) and accepting TCP/IP connect…

问题原文

原帖链接 · Clyde · CC BY-SA 3.0

when I am connecting to psql on remote server

>psql -h {hostname}
psql: could not connect to server: Connection timed out (0x0000274C/10060). Is the server running on host "{hostname}" (194.58.98.133) and accepting TCP/IP connections on port 5432?

On server:

netstat -nlp | grep 5432
tcp   0 0 0.0.0.0:5432   0.0.0.0:*  LISTEN  29609/postmaster
tcp        0      0 :::5432  :::*  LISTEN      29609/postmaster
unix  2   [ ACC ]  STREAM   LISTENING 2107633273 29609/postmaster   /tmp/.s.PGSQL.5432

there is not iptables on server. Pinging the server is successful.

What I am doing wrong?

社区高分解答

原帖链接 · Dzmitry Savinkou · CC BY-SA 3.0

I was getting this kind of error when my pg_hba.conf or AWS security groups have not been configured properly. There are plenty of docs about how to resolve this. For example, you can check the below, quoted from this link

Error: psql: could not connect to server: Connection refused Is the server running on host "192.168.0.1" and accepting TCP/IP connections on port 5432?

Common Cause: The postmaster or PostgreSQL's server daemon process is not running or configured incorrectly.

When you receive this error most of the time it is due to not having PostgreSQL configured to allow TCP/IP connections or at least not connections from your particular workstation. If you have verified that postmaster is indeed running on the host you are trying to connect to then here is a list of common causes to this problem:

  • postgresql.conf not setup to allow TCP/IP connections. You'll want to look at the listen_address configuration parameter.
  • postgresql.conf is not setup to allow connections on a non-standard port number. To determine this look at the port configuration option.
  • authentication rules in PostgreSQL's access configuration file (pg_hba.conf) are not setup to allow either your uses or IP address to connect to that database. See the official documentation for more information on setting up your pg_hba.conf properly.
  • ensure that there are no firewalls, such as iptables that are keeping your local system from even establishing a connection to the remote host

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2015-06-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。