简体   繁体   English

Postgres无法连接到数据库postgres:无法连接到服务器:没有这样的文件或目录?

[英]Postgres could not connect to database postgres: could not connect to server: No such file or directory?

I am using 4.14.10-2-MANJARO. 我正在使用4.14.10-2-MANJARO。 I have tried to install Postgres Database. 我试图安装Postgres数据库。 I have installed postgresql 10.1-1 by using command: 我已经使用命令安装了postgresql 10.1-1:

yaourt -S postgresql

And then: 接着:

sudo -u postgres -i

initdb --locale $LANG -E UTF8 -D '/var/lib/postgres/data'

createuser --interactive

And then I have got something like this: 然后我得到了这样的东西:

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 "/run/postgresql/.s.PGSQL.5432"?

I don't know how to solve it. 我不知道该怎么解决。 I have been using this website: 我一直在使用这个网站:

https://wiki.archlinux.org/index.php/PostgreSQL#Installing_PostgreSQL

Then I would like to create a new database by command: 然后,我想通过命令创建一个新的数据库:

createdb myDatabaseName

Thank you. 谢谢。

After creating the data directory with initdb , you need to start the database server process with 使用initdb创建数据目录后,需要使用以下命令启动数据库服务器进程

pg_ctl -D /var/lib/postgres/data start

But before that, you should edit /var/lib/postgres/data.postgresql.conf and set parameters like listen_addresses , port , shared_buffers and everything concerning logging. 但是在此之前,您应该编辑/var/lib/postgres/data.postgresql.conf并设置诸如listen_addressesportshared_buffers类的参数以及所有与日志记录有关的参数。

That way, you can consult the log file after starting the server to see if everything went well. 这样,您可以在启动服务器后查阅日志文件,以查看一切是否正常。

I had the same problem and I am also running 4.19.1-1-MANJARO and postgresql 10.5-3 , but most answers are for Ubuntu and refers to directories that don't exist on Manjaro. 我有同样的问题,我也正在运行4.19.1-1-MANJAROpostgresql 10.5-3 ,但是大多数答案是针对Ubuntu的,并且指的是Manjaro上不存在的目录。

You have to run systemctl to check the service to see what is wrong 您必须运行systemctl来检查服务以查看问题所在

sudo systemctl status postgresql

It gives something like this 它给出了这样的东西

systemd[1]: Starting PostgreSQL database server...
postgres[3902]: "/var/lib/postgres/data" is missing >
postgres[3902]:   su - postgres -c "initdb --locale >

and it tells you to run the su command listed above. 并告诉您运行上面列出的su命令。 But this requires the password of the user postgres . 但这需要用户postgres的密码。 To go around this we sudo the command instead. 为了解决这个问题,我们改为使用sudo命令。

sudo su - postgres -c "initdb --locale en_US.UTF-8 -D /var/lib/postgres/data'"

When this command is finished it tells you to run pg_ctl -D /var/lib/postgres/data start , but instead just start it via systemctl. 完成此命令后,它会告诉您运行pg_ctl -D /var/lib/postgres/data start ,而是通过systemctl来启动它。

sudo systemctl enable postgresql
sudo systemctl start postgresql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM