【问题标题】:How to install PostgreSQL 9.1 on OSX Lion如何在 OSX Lion 上安装 PostgreSQL 9.1
【发布时间】:2012-02-19 22:56:09
【问题描述】:

我从官方网站下载了 PostgreSQL 并运行了 .dmg 安装程序。之后我下载了 pgadmin3 并且我确实能够连接到数据库。

当我运行“psql”时,出现以下错误:

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

经过几个小时的谷歌搜索,我读到了一些 $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?

经过一番谷歌搜索后,我尝试编辑 /Library/PostgreSQL/9.1/data/pg_hba.conf 并将所有出现的 'md5' 替换为 'trust'。

然后我将用户更改为 postgres 并执行 'pg_ctl stop' 和 'pg_ctl start',切换回我自己的用户并尝试再次连接,但没有运气。

这里有更多信息:

[~]$ 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 我添加了安装程序自述文件建议的值:

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 可以正常工作,因此我假设数据库运行良好)。

【问题讨论】:

  • 你查看过服务器日志输出吗?通常在新的 OS X 安装中,由于共享内存限制,Postgres 无法启动,请参阅willbryant.net/software/mac_os_x/…
  • 刚刚检查了日志,只有很多服务器停止和启动消息,完全没有错误。我将编辑我的帖子并添加一个关于共享内存的词。我想我按照安装程序的自述文件的要求做了。

标签: osx-lion postgresql


【解决方案1】:

在主进程上运行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,请使用 postgres 的 -p 选项

【讨论】:

  • 你,先生,真棒! lsof 向我展示了 PostgreSQL 确实在侦听端口 5433(为什么?我从未更改过端口?)。我编辑了 .../data/postgresql.conf 并将端口设置回 5432,然后重新启动服务器,现在一切正常!非常感谢!
【解决方案2】:

如果您能够通过pgadmin3连接到数据库,那么您的数据库正在运行。

(1) 我会通过运行 netstat -an | 来验证grep 5432 在命令行上,作为偏执检查。你在做生意,也就是说,如果你在下面得到这个,你实际上安装了 Postgresql:

tcp4 0 0 *.5432 . 听
tcp6 0 0 *.5432 . 听
ffffff80133bfed8 流 0 0 ffffff8013be8000 0 0 0 /tmp/.s.PGSQL.5432

(2) 就我自己而言,我发现仅仅运行 psql 就会得到你的 psql 错误消息。我不得不跑

psql -h 127.0.0.1 -p 5432 [-d 数据库] -U postgres

连接数据库。换句话说,我必须明确指定 IP 和端口。由于您能够运行 psql 并收到非连接错误消息,因此操作系统理解 psql 是一个命令并且您没有路径问题。

【讨论】:

    猜你喜欢
    • 2011-11-14
    • 1970-01-01
    • 2012-08-08
    • 1970-01-01
    • 2013-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多