问题描述
我一直在尝试在系统上设置PostgreSQL(OSX 10.8,全新安装),但是在使用psql
,createdb
等时遇到麻烦.似乎有效.
I've been trying to set up PostgreSQL on my system (OSX 10.8, clean install), but I'm running into trouble with using psql
, createdb
, etc. I've tried various solutions and none seem to work.
安装成功,我使用以下方法修复了已知的套接字问题:
The install was successful, and I proceeded to fix the known sockets issue using the following:
mkdir /var/pgsql_socket
sudo chown $USER /var/pgsql_socket
然后我编辑了postgresql.conf
,将unix_socket_directory
设置为
Then I edited postgresql.conf
, set unix_socket_directory
to
unix_socket_directory = '/var/pgsql_socket'
并重新启动Pg.
这显然应该已经解决了套接字问题,但是我仍然得到:
That should apparently have fixed the socket issue, but I'm still getting:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
我还检查了服务器的状态,它似乎正在运行,但是我仍然得到没有这样的文件或目录"
Also, I've checked the status of the server, and it appears to be running, but I still get 'no such file or directory'
有什么想法吗?
推荐答案
根据错误消息,在$PATH
中最先出现的psql
命令将/tmp
作为硬编码的默认unix套接字目录.
According to the error message, the psql
command that appears first in the $PATH
has /tmp
as the hard-coded default unix socket directory.
由于实际目录实际上是/var/pgsql_socket
,因此您应该明确地告诉它,而不要依赖默认目录:
Since the actual directory is in fact /var/pgsql_socket
, you should tell it explicitly rather than relying on the default:
$ psql -h /var/pgsql_socket [other options]
这同样适用于其他客户端命令,例如createdb
,dropdb
,createuser
...
The same applies to other client-side commands like createdb
, dropdb
, createuser
...
如果不想每次都指定-h
,则可以将其放入PGHOST
环境变量中.
If you don't want to specify -h
each time, it can be put into the PGHOST
environment variable.
有些人还通过使用与localhost
的TCP连接而不是使用Unix套接字目录来解决此问题.
Some people also solve this by using TCP connections to localhost
rather than using the Unix socket directory.
此问题的根本原因是,在Mac OS X上安装PostgreSQL之后,系统最终具有两个不同的postgres客户端集实例(libpq
库,psql
和其他关联的实用程序),一个与MacOS和PostgreSQL安装程序一起提供.
The root cause of this issue would be that after installing PostgreSQL on Mac OS X, the system ends up having two different instances of the postgres client set (the libpq
library, psql
and other associated utilities), one that is bundled with MacOS and the other that comes with the PostgreSQL installer.
因此,还有另一种方法是更改您的$PATH
,以便在与系统一起安装的psql
(大概为/usr/bin/psql
)之前选择与PostgreSQL安装的psql
.
Therefore yet another method is to change your $PATH
so that the psql
installed with PostgreSQL gets choosen before the one installed with the system (presumably /usr/bin/psql
).
这篇关于PostgreSQL Mountain Lion套接字问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!