【问题标题】:Postgres/Mac - 'service already loaded', but 'could not connect to server'Postgres/Mac - '服务已经加载',但'无法连接到服务器'
【发布时间】:2018-02-07 16:00:13
【问题描述】:

我在我的 Mac(High Sierra,10.13.3)上运行 Homebrew 安装的 Postgres 版本 9.6.3,今天早上我发现 Postgres 有一些问题。昨晚还好好的,然后我把电脑睡了……今天早上我把它叫醒并尝试运行凤凰应用程序时,我得到了

[error] Postgrex.Protocol (#PID<0.306.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused

运行 psql 返回

psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

所以看起来服务器可能已经停止了......但是,运行我的别名 pg-start,转换为 launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist 返回

/usr/local/Cellar/postgresql/9.6.3/homebrew.mxcl.postgresql.plist: service already loaded

所以这很令人困惑,因为似乎一个命令表明 Postgres 没有运行,而另一个表明它正在运行。

我无法确定,但我可能在昨晚让计算机进入睡眠状态之前停止了服务器,实际上我通常不会这样做...我的 pg-stop 别名是 launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

虽然我不明白为什么这会导致问题,但这是唯一让我印象深刻的事情是我可能做过的“不同”的事情。

我已尝试重新启动我的机器,但问题仍然存在。我对调试此类问题的经验并不丰富,因此非常感谢任何指导或建议。

【问题讨论】:

    标签: postgresql homebrew


    【解决方案1】:

    好吧,我解决了,但我不确定具体的问题是什么。为了获得更多错误信息,我跑了

    postgres -D /usr/local/var/postgres
    

    这给了我

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

    我以前遇到过,所以我知道如何继续......

    以下是我为解决此问题所采取的步骤:

    首先,我跑了

    pg_ctl -D /usr/local/var/postgres start
    

    返回的

    pg_ctl: another server might be running; trying to start server anyway
    server starting
    My-MBP:~ me$ FATAL:  lock file "postmaster.pid" already exists
    HINT:  Is another postmaster (PID 1188) running in data directory "/usr/local/var/postgres"?
    

    然后我运行了我的别名pg-stop

    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
    

    紧随其后

    pg_ctl -D /usr/local/var/postgres start
    

    再次。这一次,它回来了

    server starting
    My-MBP:~ me$ LOG:  database system was shut down at 2018-02-07 11:10:43 EST
    LOG:  MultiXact member wraparound protections are now enabled
    LOG:  database system is ready to accept connections
    LOG:  autovacuum launcher started
    

    现在 Postgres 运行正常 - psql 命令等

    但是,现在我的别名 pg-stop 不起作用 -

    /Users/me/Library/LaunchAgents/homebrew.mxcl.postgresql.plist: Could not find specified service
    

    我跑了

    pg_ctl -D /usr/local/var/postgres stop
    

    然后我的pg-stop 别名被恢复。所以现在pg-startpg-stop 正在正常工作。

    我希望这对将来的某人有所帮助,但如果有人能解释这里发生了什么,我真的很感激能更深入地了解问题所在。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-24
      • 2015-06-20
      • 2018-03-09
      相关资源
      最近更新 更多