Brew 서비스를 통해 실행되는 Postgres 서버에 연결할 수 없습니다.


86

나는 이것에 대한 해결책을 찾고 있었지만 작동하는 해결책을 찾을 수 없었습니다.

brew install postgresMacBook에 brew ( )를 사용하여 postgres를 설치 했으며 현재 brew 서비스를 사용하여 실행 중입니다 ( brew services list postgres를 실행중인 서비스로 표시). 그러나 실행하려고 psql하면 다음과 같은 오류가 발생합니다.

psql : 서버에 연결할 수 없음 : 해당 파일 또는 디렉토리가 없습니다. 서버가 로컬에서 실행 중이고 Unix 도메인 소켓 "/tmp/.s.PGSQL.5432"에서 연결을 수락합니까?

누구나 이미 비슷한 문제를 해결 했습니까?

답변:


199

동일한 오류가 발생하여 프로세스 pid 파일을 제거하여 수정했습니다.

rm -f /usr/local/var/postgres/postmaster.pid


감사합니다, 작동합니다! 그런데 왜? 어떻게? 다시 시작할 때마다이 명령을 실행 했습니까?
— rap-2-h

14
@ rap-2-h Postgres가 제대로 종료되지 않는 것 같습니다. 전원 버튼을 길게 눌러 Mac을 종료해야 할 때이 문제가 발생합니다.
— Wilson Silva

6
특정 버전의 통 (예 : postgresql@9.6)을 사용하는 경우 "/ postgres /"대신 올바른 폴더를 사용해야합니다.
— Vjatseslav Gedrovits

1
실제로 이것은 macOS에서 postgres가 제대로 종료되지 않는 것과 관련이 있지만 저에게는 Apple 메뉴 + "종료 ..."옵션을 사용했을 때도 발생했기 때문에 강제 종료와 특별히 관련이 없습니다 (적어도 더 이상, macOS 10.14.3). 이 문제가 해결되었습니다. 엄지 손가락 (y)
— SidOfc

1
그래도 작동하지 않으면을 시도하십시오 tail /usr/local/var/log/postgres.log. 이것은 postgres가 실패하는 정확한 이유에 대한 자세한 정보를 제공 할 수 있습니다. 일반적으로 해당 로그인의 오류 메시지를 Google에 게시하고 StackOverflow에서 다른 수정 사항을 찾을 수 있습니다.
— -D

92

오늘이 문제가 발생했습니다. postgres는 homebrew가 실행 중이라고 생각했지만 연결 수락을 중지했습니다.

그것을 고치기 위해 나는 달렸다.

brew services restart -vvv postgresql

이 명령의 출력,

==> Successfully stopped `postgresql` (label: homebrew.mxcl.postgresql)
==> Generated plist for postgresql:
   <?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
   <plist version="1.0">
   <dict>
     <key>KeepAlive</key>
     <true/>
     <key>Label</key>
     <string>homebrew.mxcl.postgresql</string>
     <key>ProgramArguments</key>
     <array>
       <string>/usr/local/opt/postgresql/bin/postgres</string>
       <string>-D</string>
       <string>/usr/local/var/postgres</string>
     </array>
     <key>RunAtLoad</key>
     <true/>
     <key>WorkingDirectory</key>
     <string>/usr/local</string>
     <key>StandardErrorPath</key>
     <string>/usr/local/var/log/postgres.log</string>
   </dict>
   </plist>

그런 다음 저는 그 로그 파일에 뭔가가있을 수 있다고 생각했습니다.

tail -n 10 /usr/local/var/log/postgres.log

물론입니다.

[4826] FATAL:  lock file "postmaster.pid" already exists
[4826] HINT:  Is another postmaster (PID 1489) running in data directory "/usr/local/var/postgres"?

그래서 그 파일을 제거했습니다

rm /usr/local/var/postgres/postmaster.pid

그리고 모든 것이 다시 작동하기 시작했습니다.


9
나에게 가장 유용한 명령이었다tail -n 10 /usr/local/var/log/postgres.log
— 닉 로즈

41

제 경우에는 postmaster.pid파일이 없었습니다. postgres를 업그레이드하여 작동했습니다.

brew update
brew upgrade

그런 다음 메이저 버전을 10에서 11로 업그레이드했기 때문에 다음을 실행해야했습니다.

brew postgresql-upgrade-database

(출처 https://github.com/facebook/react-native/issues/18760#issuecomment-410533581 )


3
이 경우 /usr/local/var/log/postgres.log파일은 다음과 같은 마지막 몇 개의 로그를 가질 수 있습니다. FATAL: database files are incompatible with server DETAIL: The data directory was initialized by PostgreSQL version 11, which is not compatible with this version 12.2.
— dijonkitchen

이 정확한 문제가 있습니다. postgresql 11에서 12 로의 업그레이드는 실패했지만 제거하고 다시 설치하는 것이 도움이되었습니다.
— FooF

16

여기서 Wilson과 Grasshopper의 두 답변을 결합합니다.

postgres 서비스에 대한 plist 파일을 확인하여 파일 brew services list의 위치를 ​​찾고 즐겨 찾는 편집기에서 열 수 있습니다.

StandardErrorPath다음과 같이 나열된 값이 표시 되어야합니다 .

<key>StandardErrorPath</key>
<string>/usr/local/var/log/postgres.log</string>

그런 다음 다음을 사용하여 로그 파일의 끝을 마무리해야합니다. tail -n 100 /usr/local/var/log/postgres.log

제 경우 오류는 다음과 같습니다.

2017-12-06 11 : 51 : 16.078 GMT [85476] FATAL : 잠금 파일 "postmaster.pid"가 이미 존재합니다. 2017-12-06 11 : 51 : 16.078 GMT [85476] 힌트 : 다른 포스트 마스터 (PID 601)가 실행 중입니까? 데이터 디렉토리 "/ usr / local / var / postgres"?

Mac을 강제 종료해야했고 postgres가 PID 파일을 정리할 기회가 없었기 때문입니다. PID 파일을 제거하고 rm /usr/local/var/postgres/postmaster.pidpostgres를 시작하십시오.brew services start postgresql

경고 : postgres가 실행되고 있지 않다고 확신하지 않는 한이 PID 파일을 삭제하지 마십시오 . 실행 brew services stop postgresql한 다음 brew services listposgres가 중지 된 상태임을 표시 하는 결과를 기다리면됩니다.


5

나를 위해 일한 것은 /usr/local/var/postgres/폴더를 제거한 다음 postgres를 다시 제거하고 설치 하는 것이 었 습니다.


8
이 작업을 수행하기 전에 다른 응답을 시도해야합니다.
— Jean

3

버전 탭에서 postgresql93을 설치하는 것과 동일한 오류가 발생했습니다. brew services list( ~/Library/LaunchAgents/homebrew.mxcl.postgresql93.plist) 의 출력에 표시된 .plist 파일을 검사하면 다음 메시지가 표시됩니다.

치명적 : 데이터 디렉토리 "/ usr / local / var / postgres"에 그룹 또는 월드 액세스
권한이 있습니다. DETAIL : 권한은 u = rwx (0700)이어야합니다.

이 대답을하게 된 이유 : 데이터 디렉토리 "/ usr / local / var / postgres"에 잘못된 소유권이 있습니다.

실행 후 sudo chmod -R 700 /usr/local/var/postgres다른 오류가 발생했습니다.

치명적 : "pg_tblspc"디렉토리를 열 수 없음 : 해당 파일 또는 디렉토리가 없습니다.

그런 다음 나를 이끌었습니다 : 최신 버전의 OS X (Yosemite 또는 El Capitan) 설치 후`pg_tblspc`가 누락되었습니다.

실행 mkdir /usr/local/var/postgres/pg_tblspc/후 클러스터가 성공적으로 시작되었습니다.


3

여러 버전의 postgresql이 설치된 경우. 아래 언급 된 명령은 프로세스 id (pid)를 제거하고 다시 시작하는 작업을 수행합니다. 올바른 버전을 선택했는지 확인하십시오.

rm -f /usr/local/var/postgresql@9.6/postmaster.pid

brew services restart postgresql@9.6   

Eric Corner의 답변을 참조하여 문제가 로그 파일의 "잠금 파일 postmaster.pid가 이미 존재 함"에 관한 것인지 확인하십시오.


1

명령을 사용하여 업데이트

  brew postgresql-upgrade-database

다음과 같은 오류가있는 경우 'brew'명령을 찾을 수 없지만 다음과 함께 설치할 수 있습니다. sudo apt install linuxbrew-wrapper

그런 다음 명령을 사용하여 설치하십시오.

 sudo apt install linuxbrew-wrapper

0

제 경우에는 postgres.log파일 HINT: Is another postmaster already running on port 5432? If not, remove socket file "/tmp/.s.PGSQL.5432" and retry.에 소켓 파일을 제거하고 다시 시작한 후 모든 것이 정상적으로 작동했습니다. 이것은 숨겨진 파일이며 창 브라우저를 통해 볼 수 없습니다. 제거는 명령 줄을 통해 수행해야합니다.


0

libssl / libcrypto 버전이 충돌 할 수 있습니다.

brew services start postgres 로그는 나에게 나다를 주었지만 수동으로 시작 pg_ctl -D /usr/local/var/postgres start 했습니다.

/.../openssl/lib/libcrypto.1.0.0.dylib에 정의 _RAND_cleanup 누락

다음을 시도하십시오.

brew tap-new $USER/old-openssl
brew extract --version=1.0.2t openssl $USER/old-openssl
brew install openssl@1.0.2t

# and then either brew link openssl@1.0.2t or symlink the required files to current openssl
ln -s /usr/local/Cellar/openssl/openssl@1.0.2t/lib/libcrypto.1.0.0.dylib /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib
ln -s /usr/local/Cellar/openssl/openssl@1.0.2t/lib/libssl.1.0.0.dylib /usr/local/opt/openssl/lib/libssl.1.0.0.dylib

0

다른 모든 답변이 작동하지 않는 경우 ...

나는이 같은 메시지와 받아 들여진 대답을보고 있었다.

rm -f /usr/local/var/postgres/postmaster.pid

작동하지 않았습니다. 둘 다하지 않았다

rm -f /usr/local/var/postgres@9.6/postmaster.pid 특정 버전이 설치되었다는 것을 기억 한 후에.

나는 cat /usr/local/var/log/postgresql@9.6.log했고 보았다 :

FATAL:  lock file "postmaster.pid" already exists
HINT:  Is another postmaster (PID 1231) running in data directory "/usr/local/var/postgresql@9.6"?
> ps aux|grep 1231
[...] /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/usr/libexec/mobileassetd

** 생각하는 얼굴 **

iOS 시뮬레이터를 닫았습니다. Postgres가 자체적으로 다시 시작되었습니다.

이것은 데스크탑에 있으며 어제 전원이 꺼 졌으므로 다른 답변에 따르면 근본 원인은 물건을 정리할 기회를주지 않고 하드 종료라고 생각합니다.

당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.