I have installed Postgresql in my M2 macOS with the following commands:
brew update
brew install postgresql
brew services start postgresql
When I want to interact with the database through psql postgres
, it shows this error:
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: Connection refused
Is the server running locally and accepting connections on that socket?
Previously, I have installed homebrew
following these:
# We'll be installing Homebrew in the /opt directory.
cd /opt
# Create a directory for Homebrew. This requires root permissions.
sudo mkdir homebrew
# Make us the owner of the directory so that we no longer require root permissions.
sudo chown -R $(whoami) /opt/homebrew
# Download and unzip Homebrew. This command can be found at https://docs.brew.sh/Installation.
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew
# Add the Homebrew bin directory to the PATH. If you don't use zsh, you'll need to do this yourself.
echo "export PATH=/opt/homebrew/bin:$PATH" >> ~/.zshrc
When running tail -n 10 /opt/homebrew/var/log/postgresql@14.log
, I got this:
2023-08-28 06:35:08.394 -05 [55304] LOG: starting PostgreSQL 14.9 (Homebrew) on aarch64-apple-darwin22.4.0, compiled by Apple clang version 14.0.3 (clang-1403.0.22.14.1), 64-bit
2023-08-28 06:35:08.412 -05 [55304] LOG: listening on IPv6 address "::1", port 5432
2023-08-28 06:35:08.413 -05 [55304] LOG: listening on IPv4 address "127.0.0.1", port 5432
2023-08-28 06:35:08.414 -05 [55304] FATAL: could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied
2023-08-28 06:35:08.415 -05 [55304] LOG: database system is shut down
2023-08-28 06:35:18.558 -05 [55445] LOG: starting PostgreSQL 14.9 (Homebrew) on aarch64-apple-darwin22.4.0, compiled by Apple clang version 14.0.3 (clang-1403.0.22.14.1), 64-bit
2023-08-28 06:35:18.559 -05 [55445] LOG: listening on IPv6 address "::1", port 5432
2023-08-28 06:35:18.559 -05 [55445] LOG: listening on IPv4 address "127.0.0.1", port 5432
2023-08-28 06:35:18.560 -05 [55445] FATAL: could not open lock file "/tmp/.s.PGSQL.5432.lock": Permission denied
2023-08-28 06:35:18.561 -05 [55445] LOG: database system is shut down
I would like to know how to successfully install Postgresql in M2 macOS.