安装后无法在 Mac OS X 上连接到 Postgresql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14971223/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 00:48:25  来源:igfitidea点击:

Could not connect to Postgresql on Mac OS X after Installation

macossocketspostgresqlinstallation

提问by jason328

So I installed Postgresql onto my Mac and whenever I run anything like psqlor createdb cool_database_nameI get the following error.

所以我安装PostgreSQL的在我的Mac,每当我跑像什么psql或者createdb cool_database_name我碰到下面的错误。

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"?

So I follow along the different solutions. I reinstall postgresql to no avail. I go to postgresql.conf` and change it to

所以我遵循不同的解决方案。我重新安装 postgresql 无济于事。我去 postgresql.conf` 并将其更改为

#port = 5432                             # (change requires restart)
#max_connections = 20                    # (change requires restart)
# Note:  Increasing max_connections costs ~400 bytes of shared memory per
# connection slot, plus lock space (see max_locks_per_transaction).
#superuser_reserved_connections = 3     # (change requires restart)
#unix_socket_directory = '/var/pgsql_socket'             # (change requires restart)
#unix_socket_group = ''                 # (change requires restart)
#unix_socket_permissions = 0777         # begin with 0 to use octal notation

yet still nothing. I run commands such as

仍然什么都没有。我运行命令,例如

ls -lA /var/run/postgresql

Which tell me the file or directory does not exist.

哪个告诉我文件或目录不存在。

I also check into the pg_hba.conffile but everything looks ok

我也检查了pg_hba.conf文件,但一切正常

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     jason                                trust
#host    replication     jason        127.0.0.1/32            trust
#host    replication     jason        ::1/128                 trust

When I run psql -h localhostI get

当我跑步时,psql -h localhost我得到

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?

I'm at a lost as to how to fix this. Any help would be appreciated.

我不知道如何解决这个问题。任何帮助,将不胜感激。

回答by mys

The problem is that Mac OS ships PostgreSQL

问题是 Mac OS 附带 PostgreSQL

$ `which psql` --version
psql (PostgreSQL) 9.1.4
contains support for command-line editing

You need change PATH like this:

您需要像这样更改 PATH:

export PATH="path_to_bin_folder_of_your_new_postgres_install:$PATH"

e.g., for Postgres.app:

例如,对于 Postgres.app:

export PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"

This might be useful: http://blog.ringerc.id.au/2012/09/postgresql-packaging-on-mac-os-x-is-mess.html

这可能有用:http: //blog.ringerc.id.au/2012/09/postgresql-packaging-on-mac-os-x-is-mess.html