4

因此,在尝试连接到 OSX 上的 Postgres 实例时出现错误。

我收到此错误:

 Connection refused
    Is the server running locally and accepting
    connections on Unix domain socket "/tmp/.s.PGSQL.5432"?

我运行这个:

ps -ax | grep postgres 

得到这个:

 7782 ??         0:00.06 /usr/local/opt/postgresql@9.6/bin/postgres -D /usr/local/var/postgresql@9.6
 7786 ??         0:00.00 postgres: checkpointer process     
 7787 ??         0:00.01 postgres: writer process     
 7788 ??         0:00.00 postgres: wal writer process     
 7789 ??         0:00.00 postgres: autovacuum launcher process     
 7790 ??         0:00.00 postgres: stats collector process     
 7794 ttys000    0:00.00 grep postgres

/tmp/.s.PGSQL.5432 存在,尽管它具有“守护进程”组,而不是具有“轮子”的其他所有内容。

我通过 brew 设置 Postgres 9.6。

这可能是什么原因造成的?

我的 pg_hba.conf 看起来像这样:

host  all  all  0.0.0.0/0  trust
hostnossl    all          all            0.0.0.0/0  trust

这可能是什么原因造成的?

这是 postgres 日志所说的:

2017-12-15 19:40:37 UTC LOG:  database system was shut down at 2017-12-15 19:40:32 UTC
2017-12-15 19:40:37 UTC LOG:  MultiXact member wraparound protections are now enabled
2017-12-15 19:40:37 UTC LOG:  database system is ready to accept connections
2017-12-15 19:40:37 UTC LOG:  autovacuum launcher started

我只是没有看到任何可能导致这种情况的东西。

完整的 pg_hba.conf:

#
# This file controls: which hosts are allowed to connect, how clients
# are authenticated, which PostgreSQL user names they can use, which
# databases they can access.  Records take one of these forms:
#
# local      DATABASE  USER  METHOD  [OPTIONS]
# host       DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
# hostssl    DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
# hostnossl  DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
#
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# Default:
# Added by ansible
# Added by ansible
host  all  all  0.0.0.0/0  trust
hostnossl    all          all            0.0.0.0/0  trust
local  all  all    trust
# Password hosts

# Trusted hosts

# User custom
4

1 回答 1

4

该问题与 无关pg_hba.conf,因为您的连接尝试被操作系统拒绝 - 尚未涉及 PostgreSQL 服务器。

需要检查的一些事项:

  1. 您知道对于 UNIX 域套接字连接,客户端和服务器必须在同一台机器上,对吗?

  2. 套接字权限:

    ls -l /tmp/.s.PGSQL.5432
    

    我不知道 OSX 是否忽略 UNIX 域套接字的权限,但如果没有,用户需要对套接字具有读取和写入权限才能连接到它。

    如果这是问题所在,请调整 PostgreSQL 参数unix_socket_permissions并重新启动。

    (当然,它也可能缺少对 的权限/tmp,但如果这是错误的,很多事情应该停止在这台机器上工作。)

  3. 您是否使用正确的插座?

    列出 postmaster 正在侦听的套接字

    lsof -p 7782 | grep PGSQL
    

    这里,7782 是 postmaster 的进程 ID。

    PostgreSQL 参数unix_socket_directories确定创建套接字的位置。

于 2017-12-19T10:09:49.210 回答