如何在OSX Lion上安装PostgreSQL 9.1 [英] How to install PostgreSQL 9.1 on OSX Lion

查看:95
本文介绍了如何在OSX Lion上安装PostgreSQL 9.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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

  psql:无法连接到服务器:没有这样的文件或目录
服务器是否在本地运行并接受

经过数小时的搜寻后,我读到一些$ PATH问题,因此我将其放入了我的.bashrc中:

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

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

  psql:无法连接到服务器:连接被拒绝
服务器在主机上运行吗?本地主机(:: 1)并在端口5432上接受
TCP / IP连接?
无法连接到服务器:连接被拒绝
服务器是否在主机 localhost(127.0.0.1)上运行并接受端口5432上的
TCP / IP连接?
无法连接到服务器:连接被拒绝
服务器是否在主机 localhost(fe80 :: 1)上运行并接受端口5432上的
TCP / IP连接?

经过更多的谷歌搜索后,我尝试编辑/Library/PostgreSQL/9.1/data/pg_hba.conf和将所有出现的 md5替换为信任。



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

这里有更多信息:

  [〜] $其中psql 
/Library/PostgreSQL/9.1/bin/psql

ps aux | grep postgres
postgres 19022 0.0 0.0 2446096 484 ?? Ss 11:31 PM 0:00.01 postgres:统计收集器进程
postgres 19021 0.0 0.0 2486532 1776 ?? Ss 11:31 PM 0:00.01 postgres:autovacuum启动器进程
postgres 19020 0.0 0.0 2486400 576 ?? Ss 11:31 PM 0:00.03 postgres:wal writer process
postgres 19019 0.0 0.0 2486400 820 ?? Ss 11:31 PM 0:00.05 postgres:编写者进程
postgres 19017 0.0 0.0 2446096 356 ?? Ss 11:31 PM 0:00.01 postgres:记录程序进程
postgres 19015 0.0 0.1 2486400 8216 s001 S 11:31 PM 0:00.17 /Library/PostgreSQL/9.1/bin/postgres

sudo find / -name .s.PGSQL.5432
找不到文件?!?

更新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可以正常工作,因此我假设数据库正在运行

解决方案

在主进程上运行 lsof 这个。在您的情况下为19015(与我的PID一起显示):

 >须藤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 选项


I downloaded PostgreSQL from the official website and ran the .dmg installer. After that I downloaded pgadmin3 and I am indeed able to connect to the database.

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

After hours of googling I read about some $PATH issues, so I put this into my .bashrc:

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

However, this doesn't solve the error above at all. After some more hours of googling I tried to run 'psql -l localhost -U postgres'. This gives another error:

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?

After some more googling I tried to edit /Library/PostgreSQL/9.1/data/pg_hba.conf and replaced all occurrences of 'md5' with 'trust'.

Then I changed user to postgres and executed 'pg_ctl stop' and 'pg_ctl start', switched back to my own user and tried to connect again, no luck.

Here are some more infos:

[~]$ 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?!?

Update 1: In /etc/sysctl.conf I added the values suggested by the installer's README:

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

Before these settings, the installer quits with an error, afterwards the wizard appears and installs postgres (and again, using pgadmin3 works, so I assume that the database is running fine).

解决方案

Run lsof on the master process to all of this. In your case it's 19015 (shown with my PID):

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

You can leave off the awk, but basically it's getting the UNIX socket on which postgres is listening. From there, you can use the -h option to psql (but only include the directory).

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

If that doesn't work, you can check the lsof output to show you what TCP port it's actually listening on, and if it's not 5432, use the -p option to postgres

这篇关于如何在OSX Lion上安装PostgreSQL 9.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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