Postgresql:无法在控制台通过 psql 连接到默认本地主机
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30307933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Postgresql: Unable to connect through psql at console to default localhost
提问by Robert White
Postgresql server running and verified on 5432 on my localhost system:
Postgresql 服务器在我的本地主机系统上的 5432 上运行和验证:
If I type: psql -l
I get the following response:
如果我输入:psql -l
我得到以下响应:
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:无法连接到服务器:没有这样的文件或目录
服务器是否在本地运行并接受 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432”上的连接?
If I type psql -h localhost -l
, it works and gives me a list of the databases.
如果我输入psql -h localhost -l
,它就会工作并给我一个数据库列表。
The pg_hba.conf
file is wide open, showing:
该pg_hba.conf
文件是完全打开的,显示:
TYPE DATABASE USER ADDRESS METHOD
The value "local" is for Unix domain socket connections only:
值“local”仅适用于 Unix 域套接字连接:
local all all trust
Allow any IP to connect without password:
允许任何 IP 无需密码即可连接:
host all all 0.0.0.0/0 trust
IPv4 local connections:
IPv4 本地连接:
host all all 127.0.0.1/32 trust
IPv6 local connections:
IPv6 本地连接:
host all all ::1/128 trust
What have I missed? On other systems the first call from the command line works fine.
我错过了什么?在其他系统上,来自命令行的第一次调用工作正常。
回答by errata
It sounds like when you are running the command you are connecting to localhost, not the file socket.. try
听起来当您运行命令时,您正在连接到本地主机,而不是文件套接字..试试
psql -h localhost -p 5432
回答by Muhammad Taqi
Default Admin Login sudo -u postgres psql
默认管理员登录 sudo -u postgres psql
Login into specific db with privilages psql -h host -p port -U User_Name db_name
使用特权登录到特定的数据库 psql -h host -p port -U User_Name db_name
回答by Daniel Vérité
Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
服务器是否在本地运行并接受 Unix 域套接字“/var/run/postgresql/.s.PGSQL.5432”上的连接?
This just means that the unix_socket_directory
configuration parameter on the server differs from the default of the client-side psql.
这只是意味着unix_socket_directory
服务器上的配置参数与客户端 psql 的默认值不同。
/var/run/postgresql
is the default Unix domain socket path for Debian-based packages. For a self-compiled server, it is /tmp
. It may also be a custom path specified in postgresql.conf
or through a start directive.
/var/run/postgresql
是基于 Debian 的软件包的默认 Unix 域套接字路径。对于自编译的服务器,它是/tmp
. 它也可以是在postgresql.conf
start 指令中或通过 start 指令指定的自定义路径。
Assuming it's /tmp
you could do psql -l -h /tmp
. The command knows that the parameter following -h
is to be interpreted as a directory and not as a hostname because it starts with a slash.
假设它是/tmp
你可以做的psql -l -h /tmp
。该命令知道后面的参数-h
将被解释为目录而不是主机名,因为它以斜杠开头。