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