PostgreSQL Mountain Lion 套接字问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12032585/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PostgreSQL Mountain Lion socket issue
提问by irvanjitsingh
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.
我一直在试图建立的PostgreSQL我的系统上(OSX 10.8,干净的安装),但我遇到了麻烦,使用psql
,createdb
等等。我已经尝试了各种解决方案,并没有看起来的工作。
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
Then I edited postgresql.conf
, set unix_socket_directory
to
然后我编辑postgresql.conf
,设置unix_socket_directory
为
unix_socket_directory = '/var/pgsql_socket'
and restarted Pg.
并重新启动 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'
另外,我检查了服务器的状态,它似乎正在运行,但我仍然收到“没有这样的文件或目录”
Any ideas?
有任何想法吗?
采纳答案by Daniel Vérité
According to the error message, the psql
command that appears first in the $PATH
has /tmp
as the hard-coded default unix socket directory.
根据该错误信息时,psql
首先出现在命令中$PATH
具有/tmp
作为硬编码的默认Unix套接字目录。
Since the actual directory is in fact /var/pgsql_socket
, you should tell it explicitly rather than relying on the default:
由于实际目录实际上是/var/pgsql_socket
,您应该明确地告诉它而不是依赖于默认值:
$ psql -h /var/pgsql_socket [other options]
The same applies to other client-side commands like createdb
, dropdb
, createuser
...
这同样适用于其他客户端命令,如createdb
, dropdb
, createuser
...
If you don't want to specify -h
each time, it can be put into the PGHOST
environment variable.
如果不想-h
每次都指定,可以放入PGHOST
环境变量中。
Some people also solve this by using TCP connections to localhost
rather than using the Unix socket directory.
有些人还通过使用 TCP 连接localhost
而不是使用 Unix 套接字目录来解决这个问题。
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.
此问题的根本原因是在 Mac OS X 上安装 PostgreSQL 后,系统最终拥有两个不同的 postgres 客户端集实例(libpq
库psql
和其他相关实用程序),一个与 MacOS 捆绑在一起,另一个与带有 PostgreSQL 安装程序。
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
).
因此,另一种方法是更改您$PATH
的psql
设置,以便在安装系统(大概是/usr/bin/psql
)之前选择已安装的 PostgreSQL 。
回答by Dmitry Minkovsky
I encountered this same issue when installing PostgreSQL 9.2 via Homebrew. psql
that comes with this build looks to /tmp
for a socket when called without any options.
我在通过 Homebrew 安装 PostgreSQL 9.2 时遇到了同样的问题。当没有任何选项调用时psql
,此构建附带的会查找/tmp
套接字。
I didn't feel like adding any new environment variables like PGHOST
or creating aliases for psql
. There's nothing wrong with doing any of these things, but I just didn't feel like adding to the clutter of my environment.
我不想添加任何新的环境变量,例如PGHOST
或为psql
. 做任何这些事情都没有错,但我只是不想增加我的环境的混乱。
So, why not just set unix_socket_directory
in postgresql.conf
to /tmp
? I did:
那么,为什么不直接设置unix_socket_directory
在postgresql.conf
来/tmp
?我做了:
unix_socket_directory = '/tmp' # (change requires restart)
#unix_socket_group = '' # (change requires restart)
#unix_socket_permissions = 0777 # begin with 0 to use octal notation
After a reload, I can just run $ psql
with no -h
option, without having added an alias or environment variable.
重新加载后,我可以$ psql
不加-h
选择地运行,而无需添加别名或环境变量。
回答by Gunnar Djurberg
See accepted answer for question/link below. Worked for me, but note the setting to change is unix_socket_directories (plural) not unix_socket_directory as stated.
请参阅下面的问题/链接的已接受答案。对我来说有效,但请注意要更改的设置是 unix_socket_directories(复数),而不是如所述的 unix_socket_directory。
https://dba.stackexchange.com/questions/21587/postgresql-is-running-locally-but-i-cannot-connect-why
https://dba.stackexchange.com/questions/21587/postgresql-is-running-locally-but-i-cannot-connect-why
回答by joseph.hainline
I had the same problem, and after doing what you'd done I also had to change my path so that /usr/local/bin (where Homebrew puts everything) comes before /usr/bin. I don't know why this isn't the default anymore, but it's easy to change.
我遇到了同样的问题,在做了你所做的事情之后,我还必须改变我的路径,以便 /usr/local/bin (Homebrew 放置所有东西的地方)出现在 /usr/bin 之前。我不知道为什么这不再是默认设置,但是很容易更改。
sudo vi /etc/paths
then edit the file to have the /usr/local/bin line at the top.
然后编辑文件以将 /usr/local/bin 行放在顶部。
Or alternately if you just want this change to happen for your specific user account, edit your ~/.bash_profile file:
或者,如果您只想为您的特定用户帐户进行此更改,请编辑您的 ~/.bash_profile 文件:
touch ~/.bash_profile
vi ~/.bash_profile
and add this line: export PATH="/usr/local/bin:$PATH"
并添加这一行: export PATH="/usr/local/bin:$PATH"
then run source ~/.bash_profile
for the changes to take effect.
然后运行source ~/.bash_profile
以使更改生效。