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

9

我在我的Mac电脑上安装了Postgresql,但每当我运行像psqlcreatedb 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"?

所以我跟随不同的解决方案。我重新安装了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

但仍然没有任何反应。我运行了一些命令,比如:

ls -lA /var/run/postgresql

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

我还检查了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

当我运行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?

我不知道怎样解决这个问题,希望能得到帮助。

1个回答

14

问题在于Mac OS自带PostgreSQL

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

你需要像这样改变 PATH:

export PATH="path_to_bin_folder_of_your_new_postgres_install:$PATH"

例如,对于Postgres.app:

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

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


对我来说,路径是/Applications/Postgres.app/Contents/Versions/9.4/bin - dan-klasson
我从 .dmg 安装了 postgres,需要引用 '/Library/PostgreSQL/9.5/bin'。 - Kim

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接