【问题标题】:Postgres does not know where to find the server configuration file. After "brew install postgresql"Postgres 不知道在哪里可以找到服务器配置文件。在“brew install postgresql”之后
【发布时间】:2021-08-11 16:31:37
【问题描述】:

我已经使用 brew install postgresql 在 MacOS Big Sur 11.3 版上安装了 PostgreSQL。

当我运行postgres 命令时,我得到了这个错误

postgres does not know where to find the server configuration file.`
You must specify the --config-file or -D invocation option or set the PGDATA environment variable.

在哪里可以找到配置文件?

【问题讨论】:

标签: postgresql macos homebrew


【解决方案1】:

在我的 Mac (Big Sur) 上,它位于 /usr/local/var/postgres/postgresql.conf。我用来启动服务器的命令是:

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

【讨论】:

  • 我试过了,我得到:pg_ctl: directory "/usr/local/var/postgres" 不存在
【解决方案2】:

通过brew cat postgresql检查包公式postgresql.rb,数据目录为${HOMEBREW_PREFIX}/var/postgres。 (HOMEBREW_PREFIX 不是导出的 env var,它由 homebrew 内部使用)

  • /usr/local/var/postgres 在 x86 Mac 上
  • /opt/homebrew/var/postgres 在 M1 Mac 上

这个目录应该在brew install postgresql期间自动创建。

顺便说一句,使用 Homebrew 启动 psql 的规范方法应该是 brew services start postgresql,它在 macOS 上使用 launchd 来管理服务。 (对于 macOS 上的新手,launchd 可以被视为 macOS 上的systemd 替代方案。)

运行brew info postgresql,一些额外的提示会显示在输出的Caveats 部分。

❯ brew info postgresql
postgresql: stable 13.3 (bottled), HEAD
Object-relational database system
https://www.postgresql.org/
/usr/local/Cellar/postgresql/13.3 (3,225 files, 38.8MB) *
  Poured from bottle on 2021-05-14 at 09:37:24
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/postgresql.rb
License: PostgreSQL
==> Dependencies
Build: pkg-config ✔
Required: icu4c ✔, krb5 ✔, openssl@1.1 ✔, readline ✔
==> Options
--HEAD
        Install HEAD version
==> Caveats
To migrate existing data from a previous major version of PostgreSQL run:
  brew postgresql-upgrade-database

This formula has created a default database cluster with:
  initdb --locale=C -E UTF-8 /usr/local/var/postgres
For more details, read:
  https://www.postgresql.org/docs/13/app-initdb.html

To have launchd start postgresql now and restart at login:
  brew services start postgresql
Or, if you don't want/need a background service you can just run:
  pg_ctl -D /usr/local/var/postgres start

【讨论】:

  • 用户命令 开始:pg_ctl -D /opt/homebrew/var/postgres start 停止:pg_ctl -D /opt/homebrew/var/postgres stop
猜你喜欢
  • 2018-05-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-19
  • 2011-02-10
  • 2021-12-06
  • 1970-01-01
  • 2015-03-31
  • 2021-10-04
相关资源
最近更新 更多