【问题标题】:brew services start postgresql not workingbrew 服务启动 postgresql 不工作
【发布时间】:2018-12-08 12:00:22
【问题描述】:

我已经在 Mac 中使用命令安装了 postgres

brew install postgresql@9.6 并且安装成功

brew services start postgresql@9.6也成功
==> Successfully started postgresql@9.6 (label: homebrew.mxcl.postgresql@9.6)

但是当我尝试从我的 Mac 终端 psql postgresql@9.6 访问 Postgres 时,它提示我奇怪的错误

-bash: /usr/local/bin/psql: No such file or directory

我做错了什么,如何从我的终端打开 psql 为什么我的/usr/local/bin里面没有psql文件

【问题讨论】:

    标签: postgresql homebrew


    【解决方案1】:

    接受的答案不正确。

    如果通过 Homebrew 安装 postgresql@9.6,/bin 文件夹的正确路径是: /usr/local/Cellar/postgresql@9.6/9.6.15/bin

    要连接,只需输入:psql postgres

    如果您对连接的详细信息感到好奇,只需输入 \conninfo 并检查即可。

    【讨论】:

      【解决方案2】:

      您必须启用 Postgres 命令行工具。

      如果您使用的是默认终端,您将要在

      处修改文件

      ~/.bash_profile

      。如果您使用的是 Oh My Zsh 之类的东西,您将需要修改文件 ~/.zshrc

      要编辑此文件,您可能需要通过终端打开它,因此请打开终端并输入 open ~/.bash_profile。你可以用 subl 或任何你喜欢的文本编辑器替换 open 这个词。

      打开zbash_profile.zshrc 文件后,将以下行添加到文件末尾:

      export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin

      之后,您将需要退出并重新启动终端这是为了确保它重新加载您刚刚所做的更改。

      重启终端后,尝试运行 psql。

      psql -U postgres

      你应该得到以下输出。

      psql (9.6.0)

      Type "help" for help.

      postgres=#

      您可以在https://www.calhoun.io/how-to-install-postgresql-9-6-on-mac-os-x/阅读更多内容

      【讨论】:

      • 但我没有在Applications中安装Postgres.app应用程序,那我怎么能把export PATH和我通过homebrew安装Postgres
      • 如何知道我的 Postgres 运行在哪个端口上,我如何假设它是 5432
      • 使用pg_lscluster 命令或在配置文件postgresql.conf 中查找线路端口
      猜你喜欢
      • 2022-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-13
      • 1970-01-01
      相关资源
      最近更新 更多