且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在OSX Lion上安装PostgreSQL 9.1

更新时间:2023-01-20 10:51:06

在主进程上运行 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 的code>选项


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