Install

brew install postgresql@14

👉 brew postgresql@14

설치 로그

╭─    ~ ─────────────────────────────────────────────────────────────────────────────────────────────────── ✔  5s   base 
╰─ brew install postgresql@14
==> Downloading https://formulae.brew.sh/api/formula.jws.json
########################################################################################################################## 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
########################################################################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/14/manifests/14.11_1
Already downloaded: /Users/swd/Library/Caches/Homebrew/downloads/cc5ce32be3ad755d6853a306c7d20db8221cceaa63708acb1937567a4ab65fda--postgresql@14-14.11_1.bottle_manifest.json
==> Fetching postgresql@14
==> Downloading https://ghcr.io/v2/homebrew/core/postgresql/14/blobs/sha256:d49e8b487d6b7e696e74ebf7d0bddbb9b8c343d7861d760a39f0a
Already downloaded: /Users/swd/Library/Caches/Homebrew/downloads/695bc5763b3ab3f65140681669c474e2b18ff40d6ff809534e5436f2105b6d90--postgresql@14--14.11_1.arm64_sonoma.bottle.tar.gz
==> Pouring postgresql@14--14.11_1.arm64_sonoma.bottle.tar.gz
==> Caveats
This formula has created a default database cluster with:
  initdb --locale=C -E UTF-8 /opt/homebrew/var/postgresql@14
For more details, read:
  https://www.postgresql.org/docs/14/app-initdb.html

To start postgresql@14 now and restart at login:
  brew services start postgresql@14
Or, if you don't want/need a background service you can just run:
  /opt/homebrew/opt/postgresql@14/bin/postgres -D /opt/homebrew/var/postgresql@14
==> Summary
🍺  /opt/homebrew/Cellar/postgresql@14/14.11_1: 3,319 files, 46MB
==> Running `brew cleanup postgresql@14`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

로그를 잘 보면 아래의 정보를 얻을 수 있다.

postgresql 설치 파일이 있는 경로

/Users/<>/Library/Caches/Homebrew/downloads/695bc5763b3ab3f~

postgresql 이 설치된 물리적 경로

/opt/homebrew/Cellar/postgresql@14/

service 시작/정지

brew services start postgresql@14
brew services stop postgresql@14
/opt/homebrew/opt/postgresql@14/bin/postgres -D /opt/homebrew/var/postgresql@14

uninstallation

# PostgreSQL 서비스를 중지
brew services stop postgresql@14

# PostgreSQL을 제거
brew uninstall postgresql@14

# 여기서 opt 폴더는 경로 최상단 root에 숨김 처리 되어있는 폴더
# cmd + shift + . 로 숨김 폴더와 파일 확인 가능
rm -rf /opt/homebrew/var/postgresql@14

# 필요한 경우 PostgreSQL 관련 설정 파일 및 사용자/그룹을 제거
rm -rf /usr/local/etc/postgres*
sudo dscl . -delete /Users/postgres
sudo dscl . -delete /Groups/postgres

# 마무리
brew cleanup

접속

psql

접속 TroubleShooting

psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory
Is the server running locally and accepting connections on that socket?

# 아래의 명령어로 실행시켜주자.
실행: brew services start postgresql@14
psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" failed: FATAL:
database "<user>" does not exist

# 정확한 원인은 모르겠으나, 처음 설치 후 사용하다가 지웠다가 다시 설치했을 때 이런 일이 발생하였다.

# 해결방법
# 1. 아래의 명령어로 template1 DB에 접속. template1은 postgres가 기본적으로 생성하는 DB이다.
psql -d template1

# 2. 위의 명령어로 접속이 잘 된다면, 다시 \q 로 빠져나와 터미널에서 아래의 명령어를 실행한다.
# psql 접속한 상태로 아래의 명령어를 실행하면 안된다.
createdb <user>

# 3. 다시 접속
psql or psql -h localhost

# 4. 성공!

Last updated