Install postgresql@14 on M1 Mac with Homebrew

First step

Copy
brew install postgresql@14
brew services restart postgresql@14

psql postgres

If everything works, congratulations! Now close this tab and enjoy your life. If not, please continue reading.

Debugging

In M1 Mac, brew services log exists in the following path.

Copy
cat /opt/homebrew/var/log/postgresql@14.log

Checking the log here, and it says:

Copy
postgres: could not access directory "/opt/homebrew/var/postgresql@14": No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.

Okay, seems like our database is missing. Let's create one at the expected directory.

Copy
initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@14
brew services restart postgresql@14

Now everything should work.

In case you need a database user.

Copy
/opt/homebrew/bin/createuser -s <username>

psql -U <username>

## and in the psql shell, run \password to set a password
postgres=# \password