postgresql postgres:本地主机未连接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15644845/
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
postgres: localhost not connecting
提问by daydreamer
My postgreSQL.conf
looks like
我的postgreSQL.conf
样子
# - Connection Settings -
listen_addresses = '*' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost', '*' = all
# (change requires restart)
port = 5432 # (change requires restart)
and I also know that postgres is running
我也知道 postgres 正在运行
air:data postgres$ ps -aef | grep postgres
504 16474 16473 0 11:34AM ?? 0:00.00 postgres: logger process
504 16476 16473 0 11:34AM ?? 0:00.00 postgres: writer process
504 16477 16473 0 11:34AM ?? 0:00.00 postgres: wal writer process
504 16478 16473 0 11:34AM ?? 0:00.00 postgres: autovacuum launcher process
504 16479 16473 0 11:34AM ?? 0:00.00 postgres: stats collector process
0 16087 16078 0 10:54AM ttys001 0:00.03 su - postgres
504 16473 1 0 11:34AM ttys001 0:00.22 /Library/PostgreSQL/9.1/bin/postgres -D/Library/PostgreSQL/9.1/data
504 16484 16088 0 11:34AM ttys001 0:00.00 grep postgres
But I am not able to connect
但我无法连接
psql -Uuser -W
Password for user user:
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Also, when I run the following
此外,当我运行以下
lsof -i tcp:5432
? me@air11:37:13 ? ~ ? netstat -a | grep postgres
tcp6 0 0 *.postgres *.* LISTEN
tcp4 0 0 *.postgresql *.* LISTEN
It says nothing running on port 5432
What am I missing?
它说什么都没有运行port 5432
我错过了什么?
UPDATE
更新
My pg_hba.conf
looks like
我的pg_hba.conf
样子
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all md5
# IPv4 local connections:
host all all 127.0.0.1/32 md5
# IPv6 local connections:
host all all ::1/128 md5
采纳答案by daydreamer
Not sure why this was happening, but I found postgresapp.comwhich is pretty good to use
不知道为什么会这样,但我发现postgresapp.com很好用
I am using this with http://www.pgadmin.org/and I am running it smoothly so far
我在http://www.pgadmin.org/上使用它,到目前为止我运行得很顺利
回答by 1ac0
In pg_hba.conf:
在 pg_hba.conf 中:
host all all 127.0.0.1/32 trust
last column change to trust
最后一列更改为 trust
回答by Patrick
you can try to stop service and agian start the service. once you reload the configuration file. check again while it is working or not.
您可以尝试停止服务并再次启动服务。一旦你重新加载配置文件。在工作与否时再次检查。
回答by Daniel Vérité
You need to use the psql
program that comes that the PostgreSQL package that you installed instead of the psql
in the /usr/bin
directory that is part of the Apple system.
您需要使用psql
您安装的 PostgreSQL 包附带的程序,而不是Apple 系统psql
的/usr/bin
目录中的程序。
For example, if using postgres.app, they say in their documentation:
例如,如果使用postgres.app,他们在他们的文档中说:
Mac OS 10.7 ships with an older version of PostgreSQL, which can be started with the following command:
$ psql -h localhost PostgreSQL ships with a constellation of useful binaries, like pg_dump or pg_restore, that you will likely want to use. Go ahead and add the /bin directory that ships with Postgres.app to your PATH (preferably in .profile, .bashrc, .zshrc, or the like to make sure this gets set for every Terminal session):
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
Once your path is correctly set up, you should be able to run psql without a host. (If not, check that the correct version is being loaded in the PATH by doing which psql)
Mac OS 10.7 附带旧版本的 PostgreSQL,可以使用以下命令启动:
$ psql -h localhost PostgreSQL 附带了一系列有用的二进制文件,例如 pg_dump 或 pg_restore,您可能想要使用它们。继续将 Postgres.app 附带的 /bin 目录添加到您的 PATH(最好在 .profile、.bashrc、.zshrc 或类似文件中,以确保为每个终端会话设置):
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
正确设置路径后,您应该可以在没有主机的情况下运行 psql。(如果没有,请通过执行 which psql 检查是否在 PATH 中加载了正确的版本)
If using another source of pre-packaged postgresql, it's the same thing with different paths.
如果使用另一个预打包的 postgresql 源,则路径不同是相同的。