没有-h标志,psql无法连接

迭戈·维克多·德·耶稣

psql从Debian 8.7终端运行,但无法弄清楚为什么需要该-h标志才能执行。例如,如果我psql -U postgres在终端上运行,则会出现以下错误:

psql: could not connect to server: No such file or directory
        Is the server running locally and accepting
        connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

但是,当添加主机标志时,我可以连接:

psql -U postgres -h localhost

psql (9.4.10, server 9.6.2)
WARNING: psql major version 9.4, server major version 9.6.
         Some psql features might not work.
Type "help" for help.

postgres=#

原因是什么?

劳伦兹·阿尔伯

客户端和服务器似乎对应该创建UNIX套接字的目录有不同的想法。

连接到数据库后,运行

SHOW unix_socket_directories;

这将告诉您可以在哪个目录(或多个目录)中找到UNIX套接字。

您可以将目录名与-h选项一起使用,或者将环境变量设置PGHOST为本地连接名称。

例如,如果您得到的结果是/tmp(出厂默认值),则可以使用

psql -h /tmp -U postgres

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章