![当我尝试通过终端运行时出现 psql 错误](https://linux22.com/image/889583/%E5%BD%93%E6%88%91%E5%B0%9D%E8%AF%95%E9%80%9A%E8%BF%87%E7%BB%88%E7%AB%AF%E8%BF%90%E8%A1%8C%E6%97%B6%E5%87%BA%E7%8E%B0%20psql%20%E9%94%99%E8%AF%AF.png)
当我在终端运行 psql 时显示此错误
badar:~$ psql
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"?
答案1
我发现两个可能的问题:
- Postgresql 未运行
查出:
ps aux | grep [p]ostgresql
使固定:
sudo service postgresql start
- Unix 套接字连接(本地)没有权限。
在 pg_hba.conf 中查找以下行:
local all all peer
如果没有,请添加!如果前面有 #,请将其删除。然后重新启动 postgresql:
sudo service postgresql restart
答案2
尝试这个
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
参考:https://dba.stackexchange.com/questions/75214/psql-could-not-connect-to-server-no-such-file-or-directory。 希望这可以帮助 !!
答案3
最好提到数据库所在的主机名和端口(如果需要,还要提到数据库的用户和密码):
> psql -h <host> -p <port> -u <database>
> psql -h <host> -p <port> -U <username> -W <password> <database>