postgresql Mac OSX Lion Postgres 不接受 /tmp/.s.PGSQL.5432 上的连接

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

Mac OSX Lion Postgres does not accept connections on /tmp/.s.PGSQL.5432

postgresqlosx-lionhomebrew

提问by Euan Millar

I'm getting a common Mac OSX error for Homebrew installations of Postgres,

我在安装 Postgres 的 Homebrew 时遇到一个常见的 Mac OSX 错误,

No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

This is apparently due to there being multiple installs on the system. However, the usual steps are not resolving things.

这显然是由于系统上有多个安装。然而,通常的步骤并不能解决问题。

I can successfully start Postgres and running:

我可以成功启动 Postgres 并运行:

ps auxw | grep post

returns ..

返回..

euanmillar       847   0.0  0.0  2432768    588 s000  R+   11:19am   0:00.00 grep postgres
euanmillar       845   0.0  0.0  2439324    448   ??  Ss   11:19am   0:00.00 postgres:
stats collector process
euanmillar       844   0.0  0.0  2443176   1520   ??  Ss   11:19am   0:00.00 postgres:
autovacuum launcher process
euanmillar       843   0.0  0.0  2443044    544   ??  Ss   11:19am   0:00.00 postgres: wal writer process
euanmillar       842   0.0  0.0  2443044    584   ??  Ss   11:19am   0:00.00 postgres: writer process
euanmillar       841   0.0  0.0  2443044    596   ??  Ss   11:19am   0:00.00 postgres: checkpointer process
euanmillar       839   0.0  0.0  2443044   3616 s000  S    11:19am   0:00.02 /us

so it looks like postgres is running.

所以看起来 postgres 正在运行。

I have commented in the following lines in postgresql.conf

我在 postgresql.conf 中的以下几行中发表了评论

port = 5432
unix_socket_directory = '/var/pgsql_socket'
unix_socket_permissions = 0777

and in var/pgsql_socket/ I do have a hidden file .s.PGSQL.5432

在 var/pgsql_socket/ 我确实有一个隐藏文件 .s.PGSQL.5432

I have tried solutions to many of the posts here. This one especially seems similar:

我已经尝试解决这里的许多帖子。这个看起来特别相似:

https://dba.stackexchange.com/questions/21587/postgresql-is-running-locally-but-i-cannot-connect-why

https://dba.stackexchange.com/questions/21587/postgresql-is-running-locally-but-i-cannot-connect-why

But the difference is that I do have a '/var/pgsql_socket' directory which is CHOWN-ed to everyone. I have used Homebrew to completely remove and re-install Postgres and still I have the same issue.

但不同的是,我确实有一个“/var/pgsql_socket”目录,每个人都知道它是 CHOWN 的。我已经使用 Homebrew 完全删除并重新安装 Postgres,但我仍然遇到同样的问题。

回答by Iman

You need to remove the postmaster.pid, which should be in the following path: /usr/local/var/postgres/postmaster.pid

您需要删除 postmaster.pid,它应该在以下路径中: /usr/local/var/postgres/postmaster.pid

回答by courtsimas

For me, i removed postmaster.pid in /usr/local/var/postgres. fixed me right up.

对我来说,我在/usr/local/var/postgres. 把我修好。

回答by Matt Dressel

A simpler solution is to locate where the socket actually is vs where it's expected to be. In my case, I ran:

一个更简单的解决方案是定位套接字的实际位置与预期位置。就我而言,我跑了:

$ locate PGSQL.5432
/private/var/pgsql_socket/.s.PGSQL.5432
/private/var/pgsql_socket/.s.PGSQL.5432.lock

Then just symlink the expected socket location to the actual socket location.

然后只需将预期的套接字位置符号链接到实际的套接字位置。

$ ln -s /private/var/pgsql_socket/.s.PGSQL.5432 /tmp/.s.PGSQL.5432

回答by marcusb

The system client is being used and not your brew version. The symlink approach only lasts until the next restart. This approach fixes the root issue I believe

正在使用系统客户端,而不是您的 brew 版本。符号链接方法仅持续到下一次重新启动。这种方法解决了我认为的根本问题

  1. sudo edit /etc/paths
  2. Move the line containing /usr/local/binto the top of the file. (Before /usr/bin)
  3. Uninstall your postgres gem(s) (gem uninstall pg)
  4. Start up new shell to load the new environment settings
  5. bundle
  1. 须藤编辑 /etc/paths
  2. 将包含的行移动/usr/local/bin到文件的顶部。(之前/usr/bin
  3. 卸载你的 postgres gem(s) ( gem uninstall pg)
  4. 启动新的 shell 以加载新的环境设置
  5. bundle

回答by Atmaram Shetye

That is not an OS X specific issue. You will need to clean up your postgres installation and then reinstall it again. I have faced this issue on my ubuntu 12.04. While cleaning your previous installation, you will need to remove all packages starting with postgres (postgresql, postgresql-common, postgresql-client etc), in other words, postgres*. I have not used brew, have used port on OS X Lion. I guess the equivalent command should be sudo brew remove postgres*. A sudo brew install postgresql should then do the trick.

这不是 OS X 特定的问题。您需要清理 postgres 安装,然后重新安装。我在 ubuntu 12.04 上遇到过这个问题。在清理之前的安装时,您需要删除所有以 postgres 开头的包(postgresql、postgresql-common、postgresql-client 等),即 postgres*。我没有使用过 brew,在 OS X Lion 上使用过端口。我想等效的命令应该是sudo brew remove postgres*. 然后 sudo brew install postgresql 应该可以解决问题。

Also, if you feel the server is already running, you can try sudo -u postgres createuser. If that fails, you will need to reinstall.

另外,如果您觉得服务器已经在运行,您可以尝试sudo -u postgres createuser. 如果失败,您将需要重新安装。

However, the output of your ps aux | grep postis actually the grep command itself. Not of the postgres server running.

但是,您的输出ps aux | grep post实际上是 grep 命令本身。不是正在运行的 postgres 服务器。

EDIT: Looks like the following link could be of help https://dba.stackexchange.com/questions/21587/postgresql-is-running-locally-but-i-cannot-connect-whyIf yes, then this question might be a duplicate.

编辑:看起来以下链接可能有帮助https://dba.stackexchange.com/questions/21587/postgresql-is-running-locally-but-i-cannot-connect-why如果是,那么这个问题可能是一个副本。

回答by r3b00t

I had the same problem on Mac Serria. In Mac Serria you can find postmaster.pid inside /Users/<user_name>/Library/Application Support/Postgres/var-9.6if you used GUI installer rather than homebrew.

我在 Mac Serria 上遇到了同样的问题。在 Mac Serria 中,/Users/<user_name>/Library/Application Support/Postgres/var-9.6如果您使用 GUI 安装程序而不是自制软件,则可以在其中找到 postmaster.pid 。

Once you delete this file then everything should work fine.

删除此文件后,一切都应该正常工作。