起因

想要启动postgresql服务,使用命令brew service start postgresql@14报错

~% brew services start postgresql@14
Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/lucky/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist` exited with 5.

尝试

  1. 根据提示使用sudo重新运行命令,想看一下更详细的错误,但是sudo启动成功
    ~ % sudo brew services start postgresql@14
    Password:
    Warning: Taking root:admin ownership of some postgresql@14 paths:
      /opt/homebrew/Cellar/postgresql@14/14.9/bin
      /opt/homebrew/Cellar/postgresql@14/14.9/bin/postgres
      /opt/homebrew/opt/postgresql@14
      /opt/homebrew/opt/postgresql@14/bin
      /opt/homebrew/var/homebrew/linked/postgresql@14
    This will require manual removal of these paths using `sudo rm` on
    brew upgrade/reinstall/uninstall.
    Warning: postgresql@14 must be run as non-root to start at user login!
    ==> Successfully started `postgresql@14` (label: homebrew.mxcl.postgresql@14)
    
    但是仍然无法连接postgresql。
  2. 查到有可能是因为端口被占用。但是并不是。
  3. 再次尝试运行sudo brew services start postgresql@14,报错已经在运行,这里猜测pg是根据用户进行管理的,在root用户下启动的服务普通用户无法连接(未经证实)。然后运行sudo brew services stop postgresql@14

解决

尝试运行了一下brew services stop postgresql@14,竟然返回运行成功,之后再启动pg就成功了。

总结

误打误撞解决了问题,但是并不理解为什么。以及pg对不同用户的管理方式也需要再去学一些。
对于报错

Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/lucky/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist` exited with 5.

github上也有很多问答,但是没怎么细看,好像更多是就事论事,存在很多情况。

Update

启动了postgresql仍然无法连接,而且我发现如果重复启动也会报上面的错误,所以我怀疑最开始问题就不是无法启动,而是无法连接。看到了这样一篇blog,https://blog.csdn.net/qq_36840228/article/details/125724652,解决了问题,学习ing

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐