postgresql 自制的 postgres 坏了

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27700596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:51:54  来源:igfitidea点击:

Homebrew postgres broken

macospostgresqlhomebrew

提问by W.P. McNeill

I installed Postgresql 9.4.0 installed on my Mac (10.10.1/Yosemite) using homebrew. It does not work.

我使用自制软件在 Mac(10.10.1/Yosemite)上安装了 Postgresql 9.4.0。这是行不通的。

I have created the softlink to /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist in ~/Library/LaunchAgents.

我在 ~/Library/LaunchAgents 中创建了指向 /usr/local/opt/postgresql/homebrew.mxcl.postgresql.plist 的软链接。

If I try to manually load postgres I get the message that the "Operation is in progress"

如果我尝试手动加载 postgres,我会收到“操作正在进行中”的消息

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

However postgres does not appear to be running.

但是 postgres 似乎没有运行。

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

and I cannot connect with the command line client.

我无法连接命令行客户端。

> 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"?

To my knowledge I have tried all the fixes suggested on otherStackoverflowthreads discussing this problem. Specifically:

据我所知,我已经尝试了在讨论此问题的其他Stackoverflow线程上建议的所有修复程序。具体来说:

  • I have uninstalled and reinstalled postgres and the accompanying Ruby gem. There is no postgres 8.0 version on my machine.
  • I have verified that the psql client program is the 9.4.0 version installed by Homebrew and not a Mac system binary.
  • I have verified that the /usr/local/var/postgres/postmaster.pid does not exist.
  • I have rebooted the machine.
  • 我已经卸载并重新安装了 postgres 和随附的 Ruby gem。我的机器上没有 postgres 8.0 版本。
  • 我已经验证 psql 客户端程序是 Homebrew 安装的 9.4.0 版本,而不是 Mac 系统二进制文件。
  • 我已经确认 /usr/local/var/postgres/postmaster.pid 不存在。
  • 我已经重新启动了机器。

I did have Homebrew postgres working on this machine earlier. I think what broke it is upgrading from version 8 to version 9 but I'm not sure.

我之前确实有 Homebrew postgres 在这台机器上工作。我认为破坏它的是从版本 8 升级到版本 9,但我不确定。

I don't have any databases I need to preserve. I'm willing to start clean with postgres; I just need to get it to work now. Any ideas?

我没有任何需要保留的数据库。我愿意从 postgres 开始清理;我现在只需要让它工作。有任何想法吗?



The issue appears to have been permissions on the /usr/local/var/postgres directory. Here is what my var directory looked like when things weren't working.

问题似乎是对 /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")

(whoami = "billmcn")

I deleted /usr/local/var/postgres, uninstalled and reinstalled postgres, and now it looks like this.

我删除了/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

Not sure how it got into this state because I don't remember futzing with the permissions on this directory, but no matter. It works now.

不知道它是如何进入这种状态的,因为我不记得对该目录的权限进行了检查,但没关系。它现在有效。

回答by Tom Henrik Aadland

I had the same problem installing postgres using homebrew on a freshly installed Yosemite.

我在新安装的优胜美地使用自制软件安装 postgres 时遇到了同样的问题。

First off my brew config looks like this:

首先,我的 brew 配置如下所示:

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

First thing i noticed was that I had no write permission to /usr/local/var/postgres. This was easily changed issuing sudo chown -R `whoami` /usr/local/var/postgresthen I reinstalled postgresql and did

我注意到的第一件事是我没有写权限/usr/local/var/postgres。这很容易改变,sudo chown -R `whoami` /usr/local/var/postgres然后我重新安装了 postgresql 并做了

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

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

which revealed:

其中透露:

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

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

So I removed the directory /usr/local/var/postgresand issued the command to initialize the database.

所以我删除了目录/usr/local/var/postgres并发出了初始化数据库的命令。

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

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

This seemed to have done the trick and postgres is running fine.

这似乎成功了,postgres 运行良好。

回答by James

I had this same problem. The primary issue here is that the initdb step of installation will create the directory with root ownership instead of as the user on a Mac. To solve this issue:

我有同样的问题。这里的主要问题是安装的 initdb 步骤将创建具有 root 所有权的目录,而不是 Mac 上的用户。要解决此问题:

Create the data directory before running initdband set permissions of 0700

运行前创建数据目录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

Then run initdband it will respect the permissions of the data directory.

然后运行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

回答by Léo Chaz Maltrait

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

在尝试使用 Homebrew 安装 postgresql 后,我得到了这个:

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

回答by Freddo

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

请注意,他们是 Homebrew 的 github 上处理此问题的线程: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).

我有一个类似的问题。詹姆斯的回答帮助我解决了这个问题。但是我随后遇到了 jbk 提到的问题(在删除 /usr/local/var/postgres 之后,它继续被重新创建)。

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.

在运行 James 的命令之前。

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:

此外,如果像我一样,您有一个管理 homebrew 的管理员用户和一个将使用 pgsl 用于开发目的的普通用户,那么 James 命令应该以超级用户身份运行:

sudo -s

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

并且 postgres 目录的所有权应该给你的开发用户:

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

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

以 dev 用户身份运行的以下命令应该会正确填充目录:

createdb `whoami`

Running:

跑步:

psql -l

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

应该在此类操作后向您显示 postgre 中的表和用户权限。

Hope this helps.

希望这可以帮助。

回答by Lisandro

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.

这将通过将您现有的数据库升级到您将 postgres 升级到的版本来解决问题。

回答by Sam

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.

我在 High Sierra 上运行 postgres 11.2。我最近从 postgres 10 升级了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"?

我不断收到错误消息psql: could not connect to server: No such file or directory,并且我的 server.log 指示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:

我尝试了几种解决方案,包括重新启动计算机、删除postmaster.pid、使用brew services restart postgres,但都无济于事。我最终偶然发现了解决方案:

brew unlink postgresql && brew link postgresql

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!

不知道为什么会这样,但把它放在这里主要是为了我将来可以自己参考!往墙上扔东西直到它粘住!

回答by lacostenycoder

I recently had a problem which began when I upgraded some brew updates / upgrades, mainly python versions etc. What worked for me.

我最近遇到了一个问题,当我升级一些 brew 更新/升级时,主要是 python 版本等。什么对我有用。

brew uninstall postgres
brew install [email protected]
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' > ~/.zshrc
# you may need > ~/.bashrc if you use bash

I needed pg_dump, pg_restore etc so to get that working I did

我需要 pg_dump、pg_restore 等,这样我才能正常工作

brew install libpq

Start the service

启动服务

brew services start [email protected]

From here I would have expected everything to work but still all rails db commands were giving error that server was not running. This final bit was the missing piece of the puzzle which finally solved it for me.

从这里开始,我本来希望一切正常,但仍然所有 rails db 命令都给出服务器未运行的错误。最后一点是拼图的缺失部分,最终为我解决了它。

gem uninstall pg
gem install pg -v 0.20.0 # which was set in Gemfile
# could also just probably do bundle install instead.

回答by Anthony Awuley

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

检查@leo_chaz_maltrait 以修复错误错误Could not symlink share/man/man3/SPI_connect.3另一个可能出现的错误是:

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

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

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

brew link postgresql