CS/Database

[PostgreSQL] Mac M1 Postgres 실행 에러 해결_ Failure while executing; `/bin/launchctl bootstrap gui/501 /Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist` exited with 5.

kth990303 2023. 2. 8. 16:29
반응형

오랜만에 아래 명령어로 PostgreSQL를 실행하려는데 아래 에러를 만났다.

 

Postgresql 실행 시

brew services start postgresql@14

Error: Failure while executing

Bootstrap failed: 5: Input/output error
Try re-running the command as root for richer errors.
Error: Failure while executing; `/bin/launchctl bootstrap gui/501 /Users/kth990303/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist` exited with 5.

 

psql 쉘 실행 시 

혹시나 싶어 psql 쉘을 띄워보려 해도 아래 에러가 발생했다.

psql postgres

 

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?

 

 

애플리케이션 실행 시

Unable to connect to the database.

[Nest] 11550  - 2023. 02. 08. 후 3:39:29   ERROR [TypeOrmModule] Unable to connect to the database. Retrying (2)...
Error: connect ECONNREFUSED 127.0.0.1:5432
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)

 

....

- postgresql을 삭제하고 재설치해봐도 안되고...

- 버전 명시하지 않고 설치해서 안되는건가 싶어 postgresql@14로 버전 명시하고 설치해도 안되고...

- 에러뜬대로 /Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist 파일에 문제가 있는건가 싶어 해당 관련 설정을 해줘도 안되고...

- 구글링 결과 /usr/bin/var ... 절대경로에서 특정 파일을 삭제하라고 하는데 bin 폴더가 없어서 또 삽질하고...

- 어찌어찌 잘 찾았다 하더라도 postgres.conf 파일에서 권한 설정하면 해결되려나? 싶어 했는데 안돼서 또 삽질하고...

 

정말 힘들었는데 해결방법은 정말 간단했다.

이 해결방법 역시 구글링으로 찾긴 했지만, 너무나도 고통스러웠기 때문에 기록해보려한다.


해결방법

1. 아래 명령어로 해당 폴더 접속

cd /opt/homebrew/var/postgresql@14

Mac M1은 var 폴더가 `/usr/bin`이 아닌 `/opt/homebrew`에 있다는 점을 기억해둬야 될듯하다.

항상 헷갈린다..

 

2. postmaster.pid 삭제

rm -f postmaster.pid

해당 에러는 postmaster.pid 파일 정보가 손상되거나 잘못돼서 발생한다고 한다.

postmaster.pid 파일은 postgresql 실행 시에 없는 경우, 문제 없이 생성된다.

따라서 postmaster.pid 파일을 걱정없이 지워주도록 하자.

 

참고로, Postmaster.pid 파일은 postgresql의 클러스터 정보, 포트 및 listen-address 관련 정보를 담고 있다고 한다.

 

3. 재실행

brew services start postgresql@14
psql postgres

문제없이 잘 실행된다

나의 경우는 이렇게 해서 문제가 해결됐다.

애플리케이션 실행도 문제없이 잘 진행됐다.

 

왜 에러는 하필 /Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist 파일에 문제가 있다고 말하는거야 헷갈리게...

또 /bin/launchctl bootstrap gui/501 문제라길래 Http Status 501 생각나서 서버문젠가? 삽질하기도 하고... 진짜 짜증났었다ㅋㅋㅋ

 

이 글이 해당 에러를 겪는 분들에게 도움이 되길...

 

 

참고자료

반응형