2013-03-26 110 views
3

postgreSQL.conf看起来像Postgres的:本地主机连接不

# - Connection Settings - 

listen_addresses = '*'   # what IP address(es) to listen on; 
             # comma-separated list of addresses; 
             # defaults to 'localhost', '*' = all 
             # (change requires restart) 
port = 5432        # (change requires restart) 

而且我也知道,Postgres的运行

air:data postgres$ ps -aef | grep postgres 
    504 16474 16473 0 11:34AM ??   0:00.00 postgres: logger process 
    504 16476 16473 0 11:34AM ??   0:00.00 postgres: writer process 
    504 16477 16473 0 11:34AM ??   0:00.00 postgres: wal writer process 
    504 16478 16473 0 11:34AM ??   0:00.00 postgres: autovacuum launcher process 
    504 16479 16473 0 11:34AM ??   0:00.00 postgres: stats collector process 
    0 16087 16078 0 10:54AM ttys001 0:00.03 su - postgres 
    504 16473  1 0 11:34AM ttys001 0:00.22 /Library/PostgreSQL/9.1/bin/postgres -D/Library/PostgreSQL/9.1/data 
    504 16484 16088 0 11:34AM ttys001 0:00.00 grep postgres 

但我无法连接

psql -Uuser -W 
Password for user user: 
psql: could not connect to server: No such file or directory 
    Is the server running locally and accepting 
    connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"? 

而且,当我运行以下

lsof -i tcp:5432 
✘ [email protected]:37:13 ⮀ ~ ⮀ netstat -a | grep postgres 
tcp6  0  0 *.postgres    *.*     LISTEN 
tcp4  0  0 *.postgresql   *.*     LISTEN 

它说什么都没有运行port 5432 我错过了什么?

UPDATE

pg_hba.conf看起来像

# TYPE DATABASE  USER   ADDRESS     METHOD 

# "local" is for Unix domain socket connections only 
local all    all          md5 
# IPv4 local connections: 
host all    all    127.0.0.1/32   md5 
# IPv6 local connections: 
host all    all    ::1/128     md5 
+0

你是否在Mac OS X机器上? (通常很好提及你的平台) – 2013-03-26 23:38:24

+0

我的不好,是的,我正在使用Mac OS X – daydreamer 2013-03-27 03:37:45

回答

1

您需要使用自带的是你,而不是安装在psql/usr/bin目录PostgreSQL的包是部分psql程序苹果系统。

例如,如果使用postgres.app,他们在documentation说:

的Mac OS 10.7附带了一个旧版本的PostgreSQL,它可以是 开始用下面的命令:

$ PSQL -h本地主机PostgreSQL附带一系列有用的 二进制文件,如pg_dump或pg_restore,您可能希望使用 。来吧,加入/ bin目录中附带Postgres.app 到PATH(最好的.profile,.bashrc中,.zshrc,等来 确保此获取每一个终端会话设置):

PATH =“/ Applications/Postgres.app /目录/ MacOS/bin:$ PATH”
一旦你的 路径设置正确,你应该可以在没有 主机的情况下运行psql。 (如果没有,检查正确的版本被在 PATH做这PSQL加载)

如果使用预包装的PostgreSQL的另一个来源,它与不同的路径同样的事情。

3

pg_hba.conf中:

host all    all    127.0.0.1/32   trust 

最后一栏更改为trust

0

你可以尝试停止服务和agian星服务。一旦你重新加载配置文件。在工作或不工作时再次检查。