Note

Install postgresql@14 on M1 Mac with Homebrew

First step

brew install postgresql<at-mention handle="14">@14
</at-mention>brew services restart postgresql<at-mention handle="14">@14
</at-mention>
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.

cat /opt/homebrew/var/log/[email protected]

Checking the log here, and it says:

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.

initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql<at-mention handle="14">@14
</at-mention>brew services restart postgresql<at-mention handle="14">@14
</at-mention>```

Now everything should work.

In case you need a database user.

```bash
/opt/homebrew/bin/createuser -s <username>

psql -U <username>

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

0
0
...
...
...
Avatar