↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

已结束支持的版本: 7.0 / 6.5 / 6.3
历史版本。 PostgreSQL 6.5 已结束支持。 请参阅 当前版本手册.

26.2. 客户端连接问题

一旦你有了一个正在运行的 postmaster,用客户端应用连接它仍然可能因为多种原因而失败。这里给出的示例错误消息来自基于较新版本 libpq 的客户端——基于其他接口库的客户端可能产生信息量或多或少不同的其他消息。

connectDB() -- connect() failed: Connection refused
Is the postmaster running (with -i) at 'server.joe.com' and accepting connections on TCP/IP port '5432'?
    

这是常见的"我找不到可以对话的 postmaster"失败。尝试 TCP/IP 通信时它像上面这样,而尝试通过 Unix 套接字连接本地 postmaster 时则像这样:

connectDB() -- connect() failed: No such file or directory
Is the postmaster running at 'localhost' and accepting connections on Unix socket '5432'?
    

最后一行有助于确认客户端是否在尝试连接它应该连接的地方。如果那里确实没有 postmaster 在运行,内核错误消息通常会是 "Connection refused"或"No such file or directory",如图所示。(特别重要的是要认识到,在这种情况下的"Connection refused" 并不意味着 postmaster 收到了你的连接请求并拒绝了它——那种情况会产生不同的消息,如下所示。)其他错误消息如"Connection timed out"可能指示更根本的问题,比如缺乏网络连通性。

No pg_hba.conf entry for host 123.123.123.123, user joeblow, database testdb
    

如果你成功联系到了一个 postmaster 但它不想和你交谈,最有可能得到的就是这条消息。正如消息所提示的,postmaster 拒绝了连接请求,因为它在它的 pg_hba.conf 配置文件中没有找到授权条目。

Password authentication failed for user 'joeblow'
    

这样的消息表明你联系到了 postmaster,它愿意和你交谈,但前提是你通过 pg_hba.conf 文件中指定的认证方法。检查你提供的口令,或者如果错误消息提到 Kerberos 或 IDENT 认证类型之一,检查你的 Kerberos 或 IDENT 软件。

FATAL 1:  SetUserId: user 'joeblow' is not in 'pg_shadow'
    

这是认证失败的另一种变体:对给定的用户名还没有执行过 Postgres 的 create_user 命令。

FATAL 1:  Database testdb does not exist in pg_database
    

这个 postmaster 控制之下没有那个名字的数据库。注意,如果你不指定数据库名,默认使用你的 Postgres 用户名,而这未必是正确的选择。

报告文档问题

阅读 上游文档. 反馈更正前请先核对 当前版本手册.