Development Tip

Homebrew postgres 깨진

yourdevel 2020. 11. 29. 12:20
반응형

Homebrew postgres 깨진


homebrew를 사용하여 Mac (10.10.1 / Yosemite)에 Postgresql 9.4.0을 설치했습니다. 작동하지 않습니다.

~ / Library / LaunchAgents에서 /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist에 대한 소프트 링크를 만들었습니다.

postgres를 수동으로로드하려고하면 "Operation is in progress"라는 메시지가 나타납니다.

> launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
/usr/local/Cellar/postgresql/9.4.0/homebrew.mxcl.postgresql.plist: Operation already in progress

그러나 postgres는 실행되지 않는 것 같습니다.

> ps auxw | grep post
billmcn           670   0.0  0.0  2424272    452 s000  R+   10:12PM   0:00.01 grep post

명령 줄 클라이언트와 연결할 수 없습니다.

> psql
psql: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

내 지식으로 나는 이 문제를 논의 하는 다른 Stackoverflow 스레드 에서 제안 된 모든 수정을 시도했습니다 . 구체적으로 특별히:

  • postgres와 함께 제공되는 Ruby gem을 제거하고 다시 설치했습니다. 내 컴퓨터에 postgres 8.0 버전이 없습니다.
  • psql 클라이언트 프로그램이 Mac 시스템 바이너리가 아니라 Homebrew에서 설치 한 9.4.0 버전임을 확인했습니다.
  • /usr/local/var/postgres/postmaster.pid가 존재하지 않음을 확인했습니다.
  • 컴퓨터를 재부팅했습니다.

이전에이 컴퓨터에서 Homebrew postgres를 사용했습니다. 나는 그것이 버전 8에서 버전 9로 업그레이드하는 것이라고 생각하지만 확실하지 않습니다.

보존해야 할 데이터베이스가 없습니다. 나는 postgres로 깨끗하게 시작할 의향이 있습니다. 지금 작동하도록하면됩니다. 어떤 아이디어?


문제는 / usr / local / var / postgres 디렉토리에 대한 권한 인 것으로 보입니다. 다음은 일이 작동하지 않을 때 내 var 디렉토리가 어떻게 생겼는지입니다.

ll /usr/local/var/
drwxr-xr-x  3 billmcn  admin  102 Dec 20 12:44 cache
drwxr--r--  2 root     admin   68 Dec 29 21:37 postgres

(whoami = "billmcn")

/ usr / local / var / postgres를 삭제하고 postgres를 제거했다가 다시 설치했는데 이제 다음과 같이 보입니다.

ll /usr/local/var/
drwxr-xr-x   3 billmcn  admin  102 Dec 20 12:44 cache
drwx------  23 billmcn  admin  782 Dec 30 10:51 postgres

이 디렉토리에 대한 권한을 다룬 기억이 없기 때문에 어떻게이 상태가되었는지 확실하지 않지만 상관 없습니다. 이제 작동합니다.


새로 설치된 Yosemite에서 homebrew를 사용하여 postgres를 설치하는 데 동일한 문제가 발생했습니다.

먼저 내 양조 구성은 다음과 같습니다.

HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew
HEAD: 9f6926265f8e4be7cc80dfe9042f2cd3c1e8dc9e
Last commit: 64 minutes ago
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit sandybridge
OS X: 10.10.1-x86_64
Xcode: 6.1.1
Clang: 6.0 build 600
X11: N/A
System Ruby: 2.0.0-481
Perl: /usr/bin/perl
Python: /usr/bin/python
Ruby: ~/.rvm/rubies/ruby-2.1.1/bin/ruby

가장 먼저 눈에 띄는 것은에 대한 쓰기 권한이 없다는 것 /usr/local/var/postgres입니다. 이것은 쉽게 변경된 sudo chown -R `whoami` /usr/local/var/postgres다음 postgresql을 다시 설치하고

cat /usr/local/var/postgres/server.log

공개 된 :

postgres cannot access the server configuration file "/usr/local/var/postgres/postgresql.conf": No such file or directory

그래서 디렉토리를 제거 /usr/local/var/postgres하고 데이터베이스를 초기화하는 명령을 내 렸습니다.

initdb -D /usr/local/var/postgres/

이것은 트릭을 수행 한 것처럼 보였고 postgres는 잘 실행되고 있습니다.


나는 이와 같은 문제가 있었다. 여기서 가장 큰 문제는 설치의 initdb 단계에서 Mac의 사용자가 아닌 루트 소유권으로 디렉토리를 생성한다는 것입니다. 이 문제를 해결하려면 :

실행하기 전에 데이터 디렉터리를 initdb만들고 0700의 권한을 설정합니다.

rm -rf /usr/local/var/postgres  # in case this is not your first try
mkdir /usr/local/var/postgres
chmod 0700 /usr/local/var/postgres

그런 다음 실행 initdb하면 데이터 디렉토리의 권한이 적용됩니다.

initdb -D /usr/local/var/postgres

For grins and giggles, create a test db named after your user:

createdb `whoami`

Login to test:

psql

After trying to install postgresql with Homebrew, I got this:

Warning: postgresql-9.5.2 already installed, it's just not linked

So I tried:

brew link postgresql

And got this error:

Linking /usr/local/Cellar/postgresql/9.5.2... 
Error: Could not symlink share/man/man3/SPI_connect.3
/usr/local/share/man/man3 is not writable.

It seemed to be a write permission matter, so I did:

sudo chown -R `whoami` /usr/local/share/man/

It did the trick because, then I was able to do (without error):

brew link postgresql

Please note that their is a thread on Homebrew's github dealing with this issue: https://github.com/Homebrew/homebrew/issues/35240


I have had a similar issue. James answer helped me solve it. But I then ran into the issue jbk is mentioning (after having deleted /usr/local/var/postgres, it kept on being recreated).

The issue is that if you have created the symlink:

ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents

and launched the process:

launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

you should first unload it:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

before running James's commands.

rm -rf /usr/local/var/postgres  # in case this is not your first try
mkdir /usr/local/var/postgres
chmod 0700 /usr/local/var/postgres

In addition, if, like me, you have an admin user managing homebrew and a regular user who will be using pgsl for development purpose, James command should be run as super user:

sudo -s

and ownership over the postgres directory should be given to your dev user:

chown my-dev-user /usr/local/var/postgres

The following command, run as the dev user, should then properly populate the directory:

createdb `whoami`

Running:

psql -l

should show you the tables and user permissions in postgre after such manipulations.

Hope this helps.


In case anyone upgraded from a previous version, dont forget to:

brew postgresql-upgrade-database

That will solve the problem by upgrading your existing databases to the version you upgraded postgres to.


Check @leo_chaz_maltrait for fixing errors the error Could not symlink share/man/man3/SPI_connect.3 Another error that might show up is:

Error: Could not symlink lib/pkgconfig/libecpg.pc

sudo chown -R `whoami` /usr/local/lib/pkgconfig

brew link postgresql

For posterity, I had this issue and wanted to note what worked for me.

I am running postgres 11.2 on High Sierra. I had recently upgraded from postgres 10 with brew postgresql-upgrade-database.

I kept getting the error psql: could not connect to server: No such file or directory, and my server.log indicated is another postmaster (PID 5894) running in data directory "/usr/local/var/postgres"?

I tried several solutions including restarting my computer, deleting postmaster.pid, using brew services restart postgres, but to no avail. I eventually stumbled on the solution:

brew unlink postgresql && brew link postgresql

No idea why this worked, but putting it here mostly so I can reference it myself in the future! Throw stuff at the wall till it sticks!

참고URL : https://stackoverflow.com/questions/27700596/homebrew-postgres-broken

반응형