2012-02-19 41 views
3

安装PostgreSQL 9.1我从官方网站下载PostgreSQL和跑的.dmg安装程序。之后,我下载了pgadmin3,确实能够连接到数据库。如何在OSX狮子

当我运行 'PSQL' 我收到以下错误

psql: could not connect to server: No such file or directory 
    Is the server running locally and accepting 

google搜索后我读到一些$ PATH问题的时间,所以我要把它放到我的.bashrc:

export PATH=/Library/PostgreSQL/9.1/bin:$PATH 

但是,这并不能解决上述错误。经过几个小时的搜索后,我尝试运行'psql -l localhost -U postgres'。这给了另一个错误:

psql: 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" (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" (fe80::1) and accepting 
    TCP/IP connections on port 5432? 

经过一些google搜索我尝试编辑/Library/PostgreSQL/9.1/data/pg_hba.conf和更换“MD5”与“信任”的所有事件。

然后,我改变用户的Postgres和执行“pg_ctl停止”和“开始pg_ctl”,切换回我自己的用户,并试图重新连接,没有运气。

这里有一些更多的相关信息:

[~]$ which psql 
/Library/PostgreSQL/9.1/bin/psql 

ps aux | grep postgres 
postgres  19022 0.0 0.0 2446096 484 ?? Ss 11:31PM 0:00.01 postgres: stats collector process 
postgres  19021 0.0 0.0 2486532 1776 ?? Ss 11:31PM 0:00.01 postgres: autovacuum launcher process 
postgres  19020 0.0 0.0 2486400 576 ?? Ss 11:31PM 0:00.03 postgres: wal writer process 
postgres  19019 0.0 0.0 2486400 820 ?? Ss 11:31PM 0:00.05 postgres: writer process 
postgres  19017 0.0 0.0 2446096 356 ?? Ss 11:31PM 0:00.01 postgres: logger process 
postgres  19015 0.0 0.1 2486400 8216 s001 S 11:31PM 0:00.17 /Library/PostgreSQL/9.1/bin/postgres 

sudo find/-name .s.PGSQL.5432 
No file was found?!? 

更新1: /etc/sysctl.conf中我添加安装程序的README建议的值:

kern.sysv.shmmax=1610612736 
kern.sysv.shmall=393216 
kern.sysv.shmmin=1 
kern.sysv.shmmni=32 
kern.sysv.shmseg=8 
kern.maxprocperuid=512 

这些设置之前,安装程序退出时出现错误,之后向导出现并安装postgres(再次使用pgadmin3工作,所以我假定数据库运行正常)。在主流程的所有这一切

+0

你看过服务器日志输出吗?通常在新的OS X上安装Postgres无法启动,因为共享内存限制,请参阅http://willbryant.net/software/mac_os_x/postgres_initdb_fatal_shared_memory_error_on_leopard – bdon 2012-02-19 23:00:10

+0

刚刚检查了日志,只有很多服务器停止和启动消息,没有错误在所有。我将编辑我的文章并添加一个关于共享内存的字词。我想我做了安装程序的自述文件所要求的。 – mbrochh 2012-02-20 07:16:16

回答

7

运行lsof。你的情况是19015(显示我的PID):

> sudo lsof -p 286 | awk '$5 == "unix" && $NF ~ /\// { print $NF }' 
/tmp/.s.PGSQL.5432 

可以去掉awk的,但基本上是越来越上的Postgres监听的UNIX套接字。从那里,你可以使用-h选项psql(但只包括目录)。

> psql -h /tmp template1                                                                
template1=# \q 

如果不工作,你可以检查lsof输出告诉你什么是TCP端口它实际上是监听,如果不是5432,使用-p选项的Postgres

+0

你,先生,真棒! lsof告诉我PostgreSQL确实在监听5433端口(为什么?我从来没有改变端口?)。我编辑了.../data/postgresql.conf并将端口重新设置为5432,然后重新启动服务器,现在一切正常!非常感谢! – mbrochh 2012-02-20 07:42:37

1

如果你是能够通过pgadmin3连接到数据库,然后您的数据库正在运行。

(1)我想通过运行netstat的验证-an |在命令行上输入grep 5432,作为偏执检查。你是在业务,即你实际安装PostgreSQL的,如果你得到这个如下:

TCP4 0 0 * 0.5432 LISTEN
tcp6 0 0 * .5432 LISTEN
ffffff80133bfed8流0 0 ffffff8013be8000 0 0 0 /tmp/.s.PGSQL。5432

(2)说起我自己,我发现只是运行psql让我的psql错误消息。我只好跑

的psql -h 127.0.0.1 -p 5432 [-d数据库6-14 Postgres的

与数据库连接。换句话说,我必须明确指定IP和端口。由于您可以运行psql并获取一条未连接的错误消息,因此操作系统知道psql是一个命令,并且您没有路径问题。