PostgreSQL:为什么在运行psql时必须指定-h localhost? [英] postgresql: Why do I have to specify -h localhost when running psql?

查看:884
本文介绍了PostgreSQL:为什么在运行psql时必须指定-h localhost?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

psql mydb产生:

psql: could not connect to server: Permission denied
    Is the server running locally and accepting
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?

psql -h localhost mydb可以正常工作. pg_hba.conf看起来像:

psql -h localhost mydb works just fine. pg_hba.conf looks like:

local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
host    all             all             ::1/128                 trust

怎么了?

推荐答案

我发生了完全相同的事情,大概是由于psql版本冲突(一个来自Lion,一个来自自制).虽然我仍然无法弄清楚如何使psql使用/tmp套接字目录,但确实可以解决该问题.

I had the exact same thing happen to me, presumably due to the conflicting version of psql (one from Lion, one from homebrew). While I still haven't been able to figure out how to make psql use the /tmp socket directory, I do have a work around.

在.bashrc(或.zshrc等)中放置以下内容:

Put the following in your .bashrc (or .zshrc, etc):

export PGHOST=/tmp

这会将正确的主机"设置回正确的套接字目录,而不必提供-h标志

This sets the correct "host" back to the correct socket directory, without having to supply the -h flag

这篇关于PostgreSQL:为什么在运行psql时必须指定-h localhost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆