所以我在尝试连接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/[email protected]/bin/postgres -D /usr/local/var/[email protected]
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
该问题与pg_hba.conf
无关,因为操作系统拒绝了您的连接尝试 - PostgreSQL服务器尚未涉及。
有些事要检查:
ls -l /tmp/.s.PGSQL.5432
我不知道OSX是否忽略UNIX域套接字上的权限,但如果没有,用户需要在套接字上同时具有读写权限才能连接到它。
如果这是问题,请调整PostgreSQL参数unix_socket_permissions
并重新启动。
(当然,它也可能缺少对/tmp
的权限,但如果这是错误的,很多事情应该停止在这台机器上工作。)lsof -p 7782 | grep PGSQL
这里,7782是邮局主管的进程ID。
PostgreSQL参数unix_socket_directories
确定套接字的创建位置。