首页 文章

无法连接到通过brew服务运行的Postgres服务器

提问于
浏览
22

我一直在寻找解决方案,但找不到可行的解决方案 .

我在我的MacBook中使用brew( brew install postgres )安装了postgres,我目前正在使用brew服务运行它( brew services list 显示postgres作为运行服务) . 但是,当我尝试运行 psql 时,我收到以下错误 .

psql:无法连接到服务器:没有这样的文件或目录服务器是否在本地运行并接受Unix域套接字“/tmp/.s.PGSQL.5432”上的连接?

有人已经解决了类似的问题吗?

5 回答

  • 2

    我有同样的错误,我通过删除进程pid文件修复它:

    rm -f /usr/local/var/postgres/postmaster.pid

  • 45

    我今天遇到了这个问题 . postgres停止接受连接虽然自制软件认为它正在运行 .

    为了解决它,我跑了,

    brew services restart -vvv postgresql
    

    从此命令输出,

    ==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
    ==> Generated plist for postgresql:
       <?xml version="1.0" encoding="UTF-8"?>
       <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
       <plist version="1.0">
       <dict>
         <key>KeepAlive</key>
         <true/>
         <key>Label</key>
         <string>homebrew.mxcl.postgresql</string>
         <key>ProgramArguments</key>
         <array>
           <string>/usr/local/opt/postgresql/bin/postgres</string>
           <string>-D</string>
           <string>/usr/local/var/postgres</string>
         </array>
         <key>RunAtLoad</key>
         <true/>
         <key>WorkingDirectory</key>
         <string>/usr/local</string>
         <key>StandardErrorPath</key>
         <string>/usr/local/var/log/postgres.log</string>
       </dict>
       </plist>
    

    然后我想,嗯也许那个日志文件中有东西,

    tail -n 10 /usr/local/var/log/postgres.log
    

    果然,

    [4826] FATAL:  lock file "postmaster.pid" already exists
    [4826] HINT:  Is another postmaster (PID 1489) running in data directory "/usr/local/var/postgres"?
    

    所以,我删除了该文件

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

    一切都开始了 .

  • 6

    我会在这里结合Wilson和Grasshopper的两个答案 .

    您可以使用 brew services list 检查plist文件中的postgres服务,以查找文件的位置,并在您喜欢的编辑器中打开它 .

    您应该看到 StandardErrorPath 的值列为:

    <key>StandardErrorPath</key>
    <string>/usr/local/var/log/postgres.log</string>
    

    然后你应该使用 tail -n 100 /usr/local/var/log/postgres.log 尾随日志文件的结尾

    在我的情况下,错误如下:

    2017-12-06 11:51:16.078 GMT [85476]致命:锁定文件“postmaster.pid”已经存在2017-12-06 11:51:16.078 GMT [85476]提示:是否正在运行另一个postmaster(PID 601)在数据目录“/ usr / local / var / postgres”?

    这是因为我必须硬关闭我的Mac并且postgres没有机会清理PID文件 . 只需删除PID文件 rm /usr/local/var/postgres/postmaster.pid 并启动postgres brew services start postgresql

    一句警告: do not delete this PID file unless you are sure that postgres is not running . 您可以通过运行 brew services stop postgresql 然后等待 brew services list 的结果来显示posgres处于停止状态来执行此操作 .

  • 12

    我从版本点击安装postgresql93时遇到了同样的错误 . 检查 brew services list~/Library/LaunchAgents/homebrew.mxcl.postgresql93.plist )输出中指示的.plist文件,我发现以下消息:

    致命:数据目录“/ usr / local / var / postgres”具有组或世界访问权限详细信息:权限应为u = rwx(0700) .

    这让我得到了这个答案:data directory "/usr/local/var/postgres" has wrong ownership

    运行 sudo chmod -R 700 /usr/local/var/postgres 后,我得到了一个不同的错误:

    致命:无法打开目录“pg_tblspc”:没有这样的文件或目录

    然后导致我:pg_tblspc missing after installation of latest version of OS X (Yosemite or El Capitan)

    运行 mkdir /usr/local/var/postgres/pg_tblspc/ 后,群集已成功启动 .

  • 0

    对我有用的是删除 /usr/local/var/postgres/ 文件夹,然后再次卸载和安装postgres

相关问题