【问题标题】:Why postgresql@11 service failed instantly after i installed with brew on macos?为什么我在 macos 上安装 brew 后 postgresql@11 服务立即失败?
【发布时间】:2021-10-23 12:12:43
【问题描述】:

我现在在 postgresql@11 上遇到了有关 brew 服务的问题。在我重新安装 (from this blog) postgresql@11 后,它立即在brew services 上给出错误。然后我运行了这个brew services restart -vvv postgresql@11 它返回了这个结果:

<?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@11</string>
    <key>ProgramArguments</key>
    <array>
        <string>~/.homebrew/opt/postgresql@11/bin/postgres</string>
        <string>-D</string>
        <string>~/.homebrew/var/postgresql@11</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>~/.homebrew/var/log/postgresql@11.log</string>
    <key>StandardOutPath</key>
    <string>~/.homebrew/var/log/postgresql@11.log</string>
    <key>WorkingDirectory</key>
    <string>~/.homebrew</string>
   </dict>
   </plist>

当我检查~/.homebrew/var/log/postgresql@11.log 文件时,它是空的。我还检查了该文件的权限,但没关系(r,w)。在没有任何解释的情况下仍然出现此错误(空日志)。 2天前它还在工作,但不知何故我把它弄坏了。我还检查了 postmaster.pid 但该文件在我的机器上不存在,我这样搜索:find . -name "postmaster.pid"

另外,在我重新安装 postgresql@11 后,我的 postgresql@11 目录 (~/.homebrew/var/postgresql@11) 都是空的。

最后,在我的目录中 -> ~/.homebrew/Cellar/postgresql@11/11.13/bin 有 postmaster 文件,但它不是 postmaster.pid 文件,我不知道它是做什么用的,但是当我这样做时,ls -al 显示如下 -> postmaster -&gt; postgres

我的机器是 m1 芯片 macos 上的 macOS Big Sur 11.5.2。希望有人能给我一个想法。

我现在意识到我的安装也有问题。 brew postinstall postgresql@11 结果 ->

Last 15 lines from ~/Library/Logs/Homebrew/postgresql@11/post_install.01.initdb:
2021-08-23 08:27:42 +0300

~/.homebrew/Cellar/postgresql@11/11.13/bin/initdb
--locale=C
-E
UTF-8
~.homebrew/var/postgresql@11

no data was returned by command ""~/.homebrew/Cellar/postgresql@11/11.13/bin/postgres" -V"
The program "postgres" is needed by initdb but was not found in the
same directory as "~/.homebrew/Cellar/postgresql@11/11.13/bin/initdb".
Check your installation.
Warning: The post-install step did not complete successfully
You can try again using:
  brew postinstall postgresql@11

但是我看到的是 initdb 和 postgres 在同一个 bin 文件夹中:/

谢谢,

【问题讨论】:

    标签: postgresql macos homebrew apple-m1 postgresql-11


    【解决方案1】:

    M1 上的 Homebrew 应安装到 /opt/homebrew。但是从您的输出中,~/.homebrew 而不是/opt/homebrew 被用作$HOMEBREW_PREFIX。你的安装发生了什么?

    Homebrew 不支持安装到任意目录。不要导出$HOMEBREW_PREFIX 来更改它。


    引用Homebrew FAQ

    为什么要在默认位置安装 Homebrew?

    Homebrew 的许多包的预构建二进制包(称为瓶子)只能在您以默认安装前缀安装时使用,否则它们必须从源代码构建。从源代码构建需要很长时间,容易失败,并且不受支持。帮自己一个忙并安装到默认前缀,以便您可以使用我们预先构建的二进制包。对于 Intel 上的 macOS,默认前缀是 /usr/local,对于 Apple Silicon/ARM 上的 macOS,默认前缀是 /opt/homebrew,对于 Linux,默认前缀是 /home/linuxbrew/.linuxbrew。选择另一个前缀,后果自负!

    【讨论】:

    • 这是因为我这样导出路径。原因是,它会更容易访问。您可以在下面看到我的 .zshrc 文件,但我认为情况并非如此。 @simba js function path { if [[ -d "$1" ]] ; then if [[ -z "$PATH" ]] ; then export PATH=$1 else export PATH=$PATH:$1 fi fi export PATH='' path ~/.homebrew/sbin path ~/.homebrew/bin path /usr/local/sbin path /usr/local/bin path /usr/sbin path /usr/bin path /sbin path /bin
    • 它也适用于其他可执行文件,但在这里它会立即死亡。 postgres --version-> 输出为 -> [1] 46094 killed postgres --version export HOMEBREW_PREFIX=~/.homebrew/ @Simba
    • @CanerTaşan 手动启动 postgresql 时的输出是什么,~/.homebrew/opt/postgresql@11/bin/postgres -D ~/.homebrew/var/postgresql@11?
    • 一样~/.homebrew/opt/postgresql@11/bin/postgres -D ~/.homebrew/var/postgresql@11 [1] 47327 killed ~/.homebrew/opt/postgresql@11/bin/postgres -D ~/.homebrew/var/postgresql@11@simba
    • 其实我现在 redis 正在运行 ~/Library/LaunchAgents/homebrew.mxcl.redis.plist 但是 postgres 尝试在这里运行 ~/.homebrew/opt/postgresql@11/homebrew.mxcl.postgresql@11.plist @simba
    猜你喜欢
    • 2021-01-20
    • 2016-05-16
    • 1970-01-01
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 2015-09-03
    • 2014-04-09
    • 2020-03-31
    相关资源
    最近更新 更多