2

请不要将此问题移至 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"?

通常这意味着 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

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

unix_socket_directories = '/var/run/postgresql'

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

4

2 回答 2

6

你开始服务了吗?

service postgresql start
于 2018-08-21T10:36:41.130 回答
3

postgresql.conf 文件由数据库服务器读取,但不被客户端应用程序(例如 createuser、psql、...)读取。(事实上​​,客户端应用程序无法读取服务器配置文件,因为客户端必须连接到服务器,该服务器可能跨越半个地球,然后才可能知道该配置文件所在的位置)。

相反,您必须告诉客户端应用程序在哪里可以找到套接字目录。

如果您的客户端应用程序 (createuser) 正在连接到本地主机(这一定是因为您没有指定不同的主机),您可以使用 host 参数来指定套接字目录的名称。

例如: createuser -h /var/run/postgresql newusername

请参阅http://www.postgresql.org/docs/devel/static/libpq-connect.html#LIBPQ-CONNECT-HOST

希望有帮助。

于 2016-04-18T16:36:39.917 回答