swaff-y
swaff-y

Reputation: 21

Postgres does not know where to find the server configuration file. After "brew install postgresql"

I have installed PostgreSQL on MacOS Big Sur version 11.3 with brew install postgresql.

When I run the postgres command I get this error

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.

Where do I find the config file?

Upvotes: 2

Views: 6293

Answers (2)

Simba
Simba

Reputation: 27588

Checking from the package formula postgresql.rb by brew cat postgresql, the datadir is ${HOMEBREW_PREFIX}/var/postgres. (HOMEBREW_PREFIX is not an exported env var, it's used by homebrew internally)

  • /usr/local/var/postgres on x86 Mac
  • /opt/homebrew/var/postgres on M1 Mac

This dir should be created automatically during brew install postgresql.

BTW, the canonical way to start psql with Homebrew should be brew services start postgresql, which uses launchd on macOS to manage services. (For newbie on macOS, launchd could be seen as a systemd alternative on macOS.)

Run brew info postgresql and some additional tips is displayed in the Caveats part of the output.

❯ 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 ✔, [email protected] ✔, 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

Upvotes: 5

tiltowait
tiltowait

Reputation: 110

On my Mac (Big Sur), it's located at /usr/local/var/postgres/postgresql.conf. The command I use to start the server is:

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

Upvotes: 0

Related Questions