PostgreSQL错误“无法连接到服务器:没有这样的文件或目录" [英] PostgreSQL error 'Could not connect to server: No such file or directory'

查看:1274
本文介绍了PostgreSQL错误“无法连接到服务器:没有这样的文件或目录"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与其他人一样,当在我的项目中运行rake db:migrate或什至为我的 Ruby on Rails 3.2应用程序.

Like some others I am getting this error when I run rake db:migrate in my project or even try most database tasks for my Ruby on Rails 3.2 applications.

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

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

我安装了 PostgreSQL MongoDB 最近,我的PostgreSQL安装从未如此.我正在运行OS Xv10.6 Snow Leopard.

I installed PostgreSQL with Homebrew a long time ago and following an attempted installation of MongoDB recently my PostgreSQL install has never been the same. I'm running OS X v10.6 Snow Leopard.

出什么问题了,我如何更好地理解PostgreSQL的方式以及应该如何在Mac上设置PostgreSQL?

What's wrong and how do I better understand how PostgreSQL is and should be setup on my Mac?

到目前为止(我认为),这告诉我PostgreSQL尚未运行(?).

So far (I think) this tells me that PostgreSQL is not running(?).

ps -aef|grep postgres                                                                                                   (ruby-1.9.2-p320@jct-ana) (develop) ✗
  501 17604 11329   0   0:00.00 ttys001    0:00.00 grep postgres

但这是否告诉我PostgreSQL正在运行?

But does this tell me that PostgreSQL is running?

✪ launchctl load -w /usr/local/Cellar/postgresql/9.1.4/homebrew.mxcl.postgresql.plist                                                        (ruby-1.9.2-p136) 
homebrew.mxcl.postgresql: Already loaded

我该如何解决?我没看到什么?

How do I fix this? what am I not seeing?

PS:~/Library/LaunchAgents包含两个PostgreSQL .plist文件.我不确定这是否相关.

PS: ~/Library/LaunchAgents includes two PostgreSQL .plist files. I am not sure if that's relevant.

org.postgresql.postgres.plist
homebrew.mxcl.postgresql.plist

我尝试了以下操作,并得到了如下结果.

I tried the following and got a result as below.

$ psql -p 5432 -h localhost

psql: could not connect to server: Connection refused
    Is the server running on host "localhost" (127.0.0.1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (::1) and accepting
    TCP/IP connections on port 5432?
could not connect to server: Connection refused
    Is the server running on host "localhost" (fe80::1) and accepting
    TCP/IP connections on port 5432?

我已读过这本书,因为OS&X安装了自己的PostgreSQL版本,而Homebrew在不同的地方安装了不同版本,并且PostgreSQL命令正在/tmp/目录中查找.您需要在StackOverflow上进行更多搜索,但是基本上,您可以对PostgreSQL进行符号链接,以便在该tmp路径中查找的所有内容都可以找到真实的路径(如果有道理的话).

I've read since that this is occuring because OS X installs its own version of PostgreSQL and Homebrew installs a different version in a different place and the PostgreSQL commands are looking in the /tmp/ directory. You'll need to search more on Stack Overflow, but basically you symlink PostgreSQL so that anything looking in that tmp path actually finds the real path, if that makes sense.

这是我在其中找到了更多尝试的链接,特别是按照上面的方法进行符号链接, Mac OSX Lion Postgres不接受/tmp/.s.PGSQL.5432 上的连接.我仍然希望有人能对在OSX上安装PostgreSQL的概念以及它为什么如此困难的问题做出一个恰当的解释.

This is the link where I found a few more things to try, specifically doing the symlink as per above, Mac OSX Lion Postgres does not accept connections on /tmp/.s.PGSQL.5432. I still wish someone would put together a decent explanation of the concepts behind installing PostgreSQL on OS X and why it's all so difficult.

最新见解可帮助您进行故障排除:

Latest insights to help with troubleshooting:

$ which psql // This tells you which PostgreSQL you are using when you run $ psql. 

然后运行:

$ echo $PATH

要考虑的关键是:

确保要运行OS的PostgreSQL副本的路径条目在OS X系统的PostgreSQL路径之前出现.

这是决定要运行哪个PostgreSQL的核心要求,而我被告知会导致大多数此类问题.

This is a core requirement which decides which PostgreSQL gets run and is what I'm told leads to most of these issues.

推荐答案

检查您的postgres目录中是否没有postmaster.pid,可能是/usr/local/var/postgres/

Check there is no postmaster.pid in your postgres directory, probably /usr/local/var/postgres/

删除此文件并启动服务器.

remove this and start server.

检查- https://github.com/mperham/lunchy 是launchctl的绝佳包装.

Check - https://github.com/mperham/lunchy is a great wrapper for launchctl.

这篇关于PostgreSQL错误“无法连接到服务器:没有这样的文件或目录"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆