PostgreSQL错误“无法连接到服务器:没有这样的文件或目录”

时间:2022-05-13 10:41:23

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.

和其他人一样,我在运行rake db时也会遇到这个错误:在我的项目中迁移,甚至为Ruby on Rails 3.2应用程序尝试大多数数据库任务。

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

PGError(无法连接到服务器:没有这样的文件或目录。服务器是否在本地运行并在Unix域套接字上接受连接?

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.

很久以前,我在Homebrew上安装了PostgreSQL,最近我尝试安装了MongoDB,之后我的PostgreSQL安装就不一样了。我在运行OS X v10.6雪豹。

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

有什么问题吗?我如何更好地理解PostgreSQL是如何在我的Mac上设置的?

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

到目前为止(我认为)这告诉我PostgreSQL没有运行(?)。

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

But does this tell me that PostgreSQL is running?

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

✪ 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 includes two PostgreSQL .plist files. I am not sure if that's relevant.

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

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

I tried the following and got a result as below.

我尝试了以下方法,得到如下结果。

$ psql -p 5432 -h localhost

$ psql - p5432 -h本地主机

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?

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.

我读到这一点是因为OS X安装了自己的PostgreSQL版本,而Homebrew在不同的地方安装了不同的版本,并且PostgreSQL命令正在/tmp/目录中查找。您需要在堆栈溢出上进行更多的搜索,但是基本上您是symlink PostgreSQL,这样任何查看tmp路径的东西都可以找到真正的路径,如果这有意义的话。

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.

在这个链接中,我还发现了一些需要尝试的东西,特别是按照上面的步骤进行symlink, Mac OSX Lion Postgres不接受/tmp/. s.pgsql .5432上的连接。我仍然希望有人能对在OS X上安装PostgreSQL的概念以及为什么这一切如此困难给出一个合理的解释。

Latest insights to help with troubleshooting:

帮助解决故障的最新见解:

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

Then run:

然后运行:

$ echo $PATH

The key thing to take into account is this:

需要考虑的关键问题是:

Ensure that the path entry for the copy of PostgreSQL you want to run COMES BEFORE the path to the OS X system's PostgreSQL.

确保要运行的PostgreSQL副本的路径条目在通往OS X系统的PostgreSQL的路径之前。

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

这是一个核心需求,它决定运行哪一个PostgreSQL,我被告知这将导致大多数这些问题。

18 个解决方案

#1


94  

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

检查一下,没有邮差。在您的postgres目录中,可能是/usr/local/var/postgres/

remove this and start server.

删除这个并启动服务器。

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

https://github.com/mperham/lunchy是一个很棒的launchctl包装器。

#2


55  

UPDATE: HERE IS A BETTER FIX IF YOU ON OSX...

更新:如果你在OSX上,这里有一个更好的解决方案……

http://postgresapp.com/

http://postgresapp.com/


Old Answer:

旧的回答:

Here is the fix, more info here:

这里是修正,更多信息在这里:

https://github.com/mxcl/homebrew/issues/5004

https://github.com/mxcl/homebrew/issues/5004

First, stop the db, then

首先,停止db,然后

  1. cd /var
  2. cd / var
  3. rm -r pgsql_socket
  4. rm - r pgsql_socket
  5. ln -s /tmp pgsql_socket
  6. ln - s / tmp pgsql_socket
  7. chown _postgres:_postgres pgsql_socket
  8. 乔恩_postgres:_postgres pgsql_socket
  9. restart postgres (not your computer)
  10. 重启postgres(不是你的电脑)

#3


41  

For me, this works

对我来说,这个工作

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

#4


14  

For the above error you have mentioned, this work out for me..

对于你上面提到的错误,我觉得这样可以解决。

1) possibly change your default port no specified in postgres.conf file, if you have mentioned other then default port no 5432 while installing.

1)可能更改postgres中指定的默认端口。conf文件,如果您在安装时提到了其他,则默认端口为5432。

(OR)

(或)

2) Change the port no in postgresql.conf file and restart the DB server

2)更改postgresql中的端口号。conf文件并重新启动DB服务器

(OR)

(或)

3) instead of psql type full command like

3)而不是psql类型的完整命令

"psql -p 5432 -h localhost"

"psql - p5432 -h localhost"

  • server name and the port no
  • 服务器名和端口号

#5


10  

If you are running Homebrew, uninstall Postgresql end pg gems:*

如果您正在运行Homebrew,请卸载Postgresql end pg gems:*

$ gem uninstall pg
$ brew uninstall postgresql

Download and run the following script to fix permission on /usr/local:* https://gist.github.com/rpavlik/768518

下载并运行以下脚本,以修复/usr/local的权限:* https://gist.github.com/rpavlik/768518

$ ruby fix_homebrew.rb

Then install Postgres again and pg gem:*

然后再次安装Postgres和pg gem:*

$ brew install postgresql  
$ initdb /usr/local/var/postgres -E utf8

To have launchd start postgresql at login run:

要让launchd在登录时启动postgresql:

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

Or start manually.

手动或开始。

Install pg gem

安装pg宝石

$ gem install pg

I hope have helped

我希望有帮助

#6


7  

I had that problem when I upgraded Postgres to 9.3.x. The quick fix for me was to downgrade to whichever 9.2.x version I had before (no need to install a new one).

当我将Postgres升级到9.3.x时,我遇到了这个问题。对我来说,最简单的解决办法就是降级为9.2。我以前有过的x版本(不需要安装新的)。

$ ls /usr/local/Cellar/postgresql/
9.2.4
9.3.2
$ brew switch postgresql 9.2.4
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
<open a new Terminal tab or window to reload>
$ psql

This answer offers a much more comprehensive explanation along with alternative ways to fix the problem.

这个答案提供了一个更全面的解释,以及解决问题的其他方法。

#7


4  

When you run: psql -p 5432 -h localhost it does not use the loopback driver but uses a real socket and hence you need to configure postgres to accept socket connections. Hence even though pgadmin and other clients may work, psql will not.

当您运行时:psql - p5432 -h localhost不使用环回驱动程序,而是使用一个真正的套接字,因此您需要配置postgres来接受套接字连接。因此,即使pgadmin和其他客户端可以工作,psql也不能。

You need to change both the postgresql.conf file and the pg_hba.conf files so allow connection over a real socket. This will also allow connection from a remote ip which is why it is disabled by default.

您需要同时更改postgresql。conf文件和pg_hba。conf文件允许在真正的套接字上进行连接。这也将允许来自远程ip的连接,这就是为什么它在默认情况下被禁用的原因。

These files are in the data directory but the actual location can be different depending on how postgres was installed. With postgres running, run the command:

这些文件在数据目录中,但是根据安装postgres的方式,实际位置可能不同。当postgres运行时,运行以下命令:

ps -ef | grep postmaster

These two files are the -D directory (maybe /usr/local/pgsql/data).

这两个文件是-D目录(可能是/usr/local/pgsql/data)。

For the postgresql.conf file, uncomment the listen_address and change it to be:

postgresql。conf文件,取消listen_address的注释,改为:

listen_address = '*'

For the pg_hba.conf add the line:

pg_hba。配置添加一行:

host all all 0.0.0.0/0 md5

#8


4  

So for a lot of the issues here, it seems that people were already running psql and had to remove postmaster.pid. However, I did not have that issue as I never even had postgres installed in my system properly.

因此,对于这里的许多问题,似乎人们已经在运行psql,并且必须删除postmaster.pid。但是,我没有这个问题,因为我甚至没有在我的系统中正确地安装postgres。

Here's a solution that worked for me in MAC OSX Yosemite

这是一个在MAC OSX Yosemite中为我工作的解决方案。

  1. I went to http://postgresapp.com/ and downloaded the app.
  2. 我去了http://postgresapp.com/下载了这个应用。
  3. I moved the app to Application/ directory
  4. 我将应用程序移动到应用程序/目录
  5. I added it to $PATH by adding this to .bashrc or .bash_profile or .zshrc : export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
  6. 我将它添加到$PATH中,将它添加到.bashrc或.bash_profile或.zshrc: export PATH=$PATH:/Applications/Postgres.app/Contents/ version /latest/bin
  7. I ran the postgres from the Applications directory and ran the command again and it worked.
  8. 我从应用程序目录中运行了postgres,然后再次运行该命令,它成功了。

Hope this helps! Toodles!

希望这可以帮助!回见!

Also, this answer helped me the most: https://*.com/a/21503349/3173748

同样,这个答案对我帮助最大:https://*.com/a/21503349/3173748

#9


2  

I don't really know Mac or Homebrew, but I know PostgreSQL very well.

我不太了解Mac或Homebrew,但我非常了解PostgreSQL。

You want to figure out where the logs are from PostgreSQL trying to start and what the socket directory is for PostgreSQL. By default when you build PG, the socket directory is /tmp/. If you didn't change that when you built PG and then you started PG, you should be able to see a socket file in /tmp if you do: ls -al /tmp

您需要确定日志来自尝试启动的PostgreSQL,以及PostgreSQL的套接字目录是什么。默认情况下,当您构建PG时,套接字目录是/tmp/。如果您在构建PG然后启动PG时没有更改它,那么您应该能够看到/tmp中的套接字文件:ls -al /tmp

The socket file starts with a ".", so you won't see it with the '-a' to ls.

套接字文件以“”开头。所以你不会看到它的“-a”到ls。

If you don't see a socket there, and you don't see anything from ps awux | grep postgres, then PG is probably not running, or maybe it is and it's the OSX-installed one. What might be happening is that you might be getting a conflict on listening on port 5432 on localhost- use netstat -anp to see what, if anything, is listening on 5432. If a Mac OSX PG is already listening on that port then that might be the problem.

如果您没有在那里看到一个套接字,并且您没有从ps awux | grep postgres中看到任何内容,那么PG可能没有运行,或者它可能正在运行,它是安装了osx的那个。可能发生的情况是,您可能会在本地主机上的端口5432上听到冲突—使用netstat -anp查看在5432上听到了什么(如果有的话)。如果Mac OSX PG已经在监听该端口,那么这可能就是问题所在。

Hope that helps. I have heard that homebrew can make things a bit ugly and a lot of people I've talked to encourage using a VM instead.

希望有帮助。我听说homebrew可以让事情变得有点丑陋,我和很多人交谈过,鼓励他们使用VM。

#10


1  

The Cause

的原因

Lion comes with a version of postgres already installed and uses those binaries by default. In general you can get around this by using the full path to the homebrew postgres binaries but there may be still issues with other programs.

Lion附带已经安装的postgres版本,默认情况下使用这些二进制文件。一般来说,您可以通过使用homebrew postgres二进制文件的完整路径来绕过这个问题,但是其他程序可能仍然存在问题。

The Solution

解决方案

curl http://nextmarvel.net/blog/downloads/fixBrewLionPostgres.sh | sh

curl http://nextmarvel.net/blog/downloads/fixBrewLionPostgres.sh |上海

Via

通过

http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/

http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/

#11


1  

Hello world :)
The best but strange way for me was to do next things.

1) Download postgres93.app or other version. Add this app into /Applications/ folder.

(你好世界)对我来说,最好但奇怪的方法是做下一件事。1)下载postgres93。应用程序或其他版本。将此应用程序添加到/Applications/文件夹中。

2) Add a row (command) into the file .bash_profile (which is in my home directory):

2)在文件.bash_profile(在我的主目录中)中添加一行(命令):

export PATH=/Applications/Postgres93.app/Contents/MacOS/bin/:$PATH
It's a PATH to psql from Postgres93.app. The row (command) runs every time console is started.

3) Launch Postgres93.app from /Applications/ folder. It starts a local server (port is "5432" and host is "localhost").

3)Postgres93发射。应用程序/应用程序/文件夹。它启动本地服务器(端口是“5432”,主机是“localhost”)。

4) After all of this manipulations I was glad to run $ createuser -SRDP user_name and other commands and to see that it worked! Postgres93.app can be made to run every time your system starts.

4)在所有这些操作之后,我很高兴运行$ createuser -SRDP user_name和其他命令,并看到它工作!Postgres93。应用程序可以在每次系统启动时运行。

5) Also if you wanna see your databases graphically you should install PG Commander.app. It's good way to see your postgres DB as pretty data-tables

5)如果你想看到你的数据库图形化,你应该安装PG Commander.app。这是将postgres DB看作漂亮的数据表的好方法

Of, course, it's helpful only for local server. I will be glad if this instructions help others who has faced with this problem.

当然,它只对本地服务器有用。如果这些指导能帮助遇到这个问题的人,我将很高兴。

#12


1  

I had PostgreSQL 9.3 and got the same error,

我有PostgreSQL 9。3,得到了相同的错误,

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?

无法连接到服务器:连接被拒绝,服务器是否在主机“localhost”(127.0.0.1)上运行并在端口5432上接受TCP/IP连接?

I fixed this using:

我固定的使用:

chmod 777  /var/lib/pgsql/9.3/data/pg_hba.conf 
service postgresql-9.3 restart

It works for me.

它适合我。

#13


1  

for what it's worth, I experienced this same error when I had a typo (md4 instead of md5) in my pg_hba.conf file (/etc/postgresql/9.5/main/pg_hba.conf)

值得注意的是,当我在pg_hba中输入错误(md4而不是md5)时,我也经历了同样的错误。配置文件(/ etc / postgresql / 9.5 /主/ pg_hba.conf)

If you got here as I did, double-check that file once to make sure there isn't anything ridiculous in there.

如果你像我一样来到这里,再检查一下这个文件,确保里面没有任何荒谬的东西。

#14


0  

One reason you get this error is that your local postgres database shuts down when you restart your computer. In a new terminal window, simply type:

出现此错误的一个原因是,当重新启动计算机时,本地postgres数据库会关闭。在新的终端窗口中,只需输入:

$psql -h localhost 

to restart the server.

重新启动服务器。

#15


0  

There might be different issues with running PostgreSQL locally. I would recommend to clean all versions of postgres installed and start fresh. Once you have it installed, it's very easy to recreate your database if you have your rails project with the up to date db/schema.rb

本地运行PostgreSQL可能会有不同的问题。我建议清理所有版本的postgres,并重新开始。安装之后,如果您的rails项目具有最新的db/schema.rb,那么很容易重新创建数据库

Here is how I usually install PostgreSQL on a Mac. If you're running your database under the root user locally, you might want to omit the last step that creates a todo user

下面是我通常在Mac上安装PostgreSQL的方法

#16


0  

One of the reason could be that

其中一个原因可能是

unix_socket_directories in postgresql.conf file is not listed with the directory it is looking for.

unix_socket_directories postgresql。conf文件没有列出它要查找的目录。

In the question example it is looking for directory /tmp this has to be provided in the postgresql.conf file

在问题示例中,它正在寻找必须在postgresql中提供的目录/tmp。配置文件

something like this:

是这样的:

unix_socket_directories = '/var/run/postgresql,/tmp'    # comma-separated list of directories

This solution worked for me.

这个办法对我起作用了。

#17


0  

If you're on MacOS and using homebrew I found this answer extremely helpful:

如果你在MacOS上使用homebrew,我发现这个答案非常有用:

https://*.com/a/27708774/4062901

https://*.com/a/27708774/4062901

For me, my server was running but because of an upgrade I was having issues connecting (note: I use brew services). If Postgres is running, try cat /usr/local/var/postgres/server.log and see what the logs say. My error was a migration, not a connection issue.

对我来说,我的服务器正在运行,但由于升级,我的连接出现了问题(注意:我使用brew服务)。如果Postgres正在运行,请尝试cat /usr/local/var/ postgres/server。写日志,看看日志写了什么。我的错误是迁移,而不是连接问题。

Also after the manual migration they propose (which does work but) I found there was no longer a table for my user. Try this command to fix that: createdb (answered via psql: FATAL: database "<user>" does not exist)

同样,在手动迁移之后,他们建议(这确实有效),我发现不再有一个表供我的用户使用。尝试使用此命令修复:createdb(通过psql:致命:数据库“ ”不存在)

#18


-5  

It's very simple. Only add host in your database.yaml file.

很简单。只在数据库中添加主机。yaml文件。

#1


94  

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

检查一下,没有邮差。在您的postgres目录中,可能是/usr/local/var/postgres/

remove this and start server.

删除这个并启动服务器。

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

https://github.com/mperham/lunchy是一个很棒的launchctl包装器。

#2


55  

UPDATE: HERE IS A BETTER FIX IF YOU ON OSX...

更新:如果你在OSX上,这里有一个更好的解决方案……

http://postgresapp.com/

http://postgresapp.com/


Old Answer:

旧的回答:

Here is the fix, more info here:

这里是修正,更多信息在这里:

https://github.com/mxcl/homebrew/issues/5004

https://github.com/mxcl/homebrew/issues/5004

First, stop the db, then

首先,停止db,然后

  1. cd /var
  2. cd / var
  3. rm -r pgsql_socket
  4. rm - r pgsql_socket
  5. ln -s /tmp pgsql_socket
  6. ln - s / tmp pgsql_socket
  7. chown _postgres:_postgres pgsql_socket
  8. 乔恩_postgres:_postgres pgsql_socket
  9. restart postgres (not your computer)
  10. 重启postgres(不是你的电脑)

#3


41  

For me, this works

对我来说,这个工作

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

#4


14  

For the above error you have mentioned, this work out for me..

对于你上面提到的错误,我觉得这样可以解决。

1) possibly change your default port no specified in postgres.conf file, if you have mentioned other then default port no 5432 while installing.

1)可能更改postgres中指定的默认端口。conf文件,如果您在安装时提到了其他,则默认端口为5432。

(OR)

(或)

2) Change the port no in postgresql.conf file and restart the DB server

2)更改postgresql中的端口号。conf文件并重新启动DB服务器

(OR)

(或)

3) instead of psql type full command like

3)而不是psql类型的完整命令

"psql -p 5432 -h localhost"

"psql - p5432 -h localhost"

  • server name and the port no
  • 服务器名和端口号

#5


10  

If you are running Homebrew, uninstall Postgresql end pg gems:*

如果您正在运行Homebrew,请卸载Postgresql end pg gems:*

$ gem uninstall pg
$ brew uninstall postgresql

Download and run the following script to fix permission on /usr/local:* https://gist.github.com/rpavlik/768518

下载并运行以下脚本,以修复/usr/local的权限:* https://gist.github.com/rpavlik/768518

$ ruby fix_homebrew.rb

Then install Postgres again and pg gem:*

然后再次安装Postgres和pg gem:*

$ brew install postgresql  
$ initdb /usr/local/var/postgres -E utf8

To have launchd start postgresql at login run:

要让launchd在登录时启动postgresql:

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

Or start manually.

手动或开始。

Install pg gem

安装pg宝石

$ gem install pg

I hope have helped

我希望有帮助

#6


7  

I had that problem when I upgraded Postgres to 9.3.x. The quick fix for me was to downgrade to whichever 9.2.x version I had before (no need to install a new one).

当我将Postgres升级到9.3.x时,我遇到了这个问题。对我来说,最简单的解决办法就是降级为9.2。我以前有过的x版本(不需要安装新的)。

$ ls /usr/local/Cellar/postgresql/
9.2.4
9.3.2
$ brew switch postgresql 9.2.4
$ launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
<open a new Terminal tab or window to reload>
$ psql

This answer offers a much more comprehensive explanation along with alternative ways to fix the problem.

这个答案提供了一个更全面的解释,以及解决问题的其他方法。

#7


4  

When you run: psql -p 5432 -h localhost it does not use the loopback driver but uses a real socket and hence you need to configure postgres to accept socket connections. Hence even though pgadmin and other clients may work, psql will not.

当您运行时:psql - p5432 -h localhost不使用环回驱动程序,而是使用一个真正的套接字,因此您需要配置postgres来接受套接字连接。因此,即使pgadmin和其他客户端可以工作,psql也不能。

You need to change both the postgresql.conf file and the pg_hba.conf files so allow connection over a real socket. This will also allow connection from a remote ip which is why it is disabled by default.

您需要同时更改postgresql。conf文件和pg_hba。conf文件允许在真正的套接字上进行连接。这也将允许来自远程ip的连接,这就是为什么它在默认情况下被禁用的原因。

These files are in the data directory but the actual location can be different depending on how postgres was installed. With postgres running, run the command:

这些文件在数据目录中,但是根据安装postgres的方式,实际位置可能不同。当postgres运行时,运行以下命令:

ps -ef | grep postmaster

These two files are the -D directory (maybe /usr/local/pgsql/data).

这两个文件是-D目录(可能是/usr/local/pgsql/data)。

For the postgresql.conf file, uncomment the listen_address and change it to be:

postgresql。conf文件,取消listen_address的注释,改为:

listen_address = '*'

For the pg_hba.conf add the line:

pg_hba。配置添加一行:

host all all 0.0.0.0/0 md5

#8


4  

So for a lot of the issues here, it seems that people were already running psql and had to remove postmaster.pid. However, I did not have that issue as I never even had postgres installed in my system properly.

因此,对于这里的许多问题,似乎人们已经在运行psql,并且必须删除postmaster.pid。但是,我没有这个问题,因为我甚至没有在我的系统中正确地安装postgres。

Here's a solution that worked for me in MAC OSX Yosemite

这是一个在MAC OSX Yosemite中为我工作的解决方案。

  1. I went to http://postgresapp.com/ and downloaded the app.
  2. 我去了http://postgresapp.com/下载了这个应用。
  3. I moved the app to Application/ directory
  4. 我将应用程序移动到应用程序/目录
  5. I added it to $PATH by adding this to .bashrc or .bash_profile or .zshrc : export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/latest/bin
  6. 我将它添加到$PATH中,将它添加到.bashrc或.bash_profile或.zshrc: export PATH=$PATH:/Applications/Postgres.app/Contents/ version /latest/bin
  7. I ran the postgres from the Applications directory and ran the command again and it worked.
  8. 我从应用程序目录中运行了postgres,然后再次运行该命令,它成功了。

Hope this helps! Toodles!

希望这可以帮助!回见!

Also, this answer helped me the most: https://*.com/a/21503349/3173748

同样,这个答案对我帮助最大:https://*.com/a/21503349/3173748

#9


2  

I don't really know Mac or Homebrew, but I know PostgreSQL very well.

我不太了解Mac或Homebrew,但我非常了解PostgreSQL。

You want to figure out where the logs are from PostgreSQL trying to start and what the socket directory is for PostgreSQL. By default when you build PG, the socket directory is /tmp/. If you didn't change that when you built PG and then you started PG, you should be able to see a socket file in /tmp if you do: ls -al /tmp

您需要确定日志来自尝试启动的PostgreSQL,以及PostgreSQL的套接字目录是什么。默认情况下,当您构建PG时,套接字目录是/tmp/。如果您在构建PG然后启动PG时没有更改它,那么您应该能够看到/tmp中的套接字文件:ls -al /tmp

The socket file starts with a ".", so you won't see it with the '-a' to ls.

套接字文件以“”开头。所以你不会看到它的“-a”到ls。

If you don't see a socket there, and you don't see anything from ps awux | grep postgres, then PG is probably not running, or maybe it is and it's the OSX-installed one. What might be happening is that you might be getting a conflict on listening on port 5432 on localhost- use netstat -anp to see what, if anything, is listening on 5432. If a Mac OSX PG is already listening on that port then that might be the problem.

如果您没有在那里看到一个套接字,并且您没有从ps awux | grep postgres中看到任何内容,那么PG可能没有运行,或者它可能正在运行,它是安装了osx的那个。可能发生的情况是,您可能会在本地主机上的端口5432上听到冲突—使用netstat -anp查看在5432上听到了什么(如果有的话)。如果Mac OSX PG已经在监听该端口,那么这可能就是问题所在。

Hope that helps. I have heard that homebrew can make things a bit ugly and a lot of people I've talked to encourage using a VM instead.

希望有帮助。我听说homebrew可以让事情变得有点丑陋,我和很多人交谈过,鼓励他们使用VM。

#10


1  

The Cause

的原因

Lion comes with a version of postgres already installed and uses those binaries by default. In general you can get around this by using the full path to the homebrew postgres binaries but there may be still issues with other programs.

Lion附带已经安装的postgres版本,默认情况下使用这些二进制文件。一般来说,您可以通过使用homebrew postgres二进制文件的完整路径来绕过这个问题,但是其他程序可能仍然存在问题。

The Solution

解决方案

curl http://nextmarvel.net/blog/downloads/fixBrewLionPostgres.sh | sh

curl http://nextmarvel.net/blog/downloads/fixBrewLionPostgres.sh |上海

Via

通过

http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/

http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/

#11


1  

Hello world :)
The best but strange way for me was to do next things.

1) Download postgres93.app or other version. Add this app into /Applications/ folder.

(你好世界)对我来说,最好但奇怪的方法是做下一件事。1)下载postgres93。应用程序或其他版本。将此应用程序添加到/Applications/文件夹中。

2) Add a row (command) into the file .bash_profile (which is in my home directory):

2)在文件.bash_profile(在我的主目录中)中添加一行(命令):

export PATH=/Applications/Postgres93.app/Contents/MacOS/bin/:$PATH
It's a PATH to psql from Postgres93.app. The row (command) runs every time console is started.

3) Launch Postgres93.app from /Applications/ folder. It starts a local server (port is "5432" and host is "localhost").

3)Postgres93发射。应用程序/应用程序/文件夹。它启动本地服务器(端口是“5432”,主机是“localhost”)。

4) After all of this manipulations I was glad to run $ createuser -SRDP user_name and other commands and to see that it worked! Postgres93.app can be made to run every time your system starts.

4)在所有这些操作之后,我很高兴运行$ createuser -SRDP user_name和其他命令,并看到它工作!Postgres93。应用程序可以在每次系统启动时运行。

5) Also if you wanna see your databases graphically you should install PG Commander.app. It's good way to see your postgres DB as pretty data-tables

5)如果你想看到你的数据库图形化,你应该安装PG Commander.app。这是将postgres DB看作漂亮的数据表的好方法

Of, course, it's helpful only for local server. I will be glad if this instructions help others who has faced with this problem.

当然,它只对本地服务器有用。如果这些指导能帮助遇到这个问题的人,我将很高兴。

#12


1  

I had PostgreSQL 9.3 and got the same error,

我有PostgreSQL 9。3,得到了相同的错误,

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?

无法连接到服务器:连接被拒绝,服务器是否在主机“localhost”(127.0.0.1)上运行并在端口5432上接受TCP/IP连接?

I fixed this using:

我固定的使用:

chmod 777  /var/lib/pgsql/9.3/data/pg_hba.conf 
service postgresql-9.3 restart

It works for me.

它适合我。

#13


1  

for what it's worth, I experienced this same error when I had a typo (md4 instead of md5) in my pg_hba.conf file (/etc/postgresql/9.5/main/pg_hba.conf)

值得注意的是,当我在pg_hba中输入错误(md4而不是md5)时,我也经历了同样的错误。配置文件(/ etc / postgresql / 9.5 /主/ pg_hba.conf)

If you got here as I did, double-check that file once to make sure there isn't anything ridiculous in there.

如果你像我一样来到这里,再检查一下这个文件,确保里面没有任何荒谬的东西。

#14


0  

One reason you get this error is that your local postgres database shuts down when you restart your computer. In a new terminal window, simply type:

出现此错误的一个原因是,当重新启动计算机时,本地postgres数据库会关闭。在新的终端窗口中,只需输入:

$psql -h localhost 

to restart the server.

重新启动服务器。

#15


0  

There might be different issues with running PostgreSQL locally. I would recommend to clean all versions of postgres installed and start fresh. Once you have it installed, it's very easy to recreate your database if you have your rails project with the up to date db/schema.rb

本地运行PostgreSQL可能会有不同的问题。我建议清理所有版本的postgres,并重新开始。安装之后,如果您的rails项目具有最新的db/schema.rb,那么很容易重新创建数据库

Here is how I usually install PostgreSQL on a Mac. If you're running your database under the root user locally, you might want to omit the last step that creates a todo user

下面是我通常在Mac上安装PostgreSQL的方法

#16


0  

One of the reason could be that

其中一个原因可能是

unix_socket_directories in postgresql.conf file is not listed with the directory it is looking for.

unix_socket_directories postgresql。conf文件没有列出它要查找的目录。

In the question example it is looking for directory /tmp this has to be provided in the postgresql.conf file

在问题示例中,它正在寻找必须在postgresql中提供的目录/tmp。配置文件

something like this:

是这样的:

unix_socket_directories = '/var/run/postgresql,/tmp'    # comma-separated list of directories

This solution worked for me.

这个办法对我起作用了。

#17


0  

If you're on MacOS and using homebrew I found this answer extremely helpful:

如果你在MacOS上使用homebrew,我发现这个答案非常有用:

https://*.com/a/27708774/4062901

https://*.com/a/27708774/4062901

For me, my server was running but because of an upgrade I was having issues connecting (note: I use brew services). If Postgres is running, try cat /usr/local/var/postgres/server.log and see what the logs say. My error was a migration, not a connection issue.

对我来说,我的服务器正在运行,但由于升级,我的连接出现了问题(注意:我使用brew服务)。如果Postgres正在运行,请尝试cat /usr/local/var/ postgres/server。写日志,看看日志写了什么。我的错误是迁移,而不是连接问题。

Also after the manual migration they propose (which does work but) I found there was no longer a table for my user. Try this command to fix that: createdb (answered via psql: FATAL: database "<user>" does not exist)

同样,在手动迁移之后,他们建议(这确实有效),我发现不再有一个表供我的用户使用。尝试使用此命令修复:createdb(通过psql:致命:数据库“ ”不存在)

#18


-5  

It's very simple. Only add host in your database.yaml file.

很简单。只在数据库中添加主机。yaml文件。