createuser 无法连接到数据库 postgres

mno*_*tka 2 database postgresql configuration createuser

请不要将此问题移至 askubuntu,因为我认为此问题不是特定于操作系统的。

当我调用createuserpostgres 命令时(现在我是否提供任何参数都没有关系),我收到了这个错误:

createuser: could not connect to database postgres: 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"?
Run Code Online (Sandbox Code Playgroud)

通常这意味着 postgres 服务器已关闭,但这次不是:

pg_lsclusters
Ver Cluster Port Status Owner    Data directory               Log file
9.4 main    5432 online postgres /var/lib/postgresql/9.4/main /var/log/postgresql/postgresql-9.4-main.log

sudo service postgresql status
9.4/main (port 5432): online
Run Code Online (Sandbox Code Playgroud)

但确实没有/tmp/.s.PGSQL.5432文件,因为我的配置文件(/etc/postgresql/9.4/main/postgresql.conf)有这一行:

unix_socket_directories = '/var/run/postgresql'
Run Code Online (Sandbox Code Playgroud)

所以我真的不明白为什么createuser要访问/tmp/.s.PGSQL.5432?可以将此路径硬编码到createuser二进制文件中吗?我看不出有任何命令行参数来指定设置文件的位置createuser...

Dem*_*ing 6

你启动服务了吗?

service postgresql start
Run Code Online (Sandbox Code Playgroud)