postgresql을 예전에 설치해놓고 오랜만에 사용하려고 접근을 시도하려고 한 삽질 메모..

$ psql postgresql
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?
postgresql 디비에 접근하는 psql postgresql 명령어를 사용하여 디비에 접근하려고 했지만
서버가 안켜져 있다는 에러메시지를 받고
postgresql 의 status를 확인하였다.
$ brew services list
아래 이미지와 같이 status가 error로 표시되었다.

그 후 시도한 방법은 postgresql의 status가 정상으로 돌아오게 하기 위해 업데이트와 재시작을 하였다.
$ brew postgresql-upgrade-database
$ brew services restart postgresql
하지만 동일하게 status가 여전히 error로 떠서 재삭제와 재설치를 진행하였다.
brew uninstall postgresql@14
brew install postgresql@14
brew services restart postgresql
하지만 또 같이 status가 error로 뜨고 있어서 여러 구글링을 통해
pid 파일을 삭제하였고
rm /usr/local/var/postgres/postmaster.pid
그래도 동작하지 않아
/usr/local/var/postgres/ 파일 자체를 삭제하고 재설치하였는데도 동일하였다.
왜 그런지 이유를 찾기 위해 로그파일이 있는 걸 발견하고 로그파일을 확인하였다.
해당 명령어로 로그파일에는 No such file or directory 라는 명령어가 찍혀있었고 설치할 때 뒤에 @14를 지정하여 설치해서 그런것으로 판단되어 brew install postgresql를 통해 해결하였다..
tail -f /usr/local/var/log/postgresql@14.log
postgres: could not access directory "/usr/local/var/postgresql@14": No such file or directory
Run initdb or pg_basebackup to initialize a PostgreSQL data directory.

---
brew uninstall postgresql
brew install postgresql
brew services restart postgresql
brew services list

다시 삭제 및 재설치를 하고 정상적으로 동작하는 것을 확인 하였고
postgresql에서 default로 생성해주는 계정으로 접근하였다.
psql postgres
글 잘 봤습니다.