psql:无法连接到服务器:没有这样的文件或目录(Mac OS X) [英] psql: could not connect to server: No such file or directory (Mac OS X)

查看:1309
本文介绍了psql:无法连接到服务器:没有这样的文件或目录(Mac OS X)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

重新启动Mac时,出现了可怕的Postgres错误:

Upon restarting my Mac I got the dreaded Postgres error:

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"?

发生这种情况的原因是,由于一个不相关的问题,我的Macbook完全冻结了,我不得不使用电源按钮进行强制重启.重新启动后,由于此错误,我无法启动Postgres.

The reason this happened is because my macbook froze completely due to an unrelated issue and I had to do a hard reboot using the power button. After rebooting I couldn't start Postgres because of this error.

推荐答案

警告:如果在不确保确实没有postgres进程在运行的情况下删除postmaster.pid,可能会永久破坏数据库 >. (如果邮局主管已经退出,PostgreSQL应该自动将其删除.)

WARNING: If you delete postmaster.pid without making sure there are really no postgres processes running you, could permanently corrupt your database. (PostgreSQL should delete it automatically if the postmaster has exited.).

解决方案:此问题已解决-我删除了此文件,然后一切正常!

SOLUTION: This fixed the issue--I deleted this file, and then everything worked!

/usr/local/var/postgres/postmaster.pid

-

,这就是我弄清楚为什么需要删除它的方式.

and here is how I figured out why this needed to be deleted.

  1. 我使用以下命令查看是否正在运行任何PG进程.对我而言,没有,我什至无法启动PG服务器:

  1. I used the following command to see if there were any PG processes running. for me there were none, I couldn't even start the PG server:

ps auxw | grep post

  • 我搜索了上面错误消息中的文件.s.PGSQL.5432.我使用了以下命令:

  • I searched for the file .s.PGSQL.5432 that was in the error message above. i used the following command:

    sudo find / -name .s.PGSQL.5432 -ls
    

    在搜索我的整个计算机后,该文件未显示任何内容,因此该文件不存在,但是显然psql希望它"或认为它在那里".

    this didn't show anything after searching my whole computer so the file didn't exist, but obviously psql "wanted it to" or "thought it was there".

    我查看了我的服务器日志,并看到以下错误:

    I took a look at my server logs and saw the following error:

    cat /usr/local/var/postgres/server.log
    

    在服务器日志末尾,我看到以下错误:

    at the end of the server log I see the following error:

    FATAL:  pre-existing shared memory block (key 5432001, ID 65538) is still in use
    HINT:  If you're sure there are no old server processes still running, remove the shared memory block or just delete the file "postmaster.pid".
    

  • 按照错误消息中的建议,我删除了与server.log相同目录中的postmaster.pid文件.这样就解决了问题,我得以重新启动.

  • Following the advice in the error message, I deleted the postmaster.pid file in the same directory as server.log. This resolved the issue and I was able to restart.

    因此,似乎我的Macbook死机并被重新引导后,使Postgres认为它的进程即使在重新引导后仍在运行.解决了删除该文件的问题.希望这对其他人有帮助!很多人都有类似的问题,但大多数答案与文件权限有关,而在我看来,情况却有所不同.

    So, it seems that my macbook freezing and being hard-rebooted caused Postgres to think that it's processes were still running even after reboot. Deleting this file resolved. Hope this helps others! Lots of people have similar issues but most the answers had to do with file permissions, whereas in my case things were different.

    这篇关于psql:无法连接到服务器:没有这样的文件或目录(Mac OS X)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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