[Error] 맥북 껐다 켰더니 postgreSQL 실행이 안 되는데요 (postgreSQL error 256)

subbni·2024년 10월 7일
post-thumbnail

발단

평소에 거의 끄지 않고 sleep 상태로 사용해오던 m1 맥북을 오랜만에 끄고 휴식을 취하게 해주었다

그리고 다음 날 .. 하던 프로젝트를 계속하려고 postgreSQL을 실행시키는데 오류를 뱉으며 실행 되질 않는다 ㅎ

오류는 다음과 같았다

connection failed: connection to server at "127.0.0.1", port 5432 failed: could not receive data from server: connection refused

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/osubin/library/launchagents/homebrew.mxcl.postgresql@14.plist exited with 5.

또한 brew services를 통해서 확인해보니
postgresql@14가 error 256로 실행이 되지 않고 있었다

해결 못 한 (그러나 누군가에겐 해결법일 수 있는) 방법

구글링을 해보니 (m1의 경우) /opt/homebrew/var/postgresql@14/postmaster.pid, (그 외) /usr/bin/var/postgresql@14/postmaster.pid 를 삭제하고 다시 재시작하면 된단다.

삭제 명령어
rm /opt/homebrew/var/postgresql@14/postmaster.pid

하지만 이 방법은 나에겐 먹히지 않았다
삭제한 후에 재시작을 해봐도 똑같이 256 오류로 시작이 되질 않았다.

해결 방법

뭐가 문젠지 확인하기 위해 postgreSQL의 서비스 로그를 확인하였다.

로그 파일 위치 확인

로그 파일의 위치는
1. brew services 명령어를 통해 postgresql@14.plist의 위치를 알아낸다.
2. 해당 위치의 plist 파일을 열면 log 파일의 위치가 나온다.
(참조 블로그)

아래는 postgresql@14.plist 파일 안의 내용이다.

... 중략
<key>RunAtLoad</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/opt/homebrew/var/log/postgresql@14.log</string>
	<key>StandardOutPath</key>
	<string>/opt/homebrew/var/log/postgresql@14.log</string>
	<key>WorkingDirectory</key>
	<string>/opt/homebrew</string>
</dict>
</plist>

error와 output이 /opt/homebrew/var/log/postgresql@14.log에 저장되고 있음을 확인할 수 있다.

로그 확인

로그 파일을 확인해보니 다음과 같이 로그가 찍혀있었다.

2024-10-07 14:58:59.374 KST [7573] LOG:  listening on IPv6 address "::1", port 5432
2024-10-07 14:58:59.374 KST [7573] LOG:  listening on IPv4 address "127.0.0.1", port 5432
2024-10-07 14:58:59.375 KST [7573] LOG:  listening on Unix socket "/tmp/.s.PGSQL.5432"
2024-10-07 14:58:59.376 KST [7573] LOG:  invalid authentication method "0.0.0.0/0"
2024-10-07 14:58:59.376 KST [7573] CONTEXT:  line 96 of configuration file "/opt/homebrew/var/postgresql@14/pg_hba.conf"
2024-10-07 14:58:59.376 KST [7573] FATAL:  could not load pg_hba.conf
2024-10-07 14:58:59.376 KST [7573] LOG:  database system is shut down

configuration file인 pg_hba.confinvalid authentication method "0.0.0.0/0"가 존재해서 could not load 하단다 .. 난 만진 적도 없는데

pg_hba.conf 확인

실제로 0.0.0.0/0이 존재하는 라인을 확인했다 ㅎ

이제 이걸 어떻게 고칠까?

pg_hba.conf 수정

local replication all 0.0.0.0/0 trust
문제가 되는 라인이다.

  • local: 서버에서 PostgreSQL에 접속하는 로컬 클라이언트에 관한 설정임
  • replication : 복제를 위한 연결을 허용
  • all : 복제 연결을 위한 '모든' 사용자를 허용
  • 0.0.0.0/0 : 모든 IPv4 주소 범위를 의미
  • trust : 클라이언트가 비밀번호 없이 db 접속 허용, 즉 인증 없이 접속 허용

일단 결과적으로는 0.0.0.0/0 을 그냥 삭제해버리면 된다.

사실 처음 postgreSQL을 설정할 때 pg_hba.conf 파일을 초기 설정하면서 만졌던 기억이 있는데(결국 만진 적 있었던 거임) 그 때 설정값을 잘못 넣었던 것 같다.

local 설정이라 IP 범위 제한이 필요하지 않음에도 불구하고 들어가 있으니 잘못된 설정이라 오류를 뱉었던 것으로 예상된다 ㅠ

완전 초기에 했던 설정이라 그동안은 왜 쌩쌩 잘 돌아갔는지 이해가 살짝 안 가긴 하지만요 ?

해결

어쨌거나 해결 완료 ✅

결국 모든 에러 해결 방법은 ....

  1. log 파일 위치를 알아낸다.
  2. 에러 로그를 확인한다.
  3. 로그에 맞는 해결책을 적용한다.
profile
개발콩나물

4개의 댓글

comment-user-thumbnail
2024년 10월 12일

댓글 작성 후 삭제 했는데도 1개의 댓글이 있다고 뜨는 오류 발견 +_+

답글 달기
comment-user-thumbnail
2025년 5월 14일

덕분에 오류 해결했습니다ㅠㅠㅠㅠ 감사합니다!

1개의 답글