为什么我在Mac OS Lion中遇到Postgres无法连接服务器的错误? [英] Why am I getting a could not connect to server error for postgres in Mac OS Lion?

查看:88
本文介绍了为什么我在Mac OS Lion中遇到Postgres无法连接服务器的错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Mac OS Lion机器上安装了postgresql。我已经卸载并重新安装了 pg gems。



当我运行 psql 我收到以下错误:

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

运行其中psql

/ usr / local / bin / psql



我使用自制软件安装了PostgreSQL



以下是Postgres的 lsof 结果:

  postgres 21159 myuser cwd DIR 14,2 680 3528182 / usr / local / var / postgres 
postgres 21159 myuser txt REG 14,2 5092464 3546949 /usr/local/Cellar/postgresql/9.1.3/bin / postgres
postgres 21159 myuser txt REG 14,2 599280 641674 / usr / lib / dyld
postgres 21159 myuser txt REG 14,2 297734144 3151814 / private / var / db / dyld / dyld_shared_cache_x86_64
postgres 21159 myuser 0r CHR 3,2 0t0 306 / dev / null
postgres 21159 myuser 1w REG 14,2 1193 3529245 /usr/local/var/postgres/server.log
postgres 21159 myuser 2w REG 14 ,2 1193 3529245 / usr / local / var / postgres / server.log
postgres 21159 myuser 3u systm 0t0
postgres 21159 myuser 4u Unix 0xffffff8012b85578 0t0-> 0xffffff8012b85640
postgres 21159 myuser 5u IPv6 0xffffff80128f4e80(0) $ b postgres 21159 myuser 6u IPv4 0xffffff80128f9880 0t0 TCP本地主机:postgresql(LISTEN)
postgres 21159 myuser 7u IPv6 0xffffff80128f5600 0t0 TCP本地主机:postgresql(LISTEN)
postgres 21159 myuser 8u unix 0xffffff / 202。 .PGSQL.5432
postgres 21159 myuser 9u IPv6 0xffffff8013ebc508 0t0 UDP localhost:57404-> localhost:57404
postgres 21170 myuser cwd DIR 14,2 680 3528182 / usr / local / var / postgres
postgres 21170 myuser txt REG 14,2 5092464 3546949 /usr/local/Cellar/postgresql/9.1.3/bin/postgres
postgres 21170 myuser txt REG 14,2 599280 641674 / usr / lib / dyld
postgres 21170 myuser txt REG 14,2 297734144 3151814 / private / var / db / dyld / dyld_shared_cache_x86_64
postgres 21170 myuser 0r CHR 3,2 0t0 306 / dev / null
postgres 21170 myuser 1w REG 14,2 1193 3529245 /usr/local/var/postgres/server.log
postgres 21170 myuser 2w REG 14,2 1193 3529245 / usr / local / var / postgres / server.log
postgres 21170 myuser 3u systm 0t0
postgres 21170 myuser 4u unix 0xffffff8012b85578 0t0-> 0xffffff8012b85640
postgres 21170 myuser 5 PIPE 0xffffff8015152-0290 b postgres 21170 myuser 6 PIPE 0xffffff8015250810 16384-> 0xffffff8015250290
postgres 21170 myuser 9u IPv6 0xffffff8013ebc508 0t0 UDP本地主机:57404-> loca lhost:57404
postgres 21171 myuser cwd DIR 14,2 680 3528182 / usr / local / var / postgres
postgres 21171 myuser txt REG 14,2 5092464 3546949 /usr/local/Cellar/postgresql/9.1。 3 / bin / postgres
postgres 21171 myuser txt REG 14,2 599280 641674 / usr / lib / dyld
postgres 21171 myuser txt REG 14,2 297734144 3151814 / private / var / db / dyld / dyld_shared_cache_x86_64
postgres 21171 myuser 0r CHR 3,2 0t0 306 / dev / null
postgres 21171 myuser 1w REG 14,2 1193 3529245 /usr/local/var/postgres/server.log
postgres 21171 myuser 2w REG 14,2 1193 3529245 /usr/local/var/postgres/server.log
postgres 21171 myuser 3u systm 0t0
postgres 21171 myuser 4u unix 0xffffff8012b85578 0t0-> 0xffffff8012b85640
postgres 21171 myuser 5 PIP E 0xffffff80152501e0 16384-> 0xffffff8015250760
postgres 21171 myuser 6 PIPE 0xffffff8015250760 16384-> 0xffffff80152501e0
postgres 21171 myuser 9u IPv6 0xffffff8013ebc508 0t0 $ UDP本地主机:$ localhost cwd DIR 14,2 680 3528182 / usr / local / var / postgres
postgres 21172 myuser txt REG 14,2 5092464 3546949 /usr/local/Cellar/postgresql/9.1.3/bin/postgres
postgres 21172 myuser txt REG 14,2 599280 641674 / usr / lib / dyld
postgres 21172 myuser txt REG 14,2 297734144 3151814 / private / var / db / dyld / dyld_shared_cache_x86_64
postgres 21172 myuser 0r CHR 3, 2 0t0 306 / dev / null
postgres 21172 myuser 1w REG 14,2 1193 3529245 /usr/local/var/postgres/server.log
postgres 21172 myuser 2w REG 14,2 11 93 3529245 /usr/local/var/postgres/server.log
postgres 21172 myuser 3u systm 0t0
postgres 21172 myuser 4u unix 0xffffff8012b85578 0t0-> 0xffffff8012b85640
postgres 21172 myuser 5 PIPE 0xffff 16650384 -> 0xffffff8014497d10
postgres 21172 myuser 6 PIPE 0xffffff8014497d10 16384-> 0xffffff801449a650
postgres 21172 myuser 7u REG 14,2 8192 3529006 / usr / local / var / postgres / global / 12174
postgres 21172 myuser 9u IPv6 0xffffff8013ebc508 0t0 UDP localhost:57404-> localhost:57404
postgres 21173 myuser cwd DIR 14,2 680 3528182 / usr / local / var / postgres
postgres 21173 myuser txt REG 14,2 5092464 3546949 /usr/local/Cellar/postgresql/9.1.3/bin/postgres
postgres 21173 myuser txt REG 14,2 599280 641674 / usr / lib / dyld
postgr es 21173 myuser txt REG 14,2 297734144 3151814 / private / var / db / dyld / dyld_shared_cache_x86_64
postgres 21173 myuser 0r CHR 3,2 0t0 306 / dev / null
postgres 21173 myuser 1w REG 14,2 1193 3529245 /usr/local/var/postgres/server.log
postgres 21173 myuser 2w REG 14,2 1193 3529245 /usr/local/var/postgres/server.log
postgres 21173 myuser 3u systm 0t0
postgres 21173 myuser 4u Unix 0xffffff8012b85578 0t0-> 0xffffff8012b85640
postgres 21173 myuser 9u IPv6 0xffffff8013ebc508 0t0 UDP localhost:57404-> localhost:57404
p $ p>

如何解决此错误?谢谢!

解决方案

首先要尝试的东西:



psql -h本地主机



可能是客户端和服务器试图为UNIX域套接字使用不同的文件位置。您可以通过tcp / ip连接来避免这种情况。


I just installed postgresql on my Mac OS Lion machine. I've already uninstalled and reinstalled the pg gems.

When I run psql I get the following error:

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

running which psql:
/usr/local/bin/psql

I installed postgresql using homebrew

Here is a lsof results for postgres:

postgres  21159 myuser  cwd      DIR               14,2       680 3528182 /usr/local/var/postgres
postgres  21159 myuser  txt      REG               14,2   5092464 3546949 /usr/local/Cellar/postgresql/9.1.3/bin/postgres
postgres  21159 myuser  txt      REG               14,2    599280  641674 /usr/lib/dyld
postgres  21159 myuser  txt      REG               14,2 297734144 3151814 /private/var/db/dyld/dyld_shared_cache_x86_64
postgres  21159 myuser    0r     CHR                3,2       0t0     306 /dev/null
postgres  21159 myuser    1w     REG               14,2      1193 3529245 /usr/local/var/postgres/server.log
postgres  21159 myuser    2w     REG               14,2      1193 3529245 /usr/local/var/postgres/server.log
postgres  21159 myuser    3u   systm                          0t0         
postgres  21159 myuser    4u    unix 0xffffff8012b85578       0t0         ->0xffffff8012b85640
postgres  21159 myuser    5u    IPv6 0xffffff80128f4e80       0t0     TCP localhost:postgresql (LISTEN)
postgres  21159 myuser    6u    IPv4 0xffffff80128f9880       0t0     TCP localhost:postgresql (LISTEN)
postgres  21159 myuser    7u    IPv6 0xffffff80128f5600       0t0     TCP localhost:postgresql (LISTEN)
postgres  21159 myuser    8u    unix 0xffffff80202d9968       0t0         /tmp/.s.PGSQL.5432
postgres  21159 myuser    9u    IPv6 0xffffff8013ebc508       0t0     UDP localhost:57404->localhost:57404
postgres  21170 myuser  cwd      DIR               14,2       680 3528182 /usr/local/var/postgres
postgres  21170 myuser  txt      REG               14,2   5092464 3546949 /usr/local/Cellar/postgresql/9.1.3/bin/postgres
postgres  21170 myuser  txt      REG               14,2    599280  641674 /usr/lib/dyld
postgres  21170 myuser  txt      REG               14,2 297734144 3151814 /private/var/db/dyld/dyld_shared_cache_x86_64
postgres  21170 myuser    0r     CHR                3,2       0t0     306 /dev/null
postgres  21170 myuser    1w     REG               14,2      1193 3529245 /usr/local/var/postgres/server.log
postgres  21170 myuser    2w     REG               14,2      1193 3529245 /usr/local/var/postgres/server.log
postgres  21170 myuser    3u   systm                          0t0         
postgres  21170 myuser    4u    unix 0xffffff8012b85578       0t0         ->0xffffff8012b85640
postgres  21170 myuser    5     PIPE 0xffffff8015250290     16384         ->0xffffff8015250810
postgres  21170 myuser    6     PIPE 0xffffff8015250810     16384         ->0xffffff8015250290
postgres  21170 myuser    9u    IPv6 0xffffff8013ebc508       0t0     UDP localhost:57404->localhost:57404
postgres  21171 myuser  cwd      DIR               14,2       680 3528182 /usr/local/var/postgres
postgres  21171 myuser  txt      REG               14,2   5092464 3546949 /usr/local/Cellar/postgresql/9.1.3/bin/postgres
postgres  21171 myuser  txt      REG               14,2    599280  641674 /usr/lib/dyld
postgres  21171 myuser  txt      REG               14,2 297734144 3151814 /private/var/db/dyld/dyld_shared_cache_x86_64
postgres  21171 myuser    0r     CHR                3,2       0t0     306 /dev/null
postgres  21171 myuser    1w     REG               14,2      1193 3529245 /usr/local/var/postgres/server.log
postgres  21171 myuser    2w     REG               14,2      1193 3529245 /usr/local/var/postgres/server.log
postgres  21171 myuser    3u   systm                          0t0         
postgres  21171 myuser    4u    unix 0xffffff8012b85578       0t0         ->0xffffff8012b85640
postgres  21171 myuser    5     PIPE 0xffffff80152501e0     16384         ->0xffffff8015250760
postgres  21171 myuser    6     PIPE 0xffffff8015250760     16384         ->0xffffff80152501e0
postgres  21171 myuser    9u    IPv6 0xffffff8013ebc508       0t0     UDP localhost:57404->localhost:57404
postgres  21172 myuser  cwd      DIR               14,2       680 3528182 /usr/local/var/postgres
postgres  21172 myuser  txt      REG               14,2   5092464 3546949 /usr/local/Cellar/postgresql/9.1.3/bin/postgres
postgres  21172 myuser  txt      REG               14,2    599280  641674 /usr/lib/dyld
postgres  21172 myuser  txt      REG               14,2 297734144 3151814 /private/var/db/dyld/dyld_shared_cache_x86_64
postgres  21172 myuser    0r     CHR                3,2       0t0     306 /dev/null
postgres  21172 myuser    1w     REG               14,2      1193 3529245 /usr/local/var/postgres/server.log
postgres  21172 myuser    2w     REG               14,2      1193 3529245 /usr/local/var/postgres/server.log
postgres  21172 myuser    3u   systm                          0t0         
postgres  21172 myuser    4u    unix 0xffffff8012b85578       0t0         ->0xffffff8012b85640
postgres  21172 myuser    5     PIPE 0xffffff801449a650     16384         ->0xffffff8014497d10
postgres  21172 myuser    6     PIPE 0xffffff8014497d10     16384         ->0xffffff801449a650
postgres  21172 myuser    7u     REG               14,2      8192 3529006 /usr/local/var/postgres/global/12174
postgres  21172 myuser    9u    IPv6 0xffffff8013ebc508       0t0     UDP localhost:57404->localhost:57404
postgres  21173 myuser  cwd      DIR               14,2       680 3528182 /usr/local/var/postgres
postgres  21173 myuser  txt      REG               14,2   5092464 3546949 /usr/local/Cellar/postgresql/9.1.3/bin/postgres
postgres  21173 myuser  txt      REG               14,2    599280  641674 /usr/lib/dyld
postgres  21173 myuser  txt      REG               14,2 297734144 3151814 /private/var/db/dyld/dyld_shared_cache_x86_64
postgres  21173 myuser    0r     CHR                3,2       0t0     306 /dev/null
postgres  21173 myuser    1w     REG               14,2      1193 3529245 /usr/local/var/postgres/server.log
postgres  21173 myuser    2w     REG               14,2      1193 3529245 /usr/local/var/postgres/server.log
postgres  21173 myuser    3u   systm                          0t0         
postgres  21173 myuser    4u    unix 0xffffff8012b85578       0t0         ->0xffffff8012b85640
postgres  21173 myuser    9u    IPv6 0xffffff8013ebc508       0t0     UDP localhost:57404->localhost:57404

How do I resolve this error? Thanks!

解决方案

First thing to try:

psql -h localhost

It may be that the client and server are trying to use different file locations for the UNIX domain socket. You can avoid this by connecting over tcp/ip.

这篇关于为什么我在Mac OS Lion中遇到Postgres无法连接服务器的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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