postgresql 无法连接到通过 brew 服务运行的 Postgres 服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39710384/
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 06:18:43  来源:igfitidea点击:

Cannot connect to Postgres server running through brew services

macospostgresqlhomebrew

提问by leo.fcx

I've been looking for a solution for this and could not find a working solution.

我一直在为此寻找解决方案,但找不到可行的解决方案。

I've installed postgres using brew (brew install postgres) in my MacBook and I am currently running it using brew services (brew services listdisplays postgres as a running service). However, when I try to run psqlI get following error.

我已经brew install postgres在我的 MacBook 中使用 brew ( )安装了 postgres ,我目前正在使用 brew 服务运行它(将brew services listpostgres 显示为正在运行的服务)。但是,当我尝试运行时,出现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"?

psql:无法连接到服务器:没有这样的文件或目录 服务器是否在本地运行并接受 Unix 域套接字“/tmp/.s.PGSQL.5432”上的连接?

Anyone has already solved similar problem?

有人已经解决了类似的问题吗?

回答by Wilson Silva

I had the same error and I fixed it by removing the process pid file:

我有同样的错误,我通过删除进程 pid 文件来修复它:

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

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

回答by Eric Conner

I ran into this problem today. postgres stopped accepting connections though homebrew thought it was running.

我今天遇到了这个问题。尽管自制软件认为它正在运行,但 postgres 停止接受连接。

To fix it I ran,

为了修复它,我跑了,

brew services restart postgresql

Output from this command,

此命令的输出,

==> 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>

Then I thought, hmm maybe there's something in that log file,

然后我想,嗯,也许那个日志文件里有什么东西,

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

Sure enough,

果然,

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

So, I removed that file

所以,我删除了那个文件

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

And everything started working again.

一切又开始工作了。

回答by Nelu

In my case the postmaster.pidfile wasn't even there. Got it working by upgrading postgres.

在我的情况下,该postmaster.pid文件甚至不存在。通过升级 postgres 让它工作。

brew update
brew upgrade

Then, because I upgraded the major version from 10 to 11, I also had to run this:

然后,因为我将主要版本从 10 升级到 11,所以我还必须运行:

brew postgresql-upgrade-database

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

(来源https://github.com/facebook/react-native/issues/18760#issuecomment-410533581

回答by real_ate

I would combine the two answers from Wilson and Grasshopper here.

我会在这里结合 Wilson 和 Grasshopper 的两个答案。

You can check the plist file for the postgres service using brew services listto find the location of the file and just opening it up in you favourite editor.

您可以检查 postgres 服务的 plist 文件,使用它brew services list来查找文件的位置,然后在您喜欢的编辑器中打开它。

You should see the value of StandardErrorPathlisted as:

您应该看到StandardErrorPath列出的值:

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

And then you should tail the end of the log file using tail -n 100 /usr/local/var/log/postgres.log

然后你应该使用尾随日志文件的结尾 tail -n 100 /usr/local/var/log/postgres.log

In my case the error was the following:

在我的情况下,错误如下:

2017-12-06 11:51:16.078 GMT [85476] FATAL: lock file "postmaster.pid" already exists 2017-12-06 11:51:16.078 GMT [85476] HINT: Is another postmaster (PID 601) running in data directory "/usr/local/var/postgres"?

2017-12-06 11:51:16.078 GMT [85476] 致命:锁定文件“postmaster.pid”已经存在 2017-12-06 11:51:16.078 GMT [85476] 提示:是另一个 postmaster (PID 601) 正在运行数据目录“/usr/local/var/postgres”?

This was because I had to hard shutdown my Mac and postgres didn't get a chance to cleanup the PID file. Just remove the PID file rm /usr/local/var/postgres/postmaster.pidand start postgres brew services start postgresql

这是因为我不得不硬关闭我的 Mac 并且 postgres 没有机会清理 PID 文件。只需删除PID文件rm /usr/local/var/postgres/postmaster.pid并启动postgresbrew services start postgresql

A word of warning: do not delete this PID file unless you are sure that postgres is not running. You can do this by running brew services stop postgresqland then waiting for the result of brew services listto show posgres is in the stopped state.

警告:不要删除这个 PID 文件,除非你确定 postgres 没有运行。您可以通过运行brew services stop postgresql然后等待brew services list显示 posgres 处于停止状态的结果来执行此操作。

回答by António Ferreira

What worked for me was removing the /usr/local/var/postgres/folder and then uninstalling and installing postgres again

对我有用的是删除/usr/local/var/postgres/文件夹,然后再次卸载并安装 postgres

回答by Grasshopper

I got the same error installing postgresql93 from the versions tap. Inspecting the .plist file indicated in the output of brew services list(~/Library/LaunchAgents/homebrew.mxcl.postgresql93.plist) I found the following message:

我在从版本 tap 安装 postgresql93 时遇到了同样的错误。检查brew services list( ~/Library/LaunchAgents/homebrew.mxcl.postgresql93.plist)输出中指示的 .plist 文件,我发现以下消息:

FATAL: data directory "/usr/local/var/postgres" has group or world access
DETAIL: Permissions should be u=rwx (0700).

致命:数据目录“/usr/local/var/postgres”具有组或世界访问权限
详细信息:权限应为 u=rwx (0700)。

Which led me to this answer: data directory "/usr/local/var/postgres" has wrong ownership

这让我得到了这个答案:数据目录“/usr/local/var/postgres”的所有权错误

After running sudo chmod -R 700 /usr/local/var/postgresI got a different error:

运行后sudo chmod -R 700 /usr/local/var/postgres我得到了一个不同的错误:

FATAL: could not open directory "pg_tblspc": No such file or directory

致命:无法打开目录“pg_tblspc”:没有那个文件或目录

Which then led me to: `pg_tblspc` missing after installation of latest version of OS X (Yosemite or El Capitan)

然后导致我:安装最新版本的 OS X(Yosemite 或 El Capitan)后丢失了 `pg_tblspc`

After running mkdir /usr/local/var/postgres/pg_tblspc/the cluster started successfully.

运行后mkdir /usr/local/var/postgres/pg_tblspc/集群启动成功。

回答by Nadeem Qasmi

update it by using command

使用命令更新它

  brew postgresql-upgrade-database

if you have following error Command 'brew' not found,but can be installed with: sudo apt install linuxbrew-wrapper

如果您有以下错误 命令 'brew' not found, but can be installed with: sudo apt install linuxbrew-wrapper

then install it by using command

然后使用命令安装它

 sudo apt install linuxbrew-wrapper

回答by The RealDuke

In my own case, the postgres.logfile contains this HINT: Is another postmaster already running on port 5432? If not, remove socket file "/tmp/.s.PGSQL.5432" and retry.After removing the socket file and restarting, everything worked fine. Note that this is a hidden file and won't be visible through the window browser. Removal should be done via the command line.

在我自己的情况下,该postgres.log文件包含此HINT: Is another postmaster already running on port 5432? If not, remove socket file "/tmp/.s.PGSQL.5432" and retry.删除套接字文件并重新启动后,一切正常。请注意,这是一个隐藏文件,无法通过窗口浏览器看到。删除应通过命令行完成。