2

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?

Jake
  • 1,086
  • 12
  • 38
swaff-y
  • 21
  • 1
  • 4

2 Answers2

4

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 ✔, 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
Simba
  • 23,537
  • 7
  • 64
  • 76
  • user commands To start: `pg_ctl -D /opt/homebrew/var/postgres start` To stop: `pg_ctl -D /opt/homebrew/var/postgres stop` – Steven Dec 05 '21 at 06:57
0

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

tiltowait
  • 100
  • 1
  • 7